diff --git a/.gitignore b/.gitignore index 99db0d9803846..fb602cac912ed 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,7 @@ atlassian* /.idea /.gitattributes /app/config_sandbox -/app/etc/local.xml -/app/etc/*/module.xml +/app/etc/config.php /lib/internal/flex/uploader/.actionScriptProperties /lib/internal/flex/uploader/.flexProperties /lib/internal/flex/uploader/.project @@ -19,6 +18,7 @@ atlassian* /lib/internal/flex/varien/.flexLibProperties /lib/internal/flex/varien/.project /lib/internal/flex/varien/.settings +/node_modules /pub/media/*.* !/pub/media/.htaccess diff --git a/.htaccess b/.htaccess index a0e18f2633dd9..f1ef8719ba1a8 100644 --- a/.htaccess +++ b/.htaccess @@ -188,4 +188,3 @@ ## http://developer.yahoo.com/performance/rules.html#etags #FileETag none - diff --git a/CHANGELOG.md b/CHANGELOG.md index d3b08fe76afdf..b6189e1692c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,90 @@ +0.1.0-alpha106 +============= +* Various improvements: + * Refactored Service Layer of the Magento_Tax Module + * Stabilized functional tests for the Backend module + * Stabilized functional tests for the CatalogRule module + * Stabilized functional tests for the Checkout module + * Stabilized functional tests for the CurrencySymbol module + * Stabilized functional tests for the Shipping module + * Stabilized functional tests for the Tax module + * Stabilized functional tests for the User module +* Added Readme.md files to the following modules: + * Magento\RequireJs + * Magento\Ui +* Fixed bugs: + * Fixed an issue where product image assignment to a store view was not considered when displaying a product + * Fixed shipping address area blinking when billing address is filled during checkout with a virtual product + * Fixed an issue where filter_store.html was not found + * Fixed an issue where the customer account access menu did not expand on the storefront + * Fixed an issue where CMS blocks did not open when clicking from a grid + * Fixed an issue where the Create Product page was completely blocked after closing the New Attribute pop-up + * Fixed an issue where Stock Status was disabled for Bundle and Grouped products + * Fixed an issue where a product could not be saved without filling a not required bundle option + * Fixed broken "per page" selectors on the Customer's account pages + * Fixed the wrong behavior of JS loaders on the storefront pages + * Fixed Shopping cart price rule form validation + * Fixed an issue where the 'Please wait' spinner persisted when creating a customer custom attribute with existing code + * Fixed a Google Chrome specific issue where subcategories were not displayed correctly on the first hover for category item + * Fixed an issue where the 'Please wait' spinner did not disappear when creating customer with invalid email + * Fixed an issue where the Username field auto-focus on admin login page revealed password in case of fast typing + * Fixed an issue where Bundle Product original Price was not displayed in case of discount + * Fixed wrong discount calculation for bundle options + * Fixed an issue where wrong discount and total amounts were displayed on the order creation page when reordering an order with a bundle product in the Admin panel + * Fixed an issue where admin tax notifications did not appear/disappear unless cache was flushed or disabled + * Fixed an issue where catalog price and shopping cart price did not match when display currency was different from the base currency + * Fixed an issue where Tax classes did not allow 'None' as a valid 'product tax class' + * Fixed an issue where token-based authentication did not work if compilation was enabled + * Fixed the sample code in index.php illustrating multi websites set up + * Fixed commands in Setup CLI to match the ones displayed in help + * Fixed an issue where searching by a part of a product name in Advanced Search did not give correct results + * Fixed an issue where 404 page is displayed after Search Term mass deletion + * Fixed an issue where Popular Search Terms were not displayed on the storefront + * Fixed an issue where it was impossible to add Gift Message during one page checkout + * Fixed an issue where the optional Postal code setting did not work correctly + * Fixed an issue where product price details were missing in summary block in the shopping cart when the Back to shopping cart link was clicked on multishipping page + * Fixed an issue where the 404 error page was displayed instead of the Index Management page after saving mass update + * Fixed an issue where the "Out of Stock" message was not displayed for a bundle product when there was not enough of one of the associated products in stock + * Fixed an issue with the Newsletters Report page in the Admin panel + * Fixed an issue where Catalog price rule was not applying correct rates on specific products + * Fixed an issue where a fatal error was thrown after clicking a link to a downloadable product + * Fixed an issue a warning page for Grouped product with enabled MAP + * Fixed an issue where a configurable product was not displayed in catalog product grid after updating with "Add configurable attributes to the new set based on current" + * Fixed the inconsistent behavior in the integration tests for the Indexer functionality + * Fixed an issue where the What's this? information tip link was not presented on product page with configured Minimum Advertised Price (MAP) +* Processed GitHub requests: + * [#742](https://github.com/magento/magento2/issues/742) -- Admin notifications count overflow + * [#720](https://github.com/magento/magento2/issues/720) -- https filedriver is not working + * [#686](https://github.com/magento/magento2/issues/686) -- Product save validation errors in the admin don't hide the overlay + * [#702](https://github.com/magento/magento2/issues/702) -- Base table or view not found + * [#652](https://github.com/magento/magento2/issues/652) -- Multishipping checkout not to change the Billing address js issue + * [#648](https://github.com/magento/magento2/issues/648) -- An equal (=) sign in the hash of the product page to to break the tabs functionality +* Service Contracts: + * Refactored usage of new API of the Customer module + * Implemented Service Contracts for the Sales module + * Refactored Service Contracts for the Catalog module + * Refactored Service Contracts for the Grouped module +* UI Improvements: + * Implemented the Form component in Magento UI Library + * Removed extra JS loaders for category saving + * Improved the behavior of Categories management in the Admin panel + * Implemented the keyboard navigation through HTML elements + * Improved the HTML structure and UI of the Catalog Category Link, Catalog Product Link and CMS Static Block widgets + * Added UI Library documentation + * Fixed Blank & Luma themes UI bugs + * Fixed footer alignment + * Published the Luma theme and removed the Plushe theme +* Framework Improvements: + * Added the ability to configure the list of loaded modules before installation + * Merged SQL and Data Upgrades + * Moved \Magento\TestFramework\Utility\Files to Magento Framework +* Setup tool improvements: + * Removed duplication with Framework + * Deployment configuration is refactored from XML format in local.xml to associated array in config.php + * Improved performance +* Search improvements: + * Integrated the Full Text Search library into the Layered Navigation functionality + 0.1.0-alpha105 ============= * Various improvements: @@ -1891,7 +1978,7 @@ * LESS styles library added in pub/lib/css/ * A new Blank theme set as default * GitHub requests: - * [#491](https://github.com/magento/magento2/pull/491) -- Fixed bug, incorrect auto-generation Category URL for some groups of symbols (idish, cirrilic, é, ä, and other). + * [#491](https://github.com/magento/magento2/pull/491) -- Fixed bug, incorrect auto-generation Category URL for some groups of symbols (idish, cirrilic, e, a, and other). * [#480](https://github.com/magento/magento2/pull/480) -- Fixing a bug for loading config from local.xml * [#472](https://github.com/magento/magento2/issues/472) -- Params passed in pub/index.php being overwritten * [#461](https://github.com/magento/magento2/pull/461) -- Use translates for Quote\Address\Total\Shipping diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000000000..05d2fbf33b5aa --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,105 @@ +// # Globbing +// for performance reasons we're only matching one level down: +// 'test/spec/{,*/}*.js' +// If you want to recursively match all subfolders, use: +// 'test/spec/**/*.js' + +module.exports = function (grunt) { + + // Time how long tasks take. Can help when optimizing build times + require('time-grunt')(grunt); + + // Load grunt tasks automatically + require('load-grunt-tasks')(grunt); + + // Configurable paths and file names + var config = { + pub: 'pub', + var: 'var', + doc: { + path: 'lib/web/css/docs', + styleName: 'docs' + } + }; + + // Define the configuration for all the tasks + grunt.initConfig({ + + // Project settings + config: config, + + // Empties folders to start fresh + clean: { + var: { + files: [{ + dot: true, + src: [ + '<%= config.var %>/cache/*', + '<%= config.var %>/generation/*', + '<%= config.var %>/log/*', + '<%= config.var %>/maps/*', + '<%= config.var %>/page_cache/*', + '<%= config.var %>/tmp/*', + '<%= config.var %>/view/*', + '<%= config.var %>/view_preprocessed/*' + ] + }] + }, + pub: { + files: [{ + dot: true, + src: [ + '<%= config.pub %>/static/frontend/*', + '<%= config.pub %>/static/adminhtml/*' + ] + }] + } + }, + + // Compiles Less to CSS and generates necessary files if requested + less: { + documentation: { + options: { + sourceMap: false, + ieCompat: false, + paths: ['<%= config.doc.path %>/source/'] + }, + files: { + '<%= config.doc.path %>/<%= config.doc.styleName %>.css': "<%= config.doc.path %>/source/<%= config.doc.styleName %>.less" + } + } + }, + + styledocco: { + documentation: { + options: { + name: 'Magento UI Library', + verbose: true, + include: [ + '<%= config.doc.path %>/<%= config.doc.styleName %>.css', + 'lib/web/jquery/jquery.min.js', + 'lib/web/jquery/jquery-ui.min', + '<%= config.doc.path %>/source/js/dropdown.js' + ] + }, + files: { + '<%= config.doc.path %>': '<%= config.doc.path %>/source' + } + } + } + + }); + + grunt.registerTask('default', []); + + grunt.registerTask('cleanup', [ + 'clean:var', + 'clean:pub' + ]); + + grunt.registerTask('documentation', [ + 'less:documentation', + 'styledocco:documentation', + 'cleanup' + ]); +}; diff --git a/app/code/Magento/AdminNotification/Model/Feed.php b/app/code/Magento/AdminNotification/Model/Feed.php index 49fa68a72d149..9cf50c65f43c6 100644 --- a/app/code/Magento/AdminNotification/Model/Feed.php +++ b/app/code/Magento/AdminNotification/Model/Feed.php @@ -62,11 +62,11 @@ class Feed extends \Magento\Framework\Model\AbstractModel protected $curlFactory; /** - * Application arguments + * Deployment configuration * - * @var \Magento\Framework\App\Arguments + * @var \Magento\Framework\App\DeploymentConfig */ - protected $_args; + protected $_deploymentConfig; /** * @param \Magento\Framework\Model\Context $context @@ -74,7 +74,7 @@ class Feed extends \Magento\Framework\Model\AbstractModel * @param \Magento\Backend\App\ConfigInterface $backendConfig * @param \Magento\AdminNotification\Model\InboxFactory $inboxFactory * @param \Magento\Framework\Model\Resource\AbstractResource $resource - * @param \Magento\Framework\App\Arguments $args + * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig * @param \Magento\Framework\Data\Collection\Db $resourceCollection * @param \Magento\Framework\HTTP\Adapter\curlFactory $curlFactory * @param array $data @@ -85,7 +85,7 @@ public function __construct( \Magento\Backend\App\ConfigInterface $backendConfig, \Magento\AdminNotification\Model\InboxFactory $inboxFactory, \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory, - \Magento\Framework\App\Arguments $args, + \Magento\Framework\App\DeploymentConfig $deploymentConfig, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = array() @@ -94,7 +94,7 @@ public function __construct( $this->_backendConfig = $backendConfig; $this->_inboxFactory = $inboxFactory; $this->curlFactory = $curlFactory; - $this->_args = $args; + $this->_deploymentConfig = $deploymentConfig; } /** @@ -135,7 +135,7 @@ public function checkUpdate() $feedXml = $this->getFeedData(); - $installDate = strtotime($this->_args->get('install_date')); + $installDate = strtotime($this->_deploymentConfig->get('install/date')); if ($feedXml && $feedXml->channel && $feedXml->channel->item) { foreach ($feedXml->channel->item as $item) { diff --git a/app/code/Magento/AdminNotification/Model/System/Message/Security.php b/app/code/Magento/AdminNotification/Model/System/Message/Security.php index be4632352156b..4480962609fcb 100644 --- a/app/code/Magento/AdminNotification/Model/System/Message/Security.php +++ b/app/code/Magento/AdminNotification/Model/System/Message/Security.php @@ -35,7 +35,7 @@ class Security implements \Magento\Framework\Notification\MessageInterface * * @var string */ - private $_filePath = 'app/etc/local.xml'; + private $_filePath = 'app/etc/config.php'; /** * Time out for HTTP verification request diff --git a/app/code/Magento/AdminNotification/composer.json b/app/code/Magento/AdminNotification/composer.json index 4a6da5988567d..51359c783f75d 100644 --- a/app/code/Magento/AdminNotification/composer.json +++ b/app/code/Magento/AdminNotification/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.4.11|~5.5.0", - "magento/module-store": "0.1.0-alpha105", - "magento/module-core": "0.1.0-alpha105", - "magento/module-backend": "0.1.0-alpha105", - "magento/framework": "0.1.0-alpha105", + "magento/module-store": "0.1.0-alpha106", + "magento/module-core": "0.1.0-alpha106", + "magento/module-backend": "0.1.0-alpha106", + "magento/framework": "0.1.0-alpha106", "lib-libxml": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.1.0-alpha105", + "version": "0.1.0-alpha106", "extra": { "map": [ [ diff --git a/app/code/Magento/AdminNotification/etc/module.xml b/app/code/Magento/AdminNotification/etc/module.xml index 68a4115f67c14..812434fd201d3 100644 --- a/app/code/Magento/AdminNotification/etc/module.xml +++ b/app/code/Magento/AdminNotification/etc/module.xml @@ -24,7 +24,7 @@ */ --> - + diff --git a/app/code/Magento/AdminNotification/view/adminhtml/requirejs-config.js b/app/code/Magento/AdminNotification/view/adminhtml/requirejs-config.js new file mode 100644 index 0000000000000..7c52d5f8b21f7 --- /dev/null +++ b/app/code/Magento/AdminNotification/view/adminhtml/requirejs-config.js @@ -0,0 +1,33 @@ +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License (AFL 3.0) + * that is bundled with this package in the file LICENSE_AFL.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/afl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +var config = { + map: { + '*': { + systemMessageDialog: 'Magento_AdminNotification/system/notification' + } + }, + deps: [ + "Magento_AdminNotification/toolbar_entry" + ] +}; \ No newline at end of file diff --git a/app/code/Magento/AdminNotification/view/adminhtml/templates/toolbar_entry.phtml b/app/code/Magento/AdminNotification/view/adminhtml/templates/toolbar_entry.phtml index c61adb990efbf..58706c81bf36f 100644 --- a/app/code/Magento/AdminNotification/view/adminhtml/templates/toolbar_entry.phtml +++ b/app/code/Magento/AdminNotification/view/adminhtml/templates/toolbar_entry.phtml @@ -26,7 +26,7 @@ getUnreadNotificationCount(); ?>
0) : ?> - + escapeHtml($notificationCount); ?> diff --git a/app/code/Magento/AdminNotification/view/adminhtml/web/system/notification.js b/app/code/Magento/AdminNotification/view/adminhtml/web/system/notification.js index b5710b6b02861..0a654fbe503b6 100644 --- a/app/code/Magento/AdminNotification/view/adminhtml/web/system/notification.js +++ b/app/code/Magento/AdminNotification/view/adminhtml/web/system/notification.js @@ -63,4 +63,5 @@ define([ }); }); + return $.mage.systemMessageDialog; }); diff --git a/app/code/Magento/Authorization/Model/Resource/Setup.php b/app/code/Magento/Authorization/Model/Resource/Setup.php index e66ee4ec3dd32..617a49cd97a78 100644 --- a/app/code/Magento/Authorization/Model/Resource/Setup.php +++ b/app/code/Magento/Authorization/Model/Resource/Setup.php @@ -29,7 +29,7 @@ * @SuppressWarnings(PHPMD.LongVariable) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Setup extends \Magento\Framework\Module\Setup +class Setup extends \Magento\Framework\Module\DataSetup { /** * Role model factory diff --git a/app/code/Magento/Authorization/composer.json b/app/code/Magento/Authorization/composer.json index a6e58fc3c4dda..f3f935306863f 100644 --- a/app/code/Magento/Authorization/composer.json +++ b/app/code/Magento/Authorization/composer.json @@ -3,12 +3,12 @@ "description": "Authorization module provides access to Magento ACL functionality.", "require": { "php": "~5.4.11|~5.5.0", - "magento/module-backend": "0.1.0-alpha105", - "magento/framework": "0.1.0-alpha105", + "magento/module-backend": "0.1.0-alpha106", + "magento/framework": "0.1.0-alpha106", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.1.0-alpha105", + "version": "0.1.0-alpha106", "extra": { "map": [ [ diff --git a/app/code/Magento/Authorization/etc/module.xml b/app/code/Magento/Authorization/etc/module.xml index 4224828dc06f4..5103ef19308c8 100644 --- a/app/code/Magento/Authorization/etc/module.xml +++ b/app/code/Magento/Authorization/etc/module.xml @@ -24,7 +24,7 @@ */ --> - + diff --git a/app/code/Magento/Authorizenet/Model/Authorizenet.php b/app/code/Magento/Authorizenet/Model/Authorizenet.php index 599e5b3a3edeb..76d305bfdae9a 100644 --- a/app/code/Magento/Authorizenet/Model/Authorizenet.php +++ b/app/code/Magento/Authorizenet/Model/Authorizenet.php @@ -1377,6 +1377,7 @@ protected function _getRequest() */ protected function _buildRequest(\Magento\Framework\Object $payment) { + /** @var \Magento\Sales\Model\Order $order */ $order = $payment->getOrder(); $this->setStore($order->getStoreId()); @@ -1439,7 +1440,7 @@ protected function _buildRequest(\Magento\Framework\Object $payment) )->setXCompany( $billing->getCompany() )->setXAddress( - $billing->getStreet(1) + $billing->getStreetLine(1) )->setXCity( $billing->getCity() )->setXState( @@ -1476,7 +1477,7 @@ protected function _buildRequest(\Magento\Framework\Object $payment) )->setXShipToCompany( $shipping->getCompany() )->setXShipToAddress( - $shipping->getStreet(1) + $shipping->getStreetLine(1) )->setXShipToCity( $shipping->getCity() )->setXShipToState( diff --git a/app/code/Magento/Authorizenet/Model/Directpost/Request.php b/app/code/Magento/Authorizenet/Model/Directpost/Request.php index 1a817b845df76..6648c9f6a0f07 100644 --- a/app/code/Magento/Authorizenet/Model/Directpost/Request.php +++ b/app/code/Magento/Authorizenet/Model/Directpost/Request.php @@ -144,7 +144,7 @@ public function setDataFromOrder( )->setXCompany( strval($billing->getCompany()) )->setXAddress( - strval($billing->getStreet(1)) + strval($billing->getStreetLine(1)) )->setXCity( strval($billing->getCity()) )->setXState( @@ -181,7 +181,7 @@ public function setDataFromOrder( )->setXShipToCompany( strval($shipping->getCompany()) )->setXShipToAddress( - strval($shipping->getStreet(1)) + strval($shipping->getStreetLine(1)) )->setXShipToCity( strval($shipping->getCity()) )->setXShipToState( diff --git a/app/code/Magento/Authorizenet/composer.json b/app/code/Magento/Authorizenet/composer.json index d1dc6d32c91f8..e6356ba34317c 100644 --- a/app/code/Magento/Authorizenet/composer.json +++ b/app/code/Magento/Authorizenet/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.4.11|~5.5.0", - "magento/module-sales": "0.1.0-alpha105", - "magento/module-checkout": "0.1.0-alpha105", - "magento/module-backend": "0.1.0-alpha105", - "magento/module-core": "0.1.0-alpha105", - "magento/module-payment": "0.1.0-alpha105", - "magento/module-centinel": "0.1.0-alpha105", - "magento/module-catalog": "0.1.0-alpha105", - "magento/framework": "0.1.0-alpha105", + "magento/module-sales": "0.1.0-alpha106", + "magento/module-checkout": "0.1.0-alpha106", + "magento/module-backend": "0.1.0-alpha106", + "magento/module-core": "0.1.0-alpha106", + "magento/module-payment": "0.1.0-alpha106", + "magento/module-centinel": "0.1.0-alpha106", + "magento/module-catalog": "0.1.0-alpha106", + "magento/framework": "0.1.0-alpha106", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.1.0-alpha105", + "version": "0.1.0-alpha106", "extra": { "map": [ [ diff --git a/app/code/Magento/Authorizenet/etc/module.xml b/app/code/Magento/Authorizenet/etc/module.xml index dd8f3d7b1bb01..24da9bc21c871 100644 --- a/app/code/Magento/Authorizenet/etc/module.xml +++ b/app/code/Magento/Authorizenet/etc/module.xml @@ -24,7 +24,7 @@ */ --> - + diff --git a/app/code/Magento/Authorizenet/view/frontend/requirejs-config.js b/app/code/Magento/Authorizenet/view/frontend/requirejs-config.js new file mode 100644 index 0000000000000..40ac5ab24372a --- /dev/null +++ b/app/code/Magento/Authorizenet/view/frontend/requirejs-config.js @@ -0,0 +1,31 @@ +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License (AFL 3.0) + * that is bundled with this package in the file LICENSE_AFL.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/afl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +var config = { + map: { + '*': { + authorizenetAuthenticate: 'Magento_Authorizenet/authorizenet-authenticate', + directpost: 'Magento_Authorizenet/js/direct-post' + } + } +}; \ No newline at end of file diff --git a/app/code/Magento/Authorizenet/view/frontend/templates/directpost/form.phtml b/app/code/Magento/Authorizenet/view/frontend/templates/directpost/form.phtml index ae67dc82f2218..1303d70ba716f 100644 --- a/app/code/Magento/Authorizenet/view/frontend/templates/directpost/form.phtml +++ b/app/code/Magento/Authorizenet/view/frontend/templates/directpost/form.phtml @@ -54,7 +54,7 @@ $_orderUrl = $this->helper('Magento\Authorizenet\Helper\Data')->getPlaceOrderFro
- +
@@ -88,7 +88,7 @@ $_orderUrl = $this->helper('Magento\Authorizenet\Helper\Data')->getPlaceOrderFro
- + getViewFileUrl('Magento_Checkout::cvv.gif').'\" alt=\"'.__('Card Verification Number Visual Reference').'\" title=\"'.__('Card Verification Number Visual Reference').'\" />'; ?>
diff --git a/app/code/Magento/Authorizenet/view/frontend/web/authorizenet-authenticate.js b/app/code/Magento/Authorizenet/view/frontend/web/authorizenet-authenticate.js index 2a1df028436f0..1096024d97122 100644 --- a/app/code/Magento/Authorizenet/view/frontend/web/authorizenet-authenticate.js +++ b/app/code/Magento/Authorizenet/view/frontend/web/authorizenet-authenticate.js @@ -83,4 +83,5 @@ define([ } }); + return $.mage.authorizenetAuthenticate; }); \ No newline at end of file diff --git a/app/code/Magento/Authorizenet/view/frontend/web/js/direct-post.js b/app/code/Magento/Authorizenet/view/frontend/web/js/direct-post.js index dfc73e6c538e6..fbafe7ad1ed13 100644 --- a/app/code/Magento/Authorizenet/view/frontend/web/js/direct-post.js +++ b/app/code/Magento/Authorizenet/view/frontend/web/js/direct-post.js @@ -147,5 +147,5 @@ define([ } }); - + return $.mage.directpost; }); \ No newline at end of file diff --git a/app/code/Magento/Backend/App/Area/FrontNameResolver.php b/app/code/Magento/Backend/App/Area/FrontNameResolver.php index 6befd8b275d95..863e2f7b4d8e9 100644 --- a/app/code/Magento/Backend/App/Area/FrontNameResolver.php +++ b/app/code/Magento/Backend/App/Area/FrontNameResolver.php @@ -25,13 +25,15 @@ */ namespace Magento\Backend\App\Area; +use Magento\Framework\App\DeploymentConfig; + class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolverInterface { const XML_PATH_USE_CUSTOM_ADMIN_PATH = 'admin/url/use_custom_path'; const XML_PATH_CUSTOM_ADMIN_PATH = 'admin/url/custom_path'; - const PARAM_BACKEND_FRONT_NAME = 'backend.frontName'; + const PARAM_BACKEND_FRONT_NAME = 'backend/frontName'; /** * Backend area code @@ -41,21 +43,28 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver /** * @var string */ - protected $_defaultFrontName; + protected $defaultFrontName; /** * @var \Magento\Backend\App\ConfigInterface */ - protected $_config; + protected $config; + + /** + * Deployment configuration + * + * @var DeploymentConfig + */ + protected $deploymentConfig; /** * @param \Magento\Backend\App\Config $config - * @param string $defaultFrontName + * @param DeploymentConfig $deploymentConfig */ - public function __construct(\Magento\Backend\App\Config $config, $defaultFrontName) + public function __construct(\Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig) { - $this->_config = $config; - $this->_defaultFrontName = $defaultFrontName; + $this->config = $config; + $this->defaultFrontName = $deploymentConfig->get(self::PARAM_BACKEND_FRONT_NAME); } /** @@ -65,10 +74,10 @@ public function __construct(\Magento\Backend\App\Config $config, $defaultFrontNa */ public function getFrontName() { - $isCustomPathUsed = (bool)(string)$this->_config->getValue(self::XML_PATH_USE_CUSTOM_ADMIN_PATH); + $isCustomPathUsed = (bool)(string)$this->config->getValue(self::XML_PATH_USE_CUSTOM_ADMIN_PATH); if ($isCustomPathUsed) { - return (string)$this->_config->getValue(self::XML_PATH_CUSTOM_ADMIN_PATH); + return (string)$this->config->getValue(self::XML_PATH_CUSTOM_ADMIN_PATH); } - return $this->_defaultFrontName; + return $this->defaultFrontName; } } diff --git a/app/code/Magento/Backend/App/UserConfig.php b/app/code/Magento/Backend/App/UserConfig.php new file mode 100644 index 0000000000000..810218bc24661 --- /dev/null +++ b/app/code/Magento/Backend/App/UserConfig.php @@ -0,0 +1,106 @@ +response = $response; + $this->request = $request; + $this->configFactory = $configFactory; + } + + /** + * Run application + * + * @return \Magento\Framework\App\ResponseInterface + */ + public function launch() + { + $this->response->terminateOnSend(false); + $this->updateUserConfigData(); + return $this->response; + } + + /** + * Inserts provided user configuration data into database + * + * @return void + */ + private function updateUserConfigData() + { + foreach ($this->request as $key => $val) { + $configModel = $this->configFactory->create(); + $configModel->setDataByPath($key, $val); + $configModel->save(); + } + } + + /** + * {@inheritdoc} + */ + public function catchException(Bootstrap $bootstrap, \Exception $exception) + { + return false; + } +} diff --git a/app/code/Magento/Backend/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/Magento/Backend/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index 4eaac1716b277..b41f7f8be6090 100644 --- a/app/code/Magento/Backend/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/Magento/Backend/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -75,7 +75,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele { $html = $this->_getHeaderHtml($element); - $modules = array_keys($this->_moduleList->getModules()); + $modules = $this->_moduleList->getNames(); $dispatchResult = new \Magento\Framework\Object($modules); $this->_eventManager->dispatch( diff --git a/app/code/Magento/Backend/Helper/Dashboard/Data.php b/app/code/Magento/Backend/Helper/Dashboard/Data.php index 83e1283e64568..666f5f6cb378d 100644 --- a/app/code/Magento/Backend/Helper/Dashboard/Data.php +++ b/app/code/Magento/Backend/Helper/Dashboard/Data.php @@ -23,6 +23,8 @@ */ namespace Magento\Backend\Helper\Dashboard; +use \Magento\Framework\App\DeploymentConfig; + /** * Data helper for dashboard */ @@ -38,13 +40,18 @@ class Data extends \Magento\Core\Helper\Data */ protected $_installDate; + /** + * Configuration key to installation date + */ + const INSTALL_DATE = 'install/date'; + /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Framework\App\State $appState * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency - * @param string $installDate + * @param DeploymentConfig $deploymentConfig * @param bool $dbCompatibleMode */ public function __construct( @@ -53,7 +60,7 @@ public function __construct( \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Framework\App\State $appState, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, - $installDate, + DeploymentConfig $deploymentConfig, $dbCompatibleMode = true ) { parent::__construct( @@ -64,7 +71,7 @@ public function __construct( $priceCurrency, $dbCompatibleMode ); - $this->_installDate = $installDate; + $this->_installDate = $deploymentConfig->get(self::INSTALL_DATE); } /** diff --git a/app/code/Magento/Backend/Model/Config.php b/app/code/Magento/Backend/Model/Config.php index 08a06b81626c6..78fdda3bd0a7d 100644 --- a/app/code/Magento/Backend/Model/Config.php +++ b/app/code/Magento/Backend/Model/Config.php @@ -361,6 +361,41 @@ public function extendConfig($path, $full = true, $oldConfig = array()) return $extended; } + /** + * Add data by path section/group/field + * + * @param string $path + * @param mixed $value + * @return void + * @throws \UnexpectedValueException + */ + public function setDataByPath($path, $value) + { + $path = trim($path); + if ($path === '') { + throw new \UnexpectedValueException('Path must not be empty'); + } + $pathParts = explode('/', $path); + $keyDepth = count($pathParts); + if ($keyDepth !== 3) { + throw new \UnexpectedValueException( + "Allowed depth of configuration is 3 (
//). Your configuration depth is " + . $keyDepth . " for path '$path'" + ); + } + $data = [ + 'section' => $pathParts[0], + 'groups' => [ + $pathParts[1] => [ + 'fields' => [ + $pathParts[2] => ['value' => $value], + ], + ], + ], + ]; + $this->addData($data); + } + /** * Get scope name and scopeId * @todo refactor to scope resolver diff --git a/app/code/Magento/Backend/Model/Config/Backend/Admin/Custom.php b/app/code/Magento/Backend/Model/Config/Backend/Admin/Custom.php index 822b65cb2f22d..88f9ff4178979 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Admin/Custom.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Admin/Custom.php @@ -78,7 +78,7 @@ public function __construct( * * @return $this */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); @@ -95,7 +95,7 @@ protected function _beforeSave() * * @return $this */ - public function _afterSave() + public function afterSave() { $useCustomUrl = $this->getData('groups/url/fields/use_custom/value'); $value = $this->getValue(); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Admin/Custompath.php b/app/code/Magento/Backend/Model/Config/Backend/Admin/Custompath.php index 6f2639a95cdb5..b4591ae192ddb 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Admin/Custompath.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Admin/Custompath.php @@ -36,7 +36,7 @@ class Custompath extends \Magento\Framework\App\Config\Value * * @return $this */ - protected function _beforeSave() + public function beforeSave() { if ($this->getOldValue() != $this->getValue()) { $this->_registry->register('custom_admin_path_redirect', true, true); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Admin/Password/Link/Expirationperiod.php b/app/code/Magento/Backend/Model/Config/Backend/Admin/Password/Link/Expirationperiod.php index 077b2cbaae84d..3a0ae9bd3189b 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Admin/Password/Link/Expirationperiod.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Admin/Password/Link/Expirationperiod.php @@ -36,9 +36,9 @@ class Expirationperiod extends \Magento\Framework\App\Config\Value * * @return $this */ - protected function _beforeSave() + public function beforeSave() { - parent::_beforeSave(); + parent::beforeSave(); $expirationPeriod = (int)$this->getValue(); if ($expirationPeriod < 1) { diff --git a/app/code/Magento/Backend/Model/Config/Backend/Admin/Robots.php b/app/code/Magento/Backend/Model/Config/Backend/Admin/Robots.php index 7612bc3734aca..b68290918f98c 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Admin/Robots.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Admin/Robots.php @@ -96,12 +96,12 @@ protected function _afterLoad() * * @return $this */ - protected function _afterSave() + public function afterSave() { if ($this->getValue()) { $this->_directory->writeFile($this->_file, $this->getValue()); } - return parent::_afterSave(); + return parent::afterSave(); } } diff --git a/app/code/Magento/Backend/Model/Config/Backend/Admin/Usecustom.php b/app/code/Magento/Backend/Model/Config/Backend/Admin/Usecustom.php index 31a1218e8144c..b7c4438043401 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Admin/Usecustom.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Admin/Usecustom.php @@ -65,7 +65,7 @@ public function __construct( * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); if ($value == 1) { @@ -83,7 +83,7 @@ protected function _beforeSave() * * @return $this */ - protected function _afterSave() + public function afterSave() { $value = $this->getValue(); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Admin/Usesecretkey.php b/app/code/Magento/Backend/Model/Config/Backend/Admin/Usesecretkey.php index 85601783b7b35..d8e998117e8de 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Admin/Usesecretkey.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Admin/Usesecretkey.php @@ -59,7 +59,7 @@ public function __construct( /** * @return $this */ - protected function _afterSave() + public function afterSave() { $this->_backendUrl->renewSecretUrls(); return $this; diff --git a/app/code/Magento/Backend/Model/Config/Backend/Baseurl.php b/app/code/Magento/Backend/Model/Config/Backend/Baseurl.php index 37405568eebe3..a5b7988782c46 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Baseurl.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Baseurl.php @@ -58,7 +58,7 @@ public function __construct( * @return void * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); try { @@ -218,7 +218,7 @@ private function _isFullyQualifiedUrl($value) * * @return void */ - protected function _afterSave() + public function afterSave() { if ($this->isValueChanged()) { switch ($this->getPath()) { diff --git a/app/code/Magento/Backend/Model/Config/Backend/Cache.php b/app/code/Magento/Backend/Model/Config/Backend/Cache.php index d14e8f2dbf651..083f17da2d239 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Cache.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Cache.php @@ -42,7 +42,7 @@ class Cache extends \Magento\Framework\App\Config\Value * * @return void */ - protected function _afterSave() + public function afterSave() { if ($this->isValueChanged()) { $this->_cacheManager->clean($this->_cacheTags); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Cookie/Domain.php b/app/code/Magento/Backend/Model/Config/Backend/Cookie/Domain.php index 60f950e8a7daa..c6a61e219e557 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Cookie/Domain.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Cookie/Domain.php @@ -61,7 +61,7 @@ public function __construct( * @return void * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Cookie/Lifetime.php b/app/code/Magento/Backend/Model/Config/Backend/Cookie/Lifetime.php index 157942607d538..05e58c2319ae3 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Cookie/Lifetime.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Cookie/Lifetime.php @@ -61,7 +61,7 @@ public function __construct( * @return void * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Cookie/Path.php b/app/code/Magento/Backend/Model/Config/Backend/Cookie/Path.php index 731f2f37aab85..4d84e88f05879 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Cookie/Path.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Cookie/Path.php @@ -61,7 +61,7 @@ public function __construct( * @return void * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Currency/Allow.php b/app/code/Magento/Backend/Model/Config/Backend/Currency/Allow.php index 449fc5ed4601a..f114996b49a36 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Currency/Allow.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Currency/Allow.php @@ -66,7 +66,7 @@ public function __construct( * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _afterSave() + public function afterSave() { $exceptions = array(); foreach ($this->_getAllowedCurrencies() as $currencyCode) { diff --git a/app/code/Magento/Backend/Model/Config/Backend/Currency/Base.php b/app/code/Magento/Backend/Model/Config/Backend/Currency/Base.php index 878153d5c0ab9..285ebbcc892fc 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Currency/Base.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Currency/Base.php @@ -36,7 +36,7 @@ class Base extends AbstractCurrency * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _afterSave() + public function afterSave() { if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) { throw new \Magento\Framework\Model\Exception(__('Sorry, we haven\'t installed the base currency you selected.')); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Currency/Cron.php b/app/code/Magento/Backend/Model/Config/Backend/Currency/Cron.php index 3aa3f59bd3204..500ebc4494040 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Currency/Cron.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Currency/Cron.php @@ -62,7 +62,7 @@ public function __construct( * @return void * @throws \Exception */ - protected function _afterSave() + public function afterSave() { $time = $this->getData('groups/import/fields/time/value'); $frequency = $this->getData('groups/import/fields/frequency/value'); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Currency/DefaultCurrency.php b/app/code/Magento/Backend/Model/Config/Backend/Currency/DefaultCurrency.php index 32dfbfe3e8598..55387b89dbd4b 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Currency/DefaultCurrency.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Currency/DefaultCurrency.php @@ -37,7 +37,7 @@ class DefaultCurrency extends AbstractCurrency * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _afterSave() + public function afterSave() { if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) { throw new \Magento\Framework\Model\Exception( diff --git a/app/code/Magento/Backend/Model/Config/Backend/Datashare.php b/app/code/Magento/Backend/Model/Config/Backend/Datashare.php index a26a0f72683eb..07b1ca8960ce1 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Datashare.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Datashare.php @@ -34,7 +34,7 @@ class Datashare extends \Magento\Framework\App\Config\Value /** * @return void */ - protected function _afterSave() + public function afterSave() { } } diff --git a/app/code/Magento/Backend/Model/Config/Backend/Email/Address.php b/app/code/Magento/Backend/Model/Config/Backend/Email/Address.php index 63e8fc0695b38..8a7cf54ac7b67 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Email/Address.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Email/Address.php @@ -35,7 +35,7 @@ class Address extends \Magento\Framework\App\Config\Value * @return $this * @throws Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); if (!\Zend_Validate::is($value, 'EmailAddress')) { diff --git a/app/code/Magento/Backend/Model/Config/Backend/Email/Logo.php b/app/code/Magento/Backend/Model/Config/Backend/Email/Logo.php index 7db80f69a8797..ead250de9d559 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Email/Logo.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Email/Logo.php @@ -70,7 +70,7 @@ protected function _addWhetherScopeInfo() * * @return $this */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); $deleteFlag = is_array($value) && !empty($value['delete']); @@ -79,6 +79,6 @@ protected function _beforeSave() if ($this->getOldValue() && ($fileTmpName || $deleteFlag)) { $this->_mediaDirectory->delete(self::UPLOAD_DIR . '/' . $this->getOldValue()); } - return parent::_beforeSave(); + return parent::beforeSave(); } } diff --git a/app/code/Magento/Backend/Model/Config/Backend/Email/Sender.php b/app/code/Magento/Backend/Model/Config/Backend/Email/Sender.php index 4bb32ad17efe2..6f7a26dd2198a 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Email/Sender.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Email/Sender.php @@ -35,7 +35,7 @@ class Sender extends \Magento\Framework\App\Config\Value * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); if (!preg_match("/^[\S ]+$/", $value)) { diff --git a/app/code/Magento/Backend/Model/Config/Backend/Encrypted.php b/app/code/Magento/Backend/Model/Config/Backend/Encrypted.php index 7a1186310282c..1d3f99379532e 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Encrypted.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Encrypted.php @@ -94,7 +94,7 @@ protected function _afterLoad() * * @return void */ - protected function _beforeSave() + public function beforeSave() { $value = (string)$this->getValue(); // don't change value, if an obscured value came diff --git a/app/code/Magento/Backend/Model/Config/Backend/File.php b/app/code/Magento/Backend/Model/Config/Backend/File.php index 12cffc5be8ada..c2e34dbd6dbcb 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/File.php +++ b/app/code/Magento/Backend/Model/Config/Backend/File.php @@ -95,7 +95,7 @@ public function __construct( * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); $tmpName = $this->_requestData->getTmpName($this->getPath()); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Filename.php b/app/code/Magento/Backend/Model/Config/Backend/Filename.php index b56a9ea7290cf..aeef55c452d1a 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Filename.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Filename.php @@ -28,7 +28,7 @@ class Filename extends \Magento\Framework\App\Config\Value /** * @return $this */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); $value = basename($value); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Image/Adapter.php b/app/code/Magento/Backend/Model/Config/Backend/Image/Adapter.php index 317e14fc41c28..06878ccfca63e 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Image/Adapter.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Image/Adapter.php @@ -65,7 +65,7 @@ public function __construct( * @throws \Magento\Framework\Model\Exception If some of adapter dependencies was not loaded * @return \Magento\Backend\Model\Config\Backend\File */ - protected function _beforeSave() + public function beforeSave() { try { $this->_imageFactory->create($this->getValue()); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Locale.php b/app/code/Magento/Backend/Model/Config/Backend/Locale.php index ee48299ff9ae5..3134eb80a7d2f 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Locale.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Locale.php @@ -86,7 +86,7 @@ public function __construct( * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _afterSave() + public function afterSave() { /** @var $collection \Magento\Core\Model\Resource\Config\Data\Collection */ $collection = $this->_configsFactory->create(); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Locale/Timezone.php b/app/code/Magento/Backend/Model/Config/Backend/Locale/Timezone.php index 80c9a85df2615..d0d0f9af843c4 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Locale/Timezone.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Locale/Timezone.php @@ -35,7 +35,7 @@ class Timezone extends \Magento\Framework\App\Config\Value * @return $this * @throws Exception */ - protected function _beforeSave() + public function beforeSave() { if (!in_array($this->getValue(), \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC))) { throw new Exception(__('Please correct the timezone.')); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Log/Cron.php b/app/code/Magento/Backend/Model/Config/Backend/Log/Cron.php index 084e25f324c51..cb66a498bd853 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Log/Cron.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Log/Cron.php @@ -74,7 +74,7 @@ public function __construct( * @return void * @throws \Magento\Framework\Model\Exception */ - protected function _afterSave() + public function afterSave() { $enabled = $this->getData('groups/log/fields/enabled/value'); $time = $this->getData('groups/log/fields/time/value'); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Secure.php b/app/code/Magento/Backend/Model/Config/Backend/Secure.php index 1a9f69c7eef61..db23249602c39 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Secure.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Secure.php @@ -57,7 +57,7 @@ public function __construct( * * @return void */ - protected function _afterSave() + public function afterSave() { if ($this->isValueChanged()) { $this->_mergeService->cleanMergedJsCss(); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Serialized.php b/app/code/Magento/Backend/Model/Config/Backend/Serialized.php index 3f5af6147401a..2920fce044b23 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Serialized.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Serialized.php @@ -39,7 +39,7 @@ protected function _afterLoad() /** * @return void */ - protected function _beforeSave() + public function beforeSave() { if (is_array($this->getValue())) { $this->setValue(serialize($this->getValue())); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Serialized/ArraySerialized.php b/app/code/Magento/Backend/Model/Config/Backend/Serialized/ArraySerialized.php index 4d5d1e0872932..1afa3b7d1cdd1 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Serialized/ArraySerialized.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Serialized/ArraySerialized.php @@ -35,13 +35,13 @@ class ArraySerialized extends \Magento\Backend\Model\Config\Backend\Serialized * * @return void */ - protected function _beforeSave() + public function beforeSave() { $value = $this->getValue(); if (is_array($value)) { unset($value['__empty']); } $this->setValue($value); - parent::_beforeSave(); + parent::beforeSave(); } } diff --git a/app/code/Magento/Backend/Model/Config/Backend/Storage/Media/Database.php b/app/code/Magento/Backend/Model/Config/Backend/Storage/Media/Database.php index ef50b9a3c7740..ec092cb429121 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Storage/Media/Database.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Storage/Media/Database.php @@ -59,7 +59,7 @@ public function __construct( * * @return $this */ - protected function _afterSave() + public function afterSave() { $helper = $this->_coreFileStorage; $helper->getStorageModel(null, array('init' => true)); diff --git a/app/code/Magento/Backend/Model/Config/Backend/Store.php b/app/code/Magento/Backend/Model/Config/Backend/Store.php index 113fd56a290e3..f995f1a9e1724 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Store.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Store.php @@ -59,7 +59,7 @@ public function __construct( /** * @return void */ - protected function _afterSave() + public function afterSave() { $this->_mutableConfig->setValue( \Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, diff --git a/app/code/Magento/Backend/Model/Config/Backend/Translate.php b/app/code/Magento/Backend/Model/Config/Backend/Translate.php index de93f8feee582..8a9629e08a9d8 100644 --- a/app/code/Magento/Backend/Model/Config/Backend/Translate.php +++ b/app/code/Magento/Backend/Model/Config/Backend/Translate.php @@ -80,7 +80,7 @@ public function __construct( * * @return $this */ - protected function _afterSave() + public function afterSave() { $types = array_keys( $this->_scopeConfig->getValue( diff --git a/app/code/Magento/Backend/Model/Config/Source/Storage/Media/Database.php b/app/code/Magento/Backend/Model/Config/Source/Storage/Media/Database.php index f52d9f6fb9f56..b74de0e8aa13d 100644 --- a/app/code/Magento/Backend/Model/Config/Source/Storage/Media/Database.php +++ b/app/code/Magento/Backend/Model/Config/Source/Storage/Media/Database.php @@ -27,21 +27,22 @@ */ namespace Magento\Backend\Model\Config\Source\Storage\Media; -use Magento\Framework\App\Arguments; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\DeploymentConfig\ResourceConfig; class Database implements \Magento\Framework\Option\ArrayInterface { /** - * @var Arguments + * @var DeploymentConfig */ - protected $_arguments; + protected $_deploymentConfig; /** - * @param Arguments $arguments + * @param DeploymentConfig $deploymentConfig */ - public function __construct(Arguments $arguments) + public function __construct(DeploymentConfig $deploymentConfig) { - $this->_arguments = $arguments; + $this->_deploymentConfig = $deploymentConfig; } /** @@ -52,11 +53,15 @@ public function __construct(Arguments $arguments) public function toOptionArray() { $resourceOptions = array(); - foreach (array_keys($this->_arguments->getResources()) as $resourceName) { - $resourceOptions[] = array('value' => $resourceName, 'label' => $resourceName); + $resourceInfo = $this->_deploymentConfig->getSegment(ResourceConfig::CONFIG_KEY); + if (null !== $resourceInfo) { + $resourceConfig = new ResourceConfig($resourceInfo); + foreach (array_keys($resourceConfig->getData()) as $resourceName) { + $resourceOptions[] = array('value' => $resourceName, 'label' => $resourceName); + } + sort($resourceOptions); + reset($resourceOptions); } - sort($resourceOptions); - reset($resourceOptions); return $resourceOptions; } } diff --git a/app/code/Magento/Backend/Model/Config/Structure.php b/app/code/Magento/Backend/Model/Config/Structure.php index 7479b975f4a07..81b680edd3280 100644 --- a/app/code/Magento/Backend/Model/Config/Structure.php +++ b/app/code/Magento/Backend/Model/Config/Structure.php @@ -143,10 +143,13 @@ public function getElementByPathParts(array $pathParts) if (isset($this->_elements[$path])) { return $this->_elements[$path]; } - $children = $this->_data['sections']; + $children = []; + if ($this->_data) { + $children = $this->_data['sections']; + } $child = array(); foreach ($pathParts as $pathPart) { - if (array_key_exists($pathPart, $children)) { + if ($children && (array_key_exists($pathPart, $children))) { $child = $children[$pathPart]; $children = array_key_exists('children', $child) ? $child['children'] : array(); } else { diff --git a/app/code/Magento/Backend/Model/Menu/Item.php b/app/code/Magento/Backend/Model/Menu/Item.php index cf19b8c5283e4..3b999ac7ebf2d 100644 --- a/app/code/Magento/Backend/Model/Menu/Item.php +++ b/app/code/Magento/Backend/Model/Menu/Item.php @@ -427,7 +427,7 @@ protected function _isModuleDependenciesAvailable() { if ($this->_dependsOnModule) { $module = $this->_dependsOnModule; - return !!$this->_moduleList->getModule($module); + return $this->_moduleList->has($module); } return true; } diff --git a/app/code/Magento/Backend/Model/Search/Customer.php b/app/code/Magento/Backend/Model/Search/Customer.php index 2d5f256f804c6..e7b4159c2f4c2 100644 --- a/app/code/Magento/Backend/Model/Search/Customer.php +++ b/app/code/Magento/Backend/Model/Search/Customer.php @@ -48,19 +48,19 @@ class Customer extends \Magento\Framework\Object protected $_adminhtmlData = null; /** - * @var \Magento\Customer\Service\V1\CustomerAccountService + * @var \Magento\Customer\Api\CustomerRepositoryInterface */ - protected $_customerService; + protected $customerRepository; /** * @var \Magento\Framework\Api\SearchCriteriaBuilder */ - protected $_searchCriteriaBuilder; + protected $searchCriteriaBuilder; /** * @var \Magento\Framework\Api\FilterBuilder */ - protected $_filterBuilder; + protected $filterBuilder; /** * @var \Magento\Customer\Helper\View @@ -71,22 +71,22 @@ class Customer extends \Magento\Framework\Object * Initialize dependencies. * * @param \Magento\Backend\Helper\Data $adminhtmlData - * @param \Magento\Customer\Service\V1\CustomerAccountService $customerService + * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder * @param \Magento\Framework\Api\FilterBuilder $filterBuilder * @param \Magento\Customer\Helper\View $customerViewHelper */ public function __construct( \Magento\Backend\Helper\Data $adminhtmlData, - \Magento\Customer\Service\V1\CustomerAccountService $customerService, + \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\Api\FilterBuilder $filterBuilder, \Magento\Customer\Helper\View $customerViewHelper ) { $this->_adminhtmlData = $adminhtmlData; - $this->_customerService = $customerService; - $this->_searchCriteriaBuilder = $searchCriteriaBuilder; - $this->_filterBuilder = $filterBuilder; + $this->customerRepository = $customerRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->filterBuilder = $filterBuilder; $this->_customerViewHelper = $customerViewHelper; } @@ -103,39 +103,37 @@ public function load() return $this; } - $this->_searchCriteriaBuilder->setCurrentPage($this->getStart()); - $this->_searchCriteriaBuilder->setPageSize($this->getLimit()); + $this->searchCriteriaBuilder->setCurrentPage($this->getStart()); + $this->searchCriteriaBuilder->setPageSize($this->getLimit()); $searchFields = ['firstname', 'lastname', 'company']; $filters = []; foreach ($searchFields as $field) { - $filters[] = $this->_filterBuilder + $filters[] = $this->filterBuilder ->setField($field) ->setConditionType('like') ->setValue($this->getQuery() . '%') ->create(); } - $this->_searchCriteriaBuilder->addFilter($filters); - $searchCriteria = $this->_searchCriteriaBuilder->create(); - $searchResults = $this->_customerService->searchCustomers($searchCriteria); + $this->searchCriteriaBuilder->addFilter($filters); + $searchCriteria = $this->searchCriteriaBuilder->create(); + $searchResults = $this->customerRepository->getList($searchCriteria); - /** @var \Magento\Customer\Service\V1\Data\CustomerDetails $customerDetails */ - foreach ($searchResults->getItems() as $customerDetails) { - $customerData = $customerDetails->getCustomer(); - $customerAddresses = $customerDetails->getAddresses(); + foreach ($searchResults->getItems() as $customer) { + $customerAddresses = $customer->getAddresses(); /** Look for a company name defined in default billing address */ $company = null; foreach ($customerAddresses as $customerAddress) { - if ($customerAddress->isDefaultBilling()) { + if ($customerAddress->getId() == $customer->getDefaultBilling()) { $company = $customerAddress->getCompany(); break; } } $result[] = array( - 'id' => 'customer/1/' . $customerData->getId(), + 'id' => 'customer/1/' . $customer->getId(), 'type' => __('Customer'), - 'name' => $this->_customerViewHelper->getCustomerName($customerData), + 'name' => $this->_customerViewHelper->getCustomerName($customer), 'description' => $company, - 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', array('id' => $customerData->getId())) + 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', array('id' => $customer->getId())) ); } $this->setResults($result); diff --git a/app/code/Magento/Backend/Model/Session/AdminConfig.php b/app/code/Magento/Backend/Model/Session/AdminConfig.php index fff8c358482c9..207c5e16b8fd1 100644 --- a/app/code/Magento/Backend/Model/Session/AdminConfig.php +++ b/app/code/Magento/Backend/Model/Session/AdminConfig.php @@ -29,6 +29,7 @@ use Magento\Framework\Filesystem; use Magento\Framework\Session\Config; use Magento\Framework\UrlInterface; +use Magento\Framework\App\DeploymentConfig; /** * Magento Backend session configuration @@ -58,12 +59,10 @@ class AdminConfig extends Config * @param \Magento\Framework\Stdlib\String $stringHelper * @param \Magento\Framework\App\RequestInterface $request * @param Filesystem $filesystem + * @param DeploymentConfig $deploymentConfig * @param string $scopeType * @param FrontNameResolver $frontNameResolver * @param \Magento\Framework\StoreManagerInterface $storeManager - * @param string $saveMethod - * @param null|string $savePath - * @param null|string $cacheLimiter * @param string $lifetimePath * @param string $sessionName * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -74,12 +73,10 @@ public function __construct( \Magento\Framework\Stdlib\String $stringHelper, \Magento\Framework\App\RequestInterface $request, Filesystem $filesystem, + DeploymentConfig $deploymentConfig, $scopeType, FrontNameResolver $frontNameResolver, \Magento\Framework\StoreManagerInterface $storeManager, - $saveMethod = \Magento\Framework\Session\SaveHandlerInterface::DEFAULT_HANDLER, - $savePath = null, - $cacheLimiter = null, $lifetimePath = self::XML_PATH_COOKIE_LIFETIME, $sessionName = self::SESSION_NAME_ADMIN ) { @@ -89,10 +86,8 @@ public function __construct( $stringHelper, $request, $filesystem, + $deploymentConfig, $scopeType, - $saveMethod, - $savePath, - $cacheLimiter, $lifetimePath ); diff --git a/app/code/Magento/Backend/Model/Session/Quote.php b/app/code/Magento/Backend/Model/Session/Quote.php index 5239bed9d376e..2b93501e774ee 100644 --- a/app/code/Magento/Backend/Model/Session/Quote.php +++ b/app/code/Magento/Backend/Model/Session/Quote.php @@ -23,6 +23,9 @@ */ namespace Magento\Backend\Model\Session; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Api\GroupManagementInterface; + /** * Adminhtml quote session * @@ -67,9 +70,9 @@ class Quote extends \Magento\Framework\Session\SessionManager protected $_orderFactory; /** - * @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface + * @var CustomerRepositoryInterface */ - protected $_customerService; + protected $customerRepository; /** * Sales quote repository @@ -84,9 +87,9 @@ class Quote extends \Magento\Framework\Session\SessionManager protected $_storeManager; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var GroupManagementInterface */ - protected $_scopeConfig; + protected $groupManagement; /** * Constructor @@ -100,10 +103,10 @@ class Quote extends \Magento\Framework\Session\SessionManager * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory * @param \Magento\Sales\Model\QuoteRepository $quoteRepository - * @param \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerService + * @param CustomerRepositoryInterface $customerRepository * @param \Magento\Sales\Model\OrderFactory $orderFactory * @param \Magento\Framework\StoreManagerInterface $storeManager - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param GroupManagementInterface $groupManagement */ public function __construct( \Magento\Framework\App\Request\Http $request, @@ -115,16 +118,16 @@ public function __construct( \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, \Magento\Sales\Model\QuoteRepository $quoteRepository, - \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerService, + CustomerRepositoryInterface $customerRepository, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Framework\StoreManagerInterface $storeManager, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + GroupManagementInterface $groupManagement ) { $this->quoteRepository = $quoteRepository; - $this->_customerService = $customerService; + $this->customerRepository = $customerRepository; $this->_orderFactory = $orderFactory; $this->_storeManager = $storeManager; - $this->_scopeConfig = $scopeConfig; + $this->groupManagement = $groupManagement; parent::__construct( $request, $sidResolver, @@ -152,10 +155,7 @@ public function getQuote() $this->_quote = $this->quoteRepository->create(); if ($this->getStoreId()) { if (!$this->getQuoteId()) { - $customerGroupId = $this->_scopeConfig->getValue( - \Magento\Customer\Service\V1\CustomerGroupServiceInterface::XML_PATH_DEFAULT_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + $customerGroupId = $this->groupManagement->getDefaultGroup()->getId(); $this->_quote->setCustomerGroupId($customerGroupId) ->setIsActive(false) ->setStoreId($this->getStoreId()); @@ -167,7 +167,7 @@ public function getQuote() } if ($this->getCustomerId()) { - $this->_quote->assignCustomer($this->_customerService->getCustomer($this->getCustomerId())); + $this->_quote->assignCustomer($this->customerRepository->getById($this->getCustomerId())); } } $this->_quote->setIgnoreOldQty(true); diff --git a/app/code/Magento/Backend/Service/V1/ModuleService.php b/app/code/Magento/Backend/Service/V1/ModuleService.php index ad8195afa9ba3..6f3cb759f4193 100644 --- a/app/code/Magento/Backend/Service/V1/ModuleService.php +++ b/app/code/Magento/Backend/Service/V1/ModuleService.php @@ -49,11 +49,6 @@ public function __construct( */ public function getModules() { - $result = []; - $modules = $this->moduleList->getModules(); - foreach ($modules as $module) { - $result[] = $module['name']; - } - return $result; + return $this->moduleList->getNames(); } } diff --git a/app/code/Magento/Backend/composer.json b/app/code/Magento/Backend/composer.json index af0fd86131c36..3345cd14a4efe 100644 --- a/app/code/Magento/Backend/composer.json +++ b/app/code/Magento/Backend/composer.json @@ -3,26 +3,26 @@ "description": "N/A", "require": { "php": "~5.4.11|~5.5.0", - "magento/module-store": "0.1.0-alpha105", - "magento/module-directory": "0.1.0-alpha105", - "magento/module-core": "0.1.0-alpha105", - "magento/module-eav": "0.1.0-alpha105", - "magento/module-cron": "0.1.0-alpha105", - "magento/module-theme": "0.1.0-alpha105", - "magento/module-reports": "0.1.0-alpha105", - "magento/module-sales": "0.1.0-alpha105", - "magento/module-catalog": "0.1.0-alpha105", - "magento/module-user": "0.1.0-alpha105", - "magento/module-backup": "0.1.0-alpha105", - "magento/module-email": "0.1.0-alpha105", - "magento/module-customer": "0.1.0-alpha105", - "magento/module-translation": "0.1.0-alpha105", - "magento/module-require-js": "0.1.0-alpha105", - "magento/framework": "0.1.0-alpha105", + "magento/module-store": "0.1.0-alpha106", + "magento/module-directory": "0.1.0-alpha106", + "magento/module-core": "0.1.0-alpha106", + "magento/module-eav": "0.1.0-alpha106", + "magento/module-cron": "0.1.0-alpha106", + "magento/module-theme": "0.1.0-alpha106", + "magento/module-reports": "0.1.0-alpha106", + "magento/module-sales": "0.1.0-alpha106", + "magento/module-catalog": "0.1.0-alpha106", + "magento/module-user": "0.1.0-alpha106", + "magento/module-backup": "0.1.0-alpha106", + "magento/module-email": "0.1.0-alpha106", + "magento/module-customer": "0.1.0-alpha106", + "magento/module-translation": "0.1.0-alpha106", + "magento/module-require-js": "0.1.0-alpha106", + "magento/framework": "0.1.0-alpha106", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.1.0-alpha105", + "version": "0.1.0-alpha106", "extra": { "map": [ [ diff --git a/app/code/Magento/Backend/etc/adminhtml/cache.xml b/app/code/Magento/Backend/etc/adminhtml/cache.xml deleted file mode 100644 index 06649a0469ba5..0000000000000 --- a/app/code/Magento/Backend/etc/adminhtml/cache.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - System(config.xml, local.xml) and modules configuration files(config.xml, menu.xml). - - diff --git a/app/code/Magento/Backend/etc/di.xml b/app/code/Magento/Backend/etc/di.xml index faa8d7fc6cd3a..c4ee165192a4f 100644 --- a/app/code/Magento/Backend/etc/di.xml +++ b/app/code/Magento/Backend/etc/di.xml @@ -61,11 +61,6 @@ Magento\Backend\Model\Menu\Director\Director - - - Magento\Backend\App\Area\FrontNameResolver::PARAM_BACKEND_FRONT_NAME - - Magento\Backend\Model\UrlInterface\Proxy @@ -107,11 +102,6 @@ Magento\Backend\Helper\Data\Proxy - - - Magento\Framework\App\State::PARAM_INSTALL_DATE - - diff --git a/app/code/Magento/Backend/etc/module.xml b/app/code/Magento/Backend/etc/module.xml index 181be8d2cb604..d914257db8386 100644 --- a/app/code/Magento/Backend/etc/module.xml +++ b/app/code/Magento/Backend/etc/module.xml @@ -24,7 +24,7 @@ */ --> - + diff --git a/app/code/Magento/Backend/view/adminhtml/layout/default.xml b/app/code/Magento/Backend/view/adminhtml/layout/default.xml index 2916133e1079d..9b9951dd6a208 100644 --- a/app/code/Magento/Backend/view/adminhtml/layout/default.xml +++ b/app/code/Magento/Backend/view/adminhtml/layout/default.xml @@ -46,7 +46,6 @@ - diff --git a/app/code/Magento/Backend/view/adminhtml/requirejs-config.js b/app/code/Magento/Backend/view/adminhtml/requirejs-config.js new file mode 100644 index 0000000000000..279ff735897f8 --- /dev/null +++ b/app/code/Magento/Backend/view/adminhtml/requirejs-config.js @@ -0,0 +1,58 @@ +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License (AFL 3.0) + * that is bundled with this package in the file LICENSE_AFL.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/afl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +var config = { + map: { + '*': { + translateInline: 'mage/translate-inline', + form: 'mage/backend/form', + button: 'mage/backend/button', + accordion: 'mage/accordion', + actionLink: 'mage/backend/action-link', + validation: 'mage/backend/validation', + notification: 'mage/backend/notification', + loader: 'mage/loader_old', + loaderAjax: 'mage/loader_old', + floatingHeader: 'mage/backend/floating-header', + suggest: 'mage/backend/suggest', + mediabrowser: 'jquery/jstree/jquery.jstree', + tabs: 'mage/backend/tabs', + treeSuggest: 'mage/backend/tree-suggest', + calendar: 'mage/calendar', + dropdown: 'mage/dropdown_old', + collapsable: 'js/theme', + collapsible: 'mage/collapsible', + menu: 'mage/backend/menu', + jstree: 'jquery/jstree/jquery.jstree' + } + }, + deps: [ + 'Magento_Backend/system/validation-rules', + "js/theme", + "mage/dropdown_old", + "mage/backend/bootstrap" + ], + paths: { + "jquery/ui": "jquery/jquery-ui-1.9.2" + } +}; \ No newline at end of file diff --git a/app/code/Magento/Backend/view/adminhtml/templates/admin/loader.phtml b/app/code/Magento/Backend/view/adminhtml/templates/admin/loader.phtml deleted file mode 100644 index e657e66ff1f1a..0000000000000 --- a/app/code/Magento/Backend/view/adminhtml/templates/admin/loader.phtml +++ /dev/null @@ -1,27 +0,0 @@ - - diff --git a/app/code/Magento/Backend/view/adminhtml/templates/admin/login.phtml b/app/code/Magento/Backend/view/adminhtml/templates/admin/login.phtml index 280bae9956b76..454b647aa3d47 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/admin/login.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/admin/login.phtml @@ -39,7 +39,7 @@
- +
@@ -57,16 +57,27 @@
diff --git a/app/code/Magento/Backend/view/adminhtml/templates/admin/page.phtml b/app/code/Magento/Backend/view/adminhtml/templates/admin/page.phtml index e95aabc891ad3..b7cee3e23bd8b 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/admin/page.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/admin/page.phtml @@ -69,9 +69,5 @@
getChildHtml('before_body_end') ?> - - \ No newline at end of file diff --git a/app/code/Magento/Backend/view/adminhtml/templates/page/header.phtml b/app/code/Magento/Backend/view/adminhtml/templates/page/header.phtml index d5e6611b58080..55832a9da518f 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/page/header.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/page/header.phtml @@ -31,7 +31,7 @@
-
+ isCaseSensitive()) :?> +
+ Attention: Captcha is case sensitive.') ?> +
+
diff --git a/app/code/Magento/Captcha/view/frontend/web/captcha.js b/app/code/Magento/Captcha/view/frontend/web/captcha.js index 8d59eb7c0b1f5..b52589dc0bb41 100644 --- a/app/code/Magento/Captcha/view/frontend/web/captcha.js +++ b/app/code/Magento/Captcha/view/frontend/web/captcha.js @@ -21,9 +21,12 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /*jshint browser:true jquery:true*/ -define(["jquery","jquery/ui"], function($){ - +define([ + "jquery", + "jquery/ui" +], function($){ "use strict"; + $.widget('mage.captcha', { options: { refreshClass: 'refreshing', @@ -66,4 +69,6 @@ define(["jquery","jquery/ui"], function($){ }); } }); + + return $.mage.captcha; }); \ No newline at end of file diff --git a/app/code/Magento/Catalog/Api/AttributeSetManagementInterface.php b/app/code/Magento/Catalog/Api/AttributeSetManagementInterface.php new file mode 100644 index 0000000000000..83adf0485e5d9 --- /dev/null +++ b/app/code/Magento/Catalog/Api/AttributeSetManagementInterface.php @@ -0,0 +1,39 @@ +_set('is_wysiwyg_enabled', $isWysiwygEnabled); + return $this; + } + + /** + * @param bool|null $isHtmlAllowedOnFront + * @return $this + */ + public function setIsHtmlAllowedOnFront($isHtmlAllowedOnFront) + { + $this->_set('is_html_allowed_on_front', $isHtmlAllowedOnFront); + return $this; + } + + /** + * @param bool|null $usedForSortBy + * @return $this + */ + public function setUsedForSortBy($usedForSortBy) + { + $this->_set('used_for_sort_by', $usedForSortBy); + return $this; + } + + /** + * @param bool|null $isFilterable + * @return $this + */ + public function setIsFilterable($isFilterable) + { + $this->_set('is_filterable', $isFilterable); + return $this; + } + + /** + * @param bool|null $isFilterableInSearch + * @return $this + */ + public function setIsFilterableInSearch($isFilterableInSearch) + { + $this->_set('is_filterable_in_search', $isFilterableInSearch); + return $this; + } + + /** + * @param int|null $position + * @return $this + */ + public function setPosition($position) + { + $this->_set('position', $position); + return $this; + } + + /** + * @param string $applyTo + * @return $this + */ + public function setApplyTo($applyTo) + { + $this->_set('apply_to', $applyTo); + return $this; + } + + /** + * @param string|null $isConfigurable + * @return $this + */ + public function setIsConfigurable($isConfigurable) + { + $this->_set('is_configurable', $isConfigurable); + return $this; + } + + /** + * @param string|null $isSearchable + * @return $this + */ + public function setIsSearchable($isSearchable) + { + $this->_set('is_searchable', $isSearchable); + return $this; + } + + /** + * @param string|null $isVisibleInAdvancedSearch + * @return $this + */ + public function setIsVisibleInAdvancedSearch($isVisibleInAdvancedSearch) + { + $this->_set('is_visible_in_advanced_search', $isVisibleInAdvancedSearch); + return $this; + } + + /** + * @param string|null $isComparable + * @return $this + */ + public function setIsComparable($isComparable) + { + $this->_set('is_comparable', $isComparable); + return $this; + } + + /** + * @param string|null $isUsedForPromoRules + * @return $this + */ + public function setIsUsedForPromoRules($isUsedForPromoRules) + { + $this->_set('is_used_for_promo_rules', $isUsedForPromoRules); + return $this; + } + + /** + * @param string|null $isVisibleOnFront + * @return $this + */ + public function setIsVisibleOnFront($isVisibleOnFront) + { + $this->_set('is_visible_on_front', $isVisibleOnFront); + return $this; + } + + /** + * @param string|null $usedInProductListing + * @return $this + */ + public function setUsedInProductListing($usedInProductListing) + { + $this->_set('used_in_product_listing', $usedInProductListing); + return $this; + } + + /** + * @param bool|null $isVisible + * @return $this + */ + public function setIsVisible($isVisible) + { + $this->_set('is_visible', $isVisible); + return $this; + } + + /** + * @param string|null $scope + * @return $this + */ + public function setScope($scope) + { + $this->_set('scope', $scope); + return $this; + } + + /** + * @param int|null $attributeId + * @return $this + */ + public function setAttributeId($attributeId) + { + $this->_set('attribute_id', $attributeId); + return $this; + } + + /** + * @param string $attributeCode + * @return $this + */ + public function setAttributeCode($attributeCode) + { + $this->_set('attribute_code', $attributeCode); + return $this; + } + + /** + * @param string $frontendInput + * @return $this + */ + public function setFrontendInput($frontendInput) + { + $this->_set('frontend_input', $frontendInput); + return $this; + } + + /** + * @param string|null $entityTypeId + * @return $this + */ + public function setEntityTypeId($entityTypeId) + { + $this->_set('entity_type_id', $entityTypeId); + return $this; + } + + /** + * @param bool $isRequired + * @return $this + */ + public function setIsRequired($isRequired) + { + $this->_set('is_required', $isRequired); + return $this; + } + + /** + * @param \Magento\Eav\Api\Data\AttributeOptionInterface $options + * @return $this + */ + public function setOptions($options) + { + $this->_set('options', $options); + return $this; + } + + /** + * @param bool|null $isUserDefined + * @return $this + */ + public function setIsUserDefined($isUserDefined) + { + $this->_set('is_user_defined', $isUserDefined); + return $this; + } + + /** + * @param string $frontendLabel + * @return $this + */ + public function setDefaultFrontendLabel($frontendLabel) + { + $this->_set('frontend_label', $frontendLabel); + return $this; + } + + /** + * @param \Magento\Eav\Api\Data\AttributeFrontendLabelInterface[] + * $storeFrontendLabels + * @return $this + */ + public function setFrontendLabels($storeFrontendLabels) + { + $this->_set('frontend_labels', $storeFrontendLabels); + return $this; + } + + /** + * @param string|null $note + * @return $this + */ + public function setNote($note) + { + $this->_set('note', $note); + return $this; + } + + /** + * @param string|null $backendType + * @return $this + */ + public function setBackendType($backendType) + { + $this->_set('backend_type', $backendType); + return $this; + } + + /** + * @param string|null $backendModel + * @return $this + */ + public function setBackendModel($backendModel) + { + $this->_set('backend_model', $backendModel); + return $this; + } + + /** + * @param string|null $sourceModel + * @return $this + */ + public function setSourceModel($sourceModel) + { + $this->_set('source_model', $sourceModel); + return $this; + } + + /** + * @param string|null $defaultValue + * @return $this + */ + public function setDefaultValue($defaultValue) + { + $this->_set('default_value', $defaultValue); + return $this; + } + + /** + * @param string|null $isUnique + * @return $this + */ + public function setIsUnique($isUnique) + { + $this->_set('is_unique', $isUnique); + return $this; + } + + /** + * @param string|null $frontendClass + * @return $this + */ + public function setFrontendClass($frontendClass) + { + $this->_set('frontend_class', $frontendClass); + return $this; + } + + /** + * @param \Magento\Eav\Api\Data\AttributeValidationRuleInterface $validationRules + * @return $this + */ + public function setValidationRules($validationRules) + { + $this->_set('validation_rules', $validationRules); + return $this; + } + + /** + * {@inheritdoc} + */ + public function create() + { + /** TODO: temporary fix while problem with hasDataChanges flag not solved. MAGETWO-30324 */ + $object = parent::create(); + $object->setDataChanges(true); + return $object; + } +} diff --git a/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php b/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php new file mode 100644 index 0000000000000..d1fdc13ecf50e --- /dev/null +++ b/app/code/Magento/Catalog/Api/Data/ProductAttributeInterface.php @@ -0,0 +1,32 @@ + - */ namespace Magento\Catalog\Block\Adminhtml\Category; use Magento\Store\Model\Store; use Magento\Framework\Data\Tree\Node; +/** + * Class AbstractCategory + */ class AbstractCategory extends \Magento\Backend\Block\Template { /** @@ -68,7 +65,7 @@ public function __construct( \Magento\Catalog\Model\Resource\Category\Tree $categoryTree, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\CategoryFactory $categoryFactory, - array $data = array() + array $data = [] ) { $this->_categoryTree = $categoryTree; $this->_coreRegistry = $registry; @@ -254,8 +251,6 @@ public function getRootByIds($ids) public function getNode($parentNodeCategory, $recursionLevel = 2) { $nodeId = $parentNodeCategory->getId(); - $parentId = $parentNodeCategory->getParentId(); - $node = $this->_categoryTree->loadNode($nodeId); $node->loadChildren($recursionLevel); @@ -274,9 +269,9 @@ public function getNode($parentNodeCategory, $recursionLevel = 2) * @param array $args * @return string */ - public function getSaveUrl(array $args = array()) + public function getSaveUrl(array $args = []) { - $params = array('_current' => true); + $params = ['_current' => false, '_query' => false]; $params = array_merge($params, $args); return $this->getUrl('catalog/*/save', $params); } @@ -288,7 +283,7 @@ public function getEditUrl() { return $this->getUrl( 'catalog/category/edit', - array('_current' => true, 'store' => null, '_query' => false, 'id' => null, 'parent' => null) + ['store' => null, '_query' => false, 'id' => null, 'parent' => null] ); } @@ -301,7 +296,7 @@ public function getRootIds() { $ids = $this->getData('root_ids'); if (is_null($ids)) { - $ids = array(); + $ids = []; foreach ($this->_storeManager->getGroups() as $store) { $ids[] = $store->getRootCategoryId(); } diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/Form.php b/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/Form.php index 72bb3dc9f9675..c2478beb2c829 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/Form.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/Form.php @@ -31,6 +31,9 @@ use Magento\Backend\Block\Template; +/** + * Class Form + */ class Form extends \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory { /** @@ -38,7 +41,7 @@ class Form extends \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory * * @var array */ - protected $_additionalButtons = array(); + protected $_additionalButtons = []; /** * @var string @@ -51,6 +54,8 @@ class Form extends \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory protected $_jsonEncoder; /** + * Constructor + * * @param Template\Context $context * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder * @param \Magento\Catalog\Model\Resource\Category\Tree $categoryTree @@ -64,7 +69,7 @@ public function __construct( \Magento\Framework\Registry $registry, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Framework\Json\EncoderInterface $jsonEncoder, - array $data = array() + array $data = [] ) { $this->_jsonEncoder = $jsonEncoder; parent::__construct($context, $categoryTree, $registry, $categoryFactory, $data); @@ -88,12 +93,12 @@ protected function _prepareLayout() if (!$category->isReadonly() && $this->hasStoreRootCategory()) { $this->addButton( 'save', - array( + [ 'id' => 'save', 'label' => __('Save Category'), 'onclick' => "categorySubmit('" . $this->getSaveUrl() . "', true)", 'class' => 'save primary save-category' - ) + ] ); } @@ -101,15 +106,15 @@ protected function _prepareLayout() if ($categoryId && !in_array($categoryId, $this->getRootIds()) && $category->isDeleteable()) { $this->addButton( 'delete', - array( + [ 'id' => 'delete', 'label' => __('Delete Category'), 'onclick' => "categoryDelete('" . $this->getUrl( 'catalog/*/delete', - array('_current' => true) + ['_current' => true] ) . "', true, {$categoryId})", 'class' => 'delete' - ) + ] ); } @@ -118,12 +123,12 @@ protected function _prepareLayout() $resetPath = $categoryId ? 'catalog/*/edit' : 'catalog/*/add'; $this->addButton( 'reset', - array( + [ 'id' => 'reset', 'label' => __('Reset'), - 'onclick' => "categoryReset('" . $this->getUrl($resetPath, array('_current' => true)) . "',true)", + 'onclick' => "categoryReset('" . $this->getUrl($resetPath, ['_current' => true]) . "',true)", 'class' => 'reset' - ) + ] ); } @@ -136,7 +141,7 @@ protected function _prepareLayout() public function getStoreConfigurationUrl() { $storeId = (int)$this->getRequest()->getParam('store'); - $params = array(); + $params = []; // $params = array('section'=>'catalog'); if ($storeId) { $store = $this->_storeManager->getStore($storeId); @@ -266,9 +271,9 @@ public function getHeader() * @param array $args * @return string */ - public function getDeleteUrl(array $args = array()) + public function getDeleteUrl(array $args = []) { - $params = array('_current' => true); + $params = ['_current' => true]; $params = array_merge($params, $args); return $this->getUrl('catalog/*/delete', $params); } @@ -279,9 +284,9 @@ public function getDeleteUrl(array $args = array()) * @param array $args * @return string */ - public function getRefreshPathUrl(array $args = array()) + public function getRefreshPathUrl(array $args = []) { - $params = array('_current' => true); + $params = ['_current' => true]; $params = array_merge($params, $args); return $this->getUrl('catalog/*/refreshPath', $params); } @@ -306,6 +311,26 @@ public function isAjax() return $this->_request->isXmlHttpRequest() || $this->_request->getParam('isAjax'); } + /** + * Get parent category id + * + * @return int + */ + public function getParentCategoryId() + { + return (int)$this->templateContext->getRequest()->getParam('parent'); + } + + /** + * Get category id + * + * @return int + */ + public function getCategoryId() + { + return (int)$this->templateContext->getRequest()->getParam('id'); + } + /** * Add button block as a child block or to global Page Toolbar block if available * diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php index 3a2319950632a..ddfc1ca6251b6 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php @@ -32,6 +32,7 @@ use Magento\Backend\Block\Widget\Form; use Magento\Backend\Block\Widget\Form\Generic; use Magento\Backend\Model\Config\Source\Yesno; +use Magento\Catalog\Model\Entity\Attribute; class Front extends Generic { @@ -64,6 +65,7 @@ public function __construct( */ protected function _prepareForm() { + /** @var Attribute $attributeObject */ $attributeObject = $this->_coreRegistry->registry('entity_attribute'); /** @var \Magento\Framework\Data\Form $form */ @@ -212,6 +214,19 @@ protected function _prepareForm() 'wysiwyg_enabled', '0' ) + ->addFieldMap( + "is_searchable", + 'searchable' + ) + ->addFieldMap( + "is_visible_in_advanced_search", + 'advanced_search' + ) + ->addFieldDependence( + 'advanced_search', + 'searchable', + '1' + ) ); $form->setValues($attributeObject->getData()); diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Js.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Js.php index 51891fbcac604..a7994ffd319be 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Js.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Js.php @@ -25,7 +25,7 @@ namespace Magento\Catalog\Block\Adminhtml\Product\Edit; use Magento\Customer\Helper\Session\CurrentCustomer; -use Magento\Tax\Service\V1\TaxCalculationServiceInterface; +use Magento\Tax\Api\TaxCalculationInterface; use Magento\Tax\Model\TaxClass\Source\Product as ProductTaxClassSource; class Js extends \Magento\Backend\Block\Template @@ -38,7 +38,7 @@ class Js extends \Magento\Backend\Block\Template protected $coreRegistry = null; /** - * @var TaxCalculationServiceInterface + * @var TaxCalculationInterface */ protected $calculationService; @@ -66,7 +66,7 @@ class Js extends \Magento\Backend\Block\Template * @param \Magento\Framework\Registry $registry * @param CurrentCustomer $currentCustomer * @param \Magento\Core\Helper\Data $coreHelper - * @param TaxCalculationServiceInterface $calculationService + * @param TaxCalculationInterface $calculationService * @param ProductTaxClassSource $productTaxClassSource * @param array $data */ @@ -75,7 +75,7 @@ public function __construct( \Magento\Framework\Registry $registry, CurrentCustomer $currentCustomer, \Magento\Core\Helper\Data $coreHelper, - TaxCalculationServiceInterface $calculationService, + TaxCalculationInterface $calculationService, ProductTaxClassSource $productTaxClassSource, array $data = array() ) { diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.php index 47185ec755077..853cb0881dee8 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.php @@ -136,6 +136,7 @@ protected function _prepareForm() } } } + $form->addValues($values); $form->setFieldNameSuffix('product'); diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Group/AbstractGroup.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Group/AbstractGroup.php index 84972e0c7c89c..c93762712b872 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Group/AbstractGroup.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Group/AbstractGroup.php @@ -24,7 +24,8 @@ namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Price\Group; use Magento\Backend\Block\Widget; -use Magento\Customer\Service\V1\CustomerGroupServiceInterface; +use Magento\Customer\Api\GroupManagementInterface; +use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Framework\Data\Form\Element\Renderer\RendererInterface; /** @@ -73,30 +74,46 @@ abstract class AbstractGroup extends Widget implements RendererInterface protected $_directoryHelper; /** - * @var CustomerGroupServiceInterface + * @var GroupRepositoryInterface */ - protected $_groupService; + protected $_groupRepository; + + /** + * @var GroupManagementInterface + */ + protected $_groupManagement; + + /** + * @var \Magento\Framework\Api\SearchCriteriaDataBuilder + */ + protected $_searchCriteriaDataBuilder; /** * @param \Magento\Backend\Block\Template\Context $context - * @param CustomerGroupServiceInterface $groupService + * @param GroupRepositoryInterface $groupRepository * @param \Magento\Directory\Helper\Data $directoryHelper * @param \Magento\Catalog\Helper\Data $catalogData * @param \Magento\Framework\Registry $registry + * @param GroupManagementInterface $groupManagement + * @param \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaDataBuilder * @param array $data */ public function __construct( \Magento\Backend\Block\Template\Context $context, - CustomerGroupServiceInterface $groupService, + GroupRepositoryInterface $groupRepository, \Magento\Directory\Helper\Data $directoryHelper, \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\Registry $registry, + GroupManagementInterface $groupManagement, + \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaDataBuilder, array $data = array() ) { - $this->_groupService = $groupService; + $this->_groupRepository = $groupRepository; $this->_directoryHelper = $directoryHelper; $this->_catalogData = $catalogData; $this->_coreRegistry = $registry; + $this->_groupManagement = $groupManagement; + $this->_searchCriteriaDataBuilder = $searchCriteriaDataBuilder; parent::__construct($context, $data); } @@ -190,7 +207,8 @@ public function getCustomerGroups($groupId = null) if (!$this->_catalogData->isModuleEnabled('Magento_Customer')) { return array(); } - $groups = $this->_groupService->getGroups(); + /** @var \Magento\Customer\Api\Data\GroupInterface[] $groups */ + $groups = $this->_groupRepository->getList($this->_searchCriteriaDataBuilder->create()); $this->_customerGroups = $this->_getInitialCustomerGroups(); foreach ($groups as $group) { @@ -283,7 +301,7 @@ public function getWebsites() */ public function getDefaultCustomerGroup() { - return CustomerGroupServiceInterface::CUST_GROUP_ALL; + return $this->_groupManagement->getAllCustomersGroup()->getId(); } /** diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Tier.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Tier.php index e5d093d295fef..2f90ca1046b72 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Tier.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price/Tier.php @@ -23,8 +23,6 @@ */ namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Price; -use Magento\Customer\Service\V1\CustomerGroupServiceInterface; - /** * Adminhtml tier price item renderer */ @@ -42,7 +40,7 @@ class Tier extends Group\AbstractGroup */ protected function _getInitialCustomerGroups() { - return array(CustomerGroupServiceInterface::CUST_GROUP_ALL => __('ALL GROUPS')); + return array($this->_groupManagement->getAllCustomersGroup()->getId() => __('ALL GROUPS')); } /** diff --git a/app/code/Magento/Catalog/Block/Category/View.php b/app/code/Magento/Catalog/Block/Category/View.php index fc94a7f9d076c..4f475dadbd77c 100644 --- a/app/code/Magento/Catalog/Block/Category/View.php +++ b/app/code/Magento/Catalog/Block/Category/View.php @@ -50,20 +50,20 @@ class View extends \Magento\Framework\View\Element\Template implements \Magento\ /** * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Catalog\Model\Layer\Category $catalogLayer + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param \Magento\Framework\Registry $registry * @param \Magento\Catalog\Helper\Category $categoryHelper * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, - \Magento\Catalog\Model\Layer\Category $catalogLayer, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Framework\Registry $registry, \Magento\Catalog\Helper\Category $categoryHelper, array $data = array() ) { $this->_categoryHelper = $categoryHelper; - $this->_catalogLayer = $catalogLayer; + $this->_catalogLayer = $layerResolver->get(); $this->_coreRegistry = $registry; parent::__construct($context, $data); } diff --git a/app/code/Magento/Catalog/Block/Navigation.php b/app/code/Magento/Catalog/Block/Navigation.php index f84ad94588949..7995eca2c0684 100644 --- a/app/code/Magento/Catalog/Block/Navigation.php +++ b/app/code/Magento/Catalog/Block/Navigation.php @@ -74,7 +74,7 @@ class Navigation extends \Magento\Framework\View\Element\Template implements \Ma /** * Catalog layer * - * @var \Magento\Catalog\Model\Layer\Category + * @var \Magento\Catalog\Model\Layer */ protected $_catalogLayer; @@ -94,7 +94,7 @@ class Navigation extends \Magento\Framework\View\Element\Template implements \Ma * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory * @param \Magento\Catalog\Model\Resource\Product\CollectionFactory $productCollectionFactory - * @param \Magento\Catalog\Model\Layer\Category $catalogLayer + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param \Magento\Framework\App\Http\Context $httpContext * @param \Magento\Catalog\Helper\Category $catalogCategory * @param \Magento\Framework\Registry $registry @@ -105,7 +105,7 @@ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Catalog\Model\Resource\Product\CollectionFactory $productCollectionFactory, - \Magento\Catalog\Model\Layer\Category $catalogLayer, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Framework\App\Http\Context $httpContext, \Magento\Catalog\Helper\Category $catalogCategory, \Magento\Framework\Registry $registry, @@ -113,14 +113,13 @@ public function __construct( array $data = array() ) { $this->_productCollectionFactory = $productCollectionFactory; - $this->_catalogLayer = $catalogLayer; + $this->_catalogLayer = $layerResolver->get(); $this->httpContext = $httpContext; $this->_catalogCategory = $catalogCategory; $this->_registry = $registry; $this->flatState = $flatState; $this->_categoryInstance = $categoryFactory->create(); parent::__construct($context, $data); - $this->_isScopePrivate = true; } /** diff --git a/app/code/Magento/Catalog/Block/Product/ListProduct.php b/app/code/Magento/Catalog/Block/Product/ListProduct.php index 3df003f81115b..201a8aa8b991f 100644 --- a/app/code/Magento/Catalog/Block/Product/ListProduct.php +++ b/app/code/Magento/Catalog/Block/Product/ListProduct.php @@ -72,18 +72,18 @@ class ListProduct extends AbstractProduct implements IdentityInterface * @param Context $context * @param \Magento\Core\Helper\PostData $postDataHelper * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory - * @param \Magento\Catalog\Model\Layer $catalogLayer + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param array $data */ public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Core\Helper\PostData $postDataHelper, \Magento\Catalog\Model\CategoryFactory $categoryFactory, - \Magento\Catalog\Model\Layer $catalogLayer, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, array $data = array() ) { $this->_categoryFactory = $categoryFactory; - $this->_catalogLayer = $catalogLayer; + $this->_catalogLayer = $layerResolver->get(); $this->_postDataHelper = $postDataHelper; parent::__construct( $context, diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php b/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php index 29ffef6917afa..371fcc4193840 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php @@ -35,19 +35,11 @@ class Promotion extends \Magento\Catalog\Block\Product\ListProduct */ protected $_productCollectionFactory; - /** - * Layer factory - * - * @var \Magento\Catalog\Model\LayerFactory - */ - protected $_layerFactory; - /** * @param \Magento\Catalog\Block\Product\Context $context * @param \Magento\Core\Helper\PostData $postDataHelper * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory - * @param \Magento\Catalog\Model\Layer\Category $catalogLayer - * @param \Magento\Catalog\Model\LayerFactory $layerFactory + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param CollectionFactory $productCollectionFactory * @param array $data */ @@ -55,18 +47,16 @@ public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Core\Helper\PostData $postDataHelper, \Magento\Catalog\Model\CategoryFactory $categoryFactory, - \Magento\Catalog\Model\Layer\Category $catalogLayer, - \Magento\Catalog\Model\LayerFactory $layerFactory, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, CollectionFactory $productCollectionFactory, array $data = array() ) { - $this->_layerFactory = $layerFactory; $this->_productCollectionFactory = $productCollectionFactory; parent::__construct( $context, $postDataHelper, $categoryFactory, - $catalogLayer, + $layerResolver, $data ); } @@ -79,7 +69,7 @@ protected function _getProductCollection() if (is_null($this->_productCollection)) { /** @var Collection $collection */ $collection = $this->_productCollectionFactory->create(); - $this->_layerFactory->create()->prepareProductCollection($collection); + $this->_catalogLayer->prepareProductCollection($collection); $collection->addAttributeToFilter('promotion', 1)->addStoreFilter(); diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Random.php b/app/code/Magento/Catalog/Block/Product/ProductList/Random.php index 5eda5e9e95059..0539e34881330 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Random.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Random.php @@ -37,19 +37,11 @@ class Random extends \Magento\Catalog\Block\Product\ListProduct */ protected $_productCollectionFactory; - /** - * Layer factory - * - * @var \Magento\Catalog\Model\LayerFactory - */ - protected $_layerFactory; - /** * @param \Magento\Catalog\Block\Product\Context $context * @param \Magento\Core\Helper\PostData $postDataHelper * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory - * @param \Magento\Catalog\Model\Layer\Category $catalogLayer - * @param \Magento\Catalog\Model\LayerFactory $layerFactory + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param \Magento\Catalog\Model\Resource\Product\CollectionFactory $productCollectionFactory * @param array $data */ @@ -57,18 +49,16 @@ public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Core\Helper\PostData $postDataHelper, \Magento\Catalog\Model\CategoryFactory $categoryFactory, - \Magento\Catalog\Model\Layer\Category $catalogLayer, - \Magento\Catalog\Model\LayerFactory $layerFactory, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Catalog\Model\Resource\Product\CollectionFactory $productCollectionFactory, array $data = array() ) { - $this->_layerFactory = $layerFactory; $this->_productCollectionFactory = $productCollectionFactory; parent::__construct( $context, $postDataHelper, $categoryFactory, - $catalogLayer, + $layerResolver, $data ); } @@ -81,7 +71,7 @@ protected function _getProductCollection() if (is_null($this->_productCollection)) { /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */ $collection = $this->_productCollectionFactory->create(); - $this->_layerFactory->create()->prepareProductCollection($collection); + $this->_catalogLayer->prepareProductCollection($collection); $collection->getSelect()->order('rand()'); $collection->addStoreFilter(); $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0; diff --git a/app/code/Magento/Catalog/Block/Product/View.php b/app/code/Magento/Catalog/Block/Product/View.php index 6b447738a3e97..3bd14880284df 100644 --- a/app/code/Magento/Catalog/Block/Product/View.php +++ b/app/code/Magento/Catalog/Block/Product/View.php @@ -24,7 +24,7 @@ namespace Magento\Catalog\Block\Product; use Magento\Catalog\Model\Product; -use Magento\Tax\Service\V1\TaxCalculationServiceInterface; +use Magento\Tax\Api\TaxCalculationInterface; /** * Product View block @@ -76,7 +76,7 @@ class View extends AbstractProduct implements \Magento\Framework\View\Block\Iden protected $customerSession; /** - * @var TaxCalculationServiceInterface + * @var TaxCalculationInterface */ protected $taxCalculationService; @@ -90,7 +90,7 @@ class View extends AbstractProduct implements \Magento\Framework\View\Block\Iden * @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig * @param \Magento\Framework\Locale\FormatInterface $localeFormat * @param \Magento\Customer\Model\Session $customerSession - * @param TaxCalculationServiceInterface $taxCalculationService + * @param TaxCalculationInterface $taxCalculationService * @param array $data */ public function __construct( @@ -103,7 +103,7 @@ public function __construct( \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Customer\Model\Session $customerSession, - TaxCalculationServiceInterface $taxCalculationService, + TaxCalculationInterface $taxCalculationService, array $data = array() ) { $this->_productHelper = $productHelper; @@ -253,7 +253,7 @@ public function getJsonConfig() $tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList(); foreach ($tierPricesList as $tierPrice) { - $tierPrices[] = $this->_coreData->currency($tierPrice['price']->getValue(), false, false); + $tierPrices[] = $tierPrice['price']->getValue(); } $config = array( 'productId' => $product->getId(), @@ -261,26 +261,10 @@ public function getJsonConfig() 'includeTax' => $this->_taxData->priceIncludesTax() ? 'true' : 'false', 'showIncludeTax' => $this->_taxData->displayPriceIncludingTax(), 'showBothPrices' => $this->_taxData->displayBothPrices(), - 'productPrice' => $this->_coreData->currency( - $product->getPriceInfo()->getPrice('final_price')->getValue(), - false, - false - ), - 'productOldPrice' => $this->_coreData->currency( - $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), - false, - false - ), - 'inclTaxPrice' => $this->_coreData->currency( - $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(), - false, - false - ), - 'exclTaxPrice' => $this->_coreData->currency( - $product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(), - false, - false - ), + 'productPrice' => $product->getPriceInfo()->getPrice('final_price')->getValue(), + 'productOldPrice' => $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), + 'inclTaxPrice' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(), + 'exclTaxPrice' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(), 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'idSuffix' => '_clone', diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index 3bf1a84148000..a2a32616a7e92 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -1,6 +1,5 @@ resultRedirectFactory->create(); + $category = $this->_initCategory(); + if (!$category) { - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]); } $storeId = $this->getRequest()->getParam('store'); - $refreshTree = 'false'; + $refreshTree = false; $data = $this->getRequest()->getPost(); if ($data) { $category->addData($this->_filterCategoryPostData($data['general'])); @@ -133,7 +139,7 @@ public function execute() } $this->_eventManager->dispatch( 'catalog_category_prepare_save', - array('category' => $category, 'request' => $this->getRequest()) + ['category' => $category, 'request' => $this->getRequest()] ); /** @@ -172,39 +178,38 @@ public function execute() $category->save(); $this->messageManager->addSuccess(__('You saved the category.')); - $refreshTree = 'true'; + $refreshTree = true; } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); $this->_getSession()->setCategoryData($data); - $refreshTree = 'false'; + $refreshTree = false; } } if ($this->getRequest()->getPost('return_session_messages_only')) { $category->load($category->getId()); // to obtain truncated category name - /** @var $block \Magento\Framework\View\Element\Messages */ $block = $this->layoutFactory->create()->getMessagesBlock(); $block->setMessages($this->messageManager->getMessages(true)); /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ $resultJson = $this->resultJsonFactory->create(); - return $resultJson->setData([ - 'messages' => $block->getGroupedHtml(), - 'error' => $refreshTree !== 'true', - 'category' => $category->toArray() - ]); - } else { - $url = $this->getUrl('catalog/*/edit', array('_current' => true, 'id' => $category->getId())); - $body = ''; + return $resultJson->setData( + [ + 'messages' => $block->getGroupedHtml(), + 'error' => !$refreshTree, + 'category' => $category->toArray() + ] + ); } - /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ - $resultRaw = $this->resultRawFactory->create(); - return $resultRaw->setContents($body); + + return $resultRedirect->setPath( + 'catalog/*/edit', + [ + '_current' => true, + 'id' => $category->getId() + ] + ); } } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php index 3ac3ac4ec5c06..b20b1d7f210d9 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php @@ -200,13 +200,6 @@ public function execute() } $this->_eventManager->dispatch('catalog_product_to_website_change', array('products' => $productIds)); - - $this->messageManager->addNotice( - __( - 'Please refresh "Product EAV" in System -> Index Management.', - $this->getUrl('adminhtml/process/list') - ) - ); } $this->messageManager->addSuccess( diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 6eb21e6a00d43..c229dced7a040 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -24,19 +24,55 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; +use Magento\Catalog\Model\Product\AttributeSet\AlreadyExistsException; + class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute { + /** + * @var \Magento\Catalog\Model\Product\AttributeSet\BuildFactory + */ + protected $buildFactory; + + /** + * @var \Magento\Framework\Filter\FilterManager + */ + protected $filterManager; + + /** + * @var \Magento\Catalog\Helper\Product + */ + protected $productHelper; + + /** + * @var \Magento\Catalog\Model\Resource\Eav\AttributeFactory + */ + protected $attributeFactory; + + /** + * @var \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory + */ + protected $validatorFactory; + + /** + * @var \Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory + */ + protected $groupCollectionFactory; + /** * @var \Magento\Backend\Model\View\Result\RedirectFactory */ protected $resultRedirectFactory; /** - * Constructor - * * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Cache\FrontendInterface $attributeLabelCache * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Catalog\Model\Product\AttributeSet\BuildFactory $buildFactory + * @param \Magento\Catalog\Model\Resource\Eav\AttributeFactory $attributeFactory + * @param \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory + * @param \Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory + * @param \Magento\Framework\Filter\FilterManager $filterManager + * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ @@ -45,9 +81,21 @@ public function __construct( \Magento\Framework\Cache\FrontendInterface $attributeLabelCache, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\View\Result\PageFactory $resultPageFactory, + \Magento\Catalog\Model\Product\AttributeSet\BuildFactory $buildFactory, + \Magento\Catalog\Model\Resource\Eav\AttributeFactory $attributeFactory, + \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory, + \Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory, + \Magento\Framework\Filter\FilterManager $filterManager, + \Magento\Catalog\Helper\Product $productHelper, \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory ) { parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory); + $this->buildFactory = $buildFactory; + $this->filterManager = $filterManager; + $this->productHelper = $productHelper; + $this->attributeFactory = $attributeFactory; + $this->validatorFactory = $validatorFactory; + $this->groupCollectionFactory = $groupCollectionFactory; $this->resultRedirectFactory = $resultRedirectFactory; } @@ -59,32 +107,24 @@ public function execute() $data = $this->getRequest()->getPost(); $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { - /** @var $session \Magento\Backend\Model\Auth\Session */ - $session = $this->_objectManager->get('Magento\Backend\Model\Session'); + $setId = $this->getRequest()->getParam('set'); - $isNewAttributeSet = false; + $attributeSet = null; if (!empty($data['new_attribute_set_name'])) { - /** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */ - $attributeSet = $this->_objectManager->create('Magento\Eav\Model\Entity\Attribute\Set'); - $name = $this->_objectManager->get( - 'Magento\Framework\Filter\FilterManager' - )->stripTags( - $data['new_attribute_set_name'] - ); + $name = $this->filterManager->stripTags($data['new_attribute_set_name']); $name = trim($name); - $attributeSet->setEntityTypeId($this->_entityTypeId)->load($name, 'attribute_set_name'); - - if ($attributeSet->getId()) { + + try { + /** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */ + $attributeSet = $this->buildFactory->create() + ->setEntityTypeId($this->_entityTypeId) + ->setSkeletonId($setId) + ->setName($name) + ->getAttributeSet(); + } catch (AlreadyExistsException $alreadyExists) { $this->messageManager->addError(__('Attribute Set with name \'%1\' already exists.', $name)); $this->messageManager->setAttributeData($data); return $resultRedirect->setPath('catalog/*/edit', ['_current' => true]); - } - - try { - $attributeSet->setAttributeSetName($name)->validate(); - $attributeSet->save(); - $attributeSet->initFromSkeleton($this->getRequest()->getParam('set'))->save(); - $isNewAttributeSet = true; } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { @@ -94,11 +134,9 @@ public function execute() $redirectBack = $this->getRequest()->getParam('back', false); /* @var $model \Magento\Catalog\Model\Resource\Eav\Attribute */ - $model = $this->_objectManager->create('Magento\Catalog\Model\Resource\Eav\Attribute'); - /* @var $helper \Magento\Catalog\Helper\Product */ - $helper = $this->_objectManager->get('Magento\Catalog\Helper\Product'); + $model = $this->attributeFactory->create(); - $id = $this->getRequest()->getParam('attribute_id'); + $attributeId = $this->getRequest()->getParam('attribute_id'); $attributeCode = $this->getRequest()->getParam('attribute_code'); $frontendLabel = $this->getRequest()->getParam('frontend_label'); @@ -113,7 +151,7 @@ public function execute() $attributeCode ) ); - return $resultRedirect->setPath('catalog/*/edit', ['attribute_id' => $id, '_current' => true]); + return $resultRedirect->setPath('catalog/*/edit', ['attribute_id' => $attributeId, '_current' => true]); } } $data['attribute_code'] = $attributeCode; @@ -121,19 +159,17 @@ public function execute() //validate frontend_input if (isset($data['frontend_input'])) { /** @var $inputType \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator */ - $inputType = $this->_objectManager->create( - 'Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator' - ); + $inputType = $this->validatorFactory->create(); if (!$inputType->isValid($data['frontend_input'])) { foreach ($inputType->getMessages() as $message) { $this->messageManager->addError($message); } - return $resultRedirect->setPath('catalog/*/edit', ['attribute_id' => $id, '_current' => true]); + return $resultRedirect->setPath('catalog/*/edit', ['attribute_id' => $attributeId, '_current' => true]); } } - if ($id) { - $model->load($id); + if ($attributeId) { + $model->load($attributeId); if (!$model->getId()) { $this->messageManager->addError(__('This attribute no longer exists.')); return $resultRedirect->setPath('catalog/*/'); @@ -141,7 +177,7 @@ public function execute() // entity type check if ($model->getEntityTypeId() != $this->_entityTypeId) { $this->messageManager->addError(__('You can\'t update your attribute.')); - $session->setAttributeData($data); + $this->_session->setAttributeData($data); return $resultRedirect->setPath('catalog/*/'); } @@ -152,8 +188,12 @@ public function execute() /** * @todo add to helper and specify all relations for properties */ - $data['source_model'] = $helper->getAttributeSourceModelByInputType($data['frontend_input']); - $data['backend_model'] = $helper->getAttributeBackendModelByInputType($data['frontend_input']); + $data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType( + $data['frontend_input'] + ); + $data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType( + $data['frontend_input'] + ); } $data += array('is_filterable' => 0, 'is_filterable_in_search' => 0, 'apply_to' => array()); @@ -174,20 +214,18 @@ public function execute() $model->addData($data); - if (!$id) { + if (!$attributeId) { $model->setEntityTypeId($this->_entityTypeId); $model->setIsUserDefined(1); } $groupCode = $this->getRequest()->getParam('group'); - if ($this->getRequest()->getParam('set') && $groupCode) { + if ($setId && $groupCode) { // For creating product attribute on product page we need specify attribute set and group - $attributeSetId = $isNewAttributeSet ? $attributeSet->getId() : $this->getRequest()->getParam('set'); - $groupCollection = $isNewAttributeSet ? $attributeSet->getGroups() : $this->_objectManager->create( - 'Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection' - )->setAttributeSetFilter( - $attributeSetId - )->load(); + $attributeSetId = $attributeSet ? $attributeSet->getId() : $setId; + $groupCollection = $attributeSet + ? $attributeSet->getGroups() + : $this->groupCollectionFactory->create()->setAttributeSetFilter($attributeSetId)->load(); foreach ($groupCollection as $group) { if ($group->getAttributeGroupCode() == $groupCode) { $attributeGroupId = $group->getAttributeGroupId(); @@ -203,15 +241,15 @@ public function execute() $this->messageManager->addSuccess(__('You saved the product attribute.')); $this->_attributeLabelCache->clean(); - $session->setAttributeData(false); + $this->_session->setAttributeData(false); if ($this->getRequest()->getParam('popup')) { $requestParams = array( - 'id' => $this->getRequest()->getParam('product'), + 'attributeId' => $this->getRequest()->getParam('product'), 'attribute' => $model->getId(), '_current' => true, 'product_tab' => $this->getRequest()->getParam('product_tab') ); - if ($isNewAttributeSet) { + if (!is_null($attributeSet)) { $requestParams['new_attribute_set_id'] = $attributeSet->getId(); } $resultRedirect->setPath('catalog/product/addAttribute', $requestParams); @@ -223,8 +261,8 @@ public function execute() return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); - $session->setAttributeData($data); - return $resultRedirect->setPath('catalog/*/edit', ['attribute_id' => $id, '_current' => true]); + $this->_session->setAttributeData($data); + return $resultRedirect->setPath('catalog/*/edit', ['attribute_id' => $attributeId, '_current' => true]); } } return $resultRedirect->setPath('catalog/*/'); diff --git a/app/code/Magento/Catalog/Controller/Category/View.php b/app/code/Magento/Catalog/Controller/Category/View.php index 4f927a51e5c79..e119ac28c80a4 100644 --- a/app/code/Magento/Catalog/Controller/Category/View.php +++ b/app/code/Magento/Catalog/Controller/Category/View.php @@ -25,6 +25,7 @@ namespace Magento\Catalog\Controller\Category; use Magento\Framework\View\Result\PageFactory; +use Magento\Catalog\Model\Layer\Resolver; class View extends \Magento\Framework\App\Action\Action { @@ -71,6 +72,13 @@ class View extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; + /** + * Catalog Layer Resolver + * + * @var Resolver + */ + private $layerResolver; + /** * Constructor * @@ -81,6 +89,7 @@ class View extends \Magento\Framework\App\Action\Action * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator + * @param Resolver $layerResolver * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( @@ -91,8 +100,10 @@ public function __construct( \Magento\Framework\Registry $coreRegistry, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, - PageFactory $resultPageFactory + PageFactory $resultPageFactory, + Resolver $layerResolver ) { + parent::__construct($context); $this->_storeManager = $storeManager; $this->_categoryFactory = $categoryFactory; $this->_catalogDesign = $catalogDesign; @@ -100,7 +111,7 @@ public function __construct( $this->_coreRegistry = $coreRegistry; $this->categoryUrlPathGenerator = $categoryUrlPathGenerator; $this->resultPageFactory = $resultPageFactory; - parent::__construct($context); + $this->layerResolver = $layerResolver; } /** @@ -153,6 +164,7 @@ public function execute() } $category = $this->_initCategory(); if ($category) { + $this->layerResolver->create(Resolver::CATALOG_LAYER_CATEGORY); $settings = $this->_catalogDesign->getDesignSettings($category); // apply custom design diff --git a/app/code/Magento/Catalog/Helper/Data.php b/app/code/Magento/Catalog/Helper/Data.php index aa81392fb0a37..4aea9669cc42c 100644 --- a/app/code/Magento/Catalog/Helper/Data.php +++ b/app/code/Magento/Catalog/Helper/Data.php @@ -24,9 +24,7 @@ namespace Magento\Catalog\Helper; use Magento\Framework\Pricing\PriceCurrencyInterface; -use Magento\Tax\Service\V1\Data\QuoteDetailsBuilder; -use Magento\Tax\Service\V1\Data\QuoteDetails\ItemBuilder as QuoteDetailsItemBuilder; -use Magento\Tax\Service\V1\Data\TaxClassKey; +use Magento\Tax\Api\Data\TaxClassKeyInterface; use Magento\Customer\Model\Address\Converter as AddressConverter; use Magento\Customer\Model\Session as CustomerSession; use Magento\Tax\Model\Config; @@ -142,7 +140,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper /** * Tax class key builder * - * @var \Magento\Tax\Service\V1\Data\TaxClassKeyBuilder + * @var \Magento\Tax\Api\Data\TaxClassKeyDataBuilder */ protected $_taxClassKeyBuilder; @@ -156,14 +154,14 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper /** * Quote details builder * - * @var QuoteDetailsBuilder + * @var \Magento\Tax\Api\Data\QuoteDetailsDataBuilder */ protected $_quoteDetailsBuilder; /** * Quote details item builder * - * @var QuoteDetailsItemBuilder + * @var \Magento\Tax\Api\Data\QuoteDetailsItemDataBuilder */ protected $_quoteDetailsItemBuilder; @@ -182,7 +180,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper /** * Tax calculation service interface * - * @var \Magento\Tax\Service\V1\TaxCalculationServiceInterface + * @var \Magento\Tax\Api\TaxCalculationInterface */ protected $_taxCalculationService; @@ -206,11 +204,11 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Catalog\Model\Template\Filter\Factory $templateFilterFactory * @param string $templateFilterModel - * @param TaxClassKeyBuilder $taxClassKeyBuilder + * @param \Magento\Tax\Api\Data\TaxClassKeyDataBuilder $taxClassKeyBuilder * @param Config $taxConfig - * @param QuoteDetailsBuilder $quoteDetailsBuilder - * @param QuoteDetailsItemBuilder $quoteDetailsItemBuilder - * @param TaxCalculationServiceInterface $taxCalculationService + * @param \Magento\Tax\Api\Data\QuoteDetailsDataBuilder $quoteDetailsBuilder + * @param \Magento\Tax\Api\Data\QuoteDetailsItemDataBuilder $quoteDetailsItemBuilder + * @param \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService * @param CustomerSession $customerSession * @param AddressConverter $addressConverter * @param PriceCurrencyInterface $priceCurrency @@ -228,11 +226,11 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Catalog\Model\Template\Filter\Factory $templateFilterFactory, $templateFilterModel, - \Magento\Tax\Service\V1\Data\TaxClassKeyBuilder $taxClassKeyBuilder, + \Magento\Tax\Api\Data\TaxClassKeyDataBuilder $taxClassKeyBuilder, \Magento\Tax\Model\Config $taxConfig, - QuoteDetailsBuilder $quoteDetailsBuilder, - QuoteDetailsItemBuilder $quoteDetailsItemBuilder, - \Magento\Tax\Service\V1\TaxCalculationServiceInterface $taxCalculationService, + \Magento\Tax\Api\Data\QuoteDetailsDataBuilder $quoteDetailsBuilder, + \Magento\Tax\Api\Data\QuoteDetailsItemDataBuilder $quoteDetailsItemBuilder, + \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService, CustomerSession $customerSession, AddressConverter $addressConverter, PriceCurrencyInterface $priceCurrency @@ -532,8 +530,9 @@ public function getTaxPrice( ->setCode($product->getSku()) ->setShortDescription($product->getShortDescription()) ->setTaxClassKey( - $this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID) - ->setValue($product->getTaxClassId())->create() + $this->_taxClassKeyBuilder->setType(TaxClassKeyInterface::TYPE_ID) + ->setValue($product->getTaxClassId()) + ->create() )->setTaxIncluded($priceIncludesTax) ->setType('product') ->setUnitPrice($price) @@ -542,8 +541,9 @@ public function getTaxPrice( ->setShippingAddress($shippingAddressDataObject) ->setBillingAddress($billingAddressDataObject) ->setCustomerTaxClassKey( - $this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID) - ->setValue($ctc)->create() + $this->_taxClassKeyBuilder->setType(TaxClassKeyInterface::TYPE_ID) + ->setValue($ctc) + ->create() )->setItems([$item]) ->setCustomerId($this->_customerSession->getCustomerId()) ->create(); diff --git a/app/code/Magento/Catalog/Model/AbstractModel.php b/app/code/Magento/Catalog/Model/AbstractModel.php index 3a567565f1d7e..f511b009895b7 100644 --- a/app/code/Magento/Catalog/Model/AbstractModel.php +++ b/app/code/Magento/Catalog/Model/AbstractModel.php @@ -28,7 +28,7 @@ * * @author Magento Core Team */ -abstract class AbstractModel extends \Magento\Framework\Model\AbstractModel +abstract class AbstractModel extends \Magento\Framework\Model\AbstractExtensibleModel { /** * Attribute default values @@ -78,6 +78,7 @@ abstract class AbstractModel extends \Magento\Framework\Model\AbstractModel /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Api\MetadataServiceInterface $metadataService * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\Db $resourceCollection @@ -86,13 +87,14 @@ abstract class AbstractModel extends \Magento\Framework\Model\AbstractModel public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Framework\Api\MetadataServiceInterface $metadataService, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = array() ) { $this->_storeManager = $storeManager; - parent::__construct($context, $registry, $resource, $resourceCollection, $data); + parent::__construct($context, $registry, $metadataService, $resource, $resourceCollection, $data); } /** @@ -328,10 +330,10 @@ public function getExistsStoreValueFlag($attributeCode) * * @return \Magento\Catalog\Model\AbstractModel */ - protected function _beforeSave() + public function beforeSave() { $this->unlockAttributes(); - return parent::_beforeSave(); + return parent::beforeSave(); } /** diff --git a/app/code/Magento/Catalog/Model/Category.php b/app/code/Magento/Catalog/Model/Category.php index f7f2197b8b5eb..f95aac33243a4 100644 --- a/app/code/Magento/Catalog/Model/Category.php +++ b/app/code/Magento/Catalog/Model/Category.php @@ -27,6 +27,7 @@ use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; use Magento\UrlRewrite\Model\UrlFinderInterface; +use Magento\Framework\Convert\ConvertArray; /** * Catalog category @@ -37,13 +38,15 @@ * @method int getMovedCategoryId() * @method Category setAffectedCategoryIds(array $categoryIds) * @method array getAffectedCategoryIds() - * @method string getUrlKey() * @method Category setUrlKey(string $urlKey) * @method Category setUrlPath(string $urlPath) * * @SuppressWarnings(PHPMD.LongVariable) */ -class Category extends \Magento\Catalog\Model\AbstractModel implements \Magento\Framework\Object\IdentityInterface +class Category extends \Magento\Catalog\Model\AbstractModel implements + \Magento\Framework\Object\IdentityInterface, + \Magento\Catalog\Api\Data\CategoryInterface, + \Magento\Catalog\Api\Data\CategoryTreeInterface { /** * Entity code. @@ -186,6 +189,7 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements \Magento\ /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService * @param \Magento\Framework\StoreManagerInterface $storeManager * @param Resource\Category\Tree $categoryTreeResource * @param Resource\Category\TreeFactory $categoryTreeFactory @@ -206,6 +210,7 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements \Magento\ public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Resource\Category\Tree $categoryTreeResource, \Magento\Catalog\Model\Resource\Category\TreeFactory $categoryTreeFactory, @@ -235,7 +240,15 @@ public function __construct( $this->categoryUrlPathGenerator = $categoryUrlPathGenerator; $this->urlFinder = $urlFinder; $this->indexerRegistry = $indexerRegistry; - parent::__construct($context, $registry, $storeManager, $resource, $resourceCollection, $data); + parent::__construct( + $context, + $registry, + $metadataService, + $storeManager, + $resource, + $resourceCollection, + $data + ); } /** @@ -613,6 +626,10 @@ public function getParentCategory() */ public function getParentId() { + $parentId = $this->getData('parent_id'); + if (isset($parentId)) { + return $parentId; + } $parentIds = $this->getParentIds(); return intval(array_pop($parentIds)); } @@ -803,12 +820,12 @@ public function getName() * @throws \Magento\Framework\Model\Exception * @return $this */ - protected function _beforeDelete() + public function beforeDelete() { if ($this->getResource()->isForbiddenToDelete($this->getId())) { throw new \Magento\Framework\Model\Exception("Can't delete root category."); } - return parent::_beforeDelete(); + return parent::beforeDelete(); } /** @@ -990,9 +1007,9 @@ public function validate() * * @return \Magento\Catalog\Model\Category */ - protected function _afterSave() + public function afterSave() { - $result = parent::_afterSave(); + $result = parent::afterSave(); $this->_getResource()->addCommitCallback(array($this, 'reindex')); return $result; } @@ -1021,10 +1038,10 @@ public function reindex() * * @return \Magento\Framework\Model\AbstractModel */ - protected function _afterDeleteCommit() + public function afterDeleteCommit() { $this->reindex(); - return parent::_afterDeleteCommit(); + return parent::afterDeleteCommit(); } /** @@ -1042,4 +1059,139 @@ public function getIdentities() } return $identities; } + + /** + * @return string|null + */ + public function getPath() + { + return $this->getData('path'); + } + + /** + * @return int|null + */ + public function getPosition() + { + return $this->getData('position'); + } + + /** + * @return int + */ + public function getChildrenCount() + { + return $this->getData('children_count'); + } + + /** + * @return string|null + */ + public function getCreatedAt() + { + return $this->getData('created_at'); + } + + /** + * @return string|null + */ + public function getUpdatedAt() + { + return $this->getData('updated_at'); + } + + /** + * @return bool + */ + public function getIsActive() + { + return $this->getData('is_active'); + } + + /** + * @return int|null + */ + public function getCategoryId() + { + return $this->getData('category_id'); + } + + /** + * @return string|null + */ + public function getDisplayMode() + { + return $this->getData('display_mode'); + } + + /** + * @return bool|null + */ + public function getIncludeInMenu() + { + return $this->getData('include_in_menu'); + } + + /** + * @return string|null + */ + public function getUrlKey() + { + return $this->getData('url_key'); + } + + /** + * @return \Magento\Catalog\Api\Data\CategoryTreeInterface[]|null + */ + public function getChildrenData() + { + return $this->getData('children_data'); + } + + /** + * Return Data Object data in array format. + * + * @return array + */ + public function __toArray() + { + $data = $this->_data; + $hasToArray = function ($model) { + return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']); + }; + foreach ($data as $key => $value) { + if ($hasToArray($value)) { + $data[$key] = $value->__toArray(); + } elseif (is_array($value)) { + foreach ($value as $nestedKey => $nestedValue) { + if ($hasToArray($nestedValue)) { + $value[$nestedKey] = $nestedValue->__toArray(); + } + } + $data[$key] = $value; + } + } + return $data; + } + + /** + * Convert Category model into flat array. + * + * @return array + */ + public function toFlatArray() + { + $dataArray = $this->__toArray(); + //process custom attributes if present + if (array_key_exists('custom_attributes', $dataArray) && !empty($dataArray['custom_attributes'])) { + /** @var \Magento\Framework\Api\AttributeInterface[] $customAttributes */ + $customAttributes = $dataArray['custom_attributes']; + unset ($dataArray['custom_attributes']); + foreach ($customAttributes as $attributeValue) { + $dataArray[$attributeValue[\Magento\Framework\Api\AttributeInterface::ATTRIBUTE_CODE]] + = $attributeValue[\Magento\Framework\Api\AttributeInterface::VALUE]; + } + } + return ConvertArray::toFlatArray($dataArray); + } } diff --git a/app/code/Magento/Catalog/Model/Category/Attribute.php b/app/code/Magento/Catalog/Model/Category/Attribute.php new file mode 100644 index 0000000000000..9311884aa500f --- /dev/null +++ b/app/code/Magento/Catalog/Model/Category/Attribute.php @@ -0,0 +1,166 @@ +getData('apply_to')) { + if (is_array($this->getData('apply_to'))) { + return $this->getData('apply_to'); + } + return explode(',', $this->getData('apply_to')); + } else { + return array(); + } + } + + /** + * {@inheritdoc} + */ + public function getIsHtmlAllowedOnFront() + { + return $this->getData(self::IS_HTML_ALLOWED_ON_FRONT); + } + + /** + * {@inheritdoc} + */ + public function getUsedForSortBy() + { + return $this->getData(self::USED_FOR_SORT_BY); + } + + /** + * {@inheritdoc} + */ + public function getIsWysiwygEnabled() + { + return $this->getData(self::IS_WYSIWYG_ENABLED); + } + + /** + * {@inheritdoc} + */ + public function getIsFilterable() + { + return $this->getData(self::IS_FILTERABLE); + } + + /** + * {@inheritdoc} + */ + public function getIsFilterableInSearch() + { + return $this->getData(self::IS_FILTERABLE_IN_SEARCH); + } + + /** + * {@inheritdoc} + */ + public function getPosition() + { + return $this->getData(self::POSITION); + } + + /** + * {@inheritdoc} + */ + public function getIsSearchable() + { + return $this->getData(self::IS_SEARCHABLE); + } + + /** + * {@inheritdoc} + */ + public function getIsConfigurable() + { + return $this->getData(self::IS_CONFIGURABLE); + } + + /** + * {@inheritdoc} + */ + public function getIsVisibleInAdvancedSearch() + { + return $this->getData(self::IS_VISIBLE_IN_ADVANCED_SEARCH); + } + + /** + * {@inheritdoc} + */ + public function getIsComparable() + { + return $this->getData(self::IS_COMPARABLE); + } + + /** + * {@inheritdoc} + */ + public function getScope() + { + return $this->isScopeGlobal() ? 'global' : ($this->isScopeWebsite() ? 'website' : 'store'); + } + + /** + * {@inheritdoc} + */ + public function getIsVisibleOnFront() + { + return $this->getData(self::IS_VISIBLE_ON_FRONT); + } + + /** + * {@inheritdoc} + */ + public function getIsUsedForPromoRules() + { + return $this->getData(self::IS_USED_FOR_PROMO_RULES); + } + + /** + * {@inheritdoc} + */ + public function getUsedInProductListing() + { + return $this->getData(self::USED_IN_PRODUCT_LISTING); + } + + /** + * {@inheritdoc} + */ + public function getIsVisible() + { + return $this->getData(self::IS_VISIBLE); + } +} diff --git a/app/code/Magento/Catalog/Model/Category/Attribute/OptionManagement.php b/app/code/Magento/Catalog/Model/Category/Attribute/OptionManagement.php new file mode 100644 index 0000000000000..33c9ec7023856 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Category/Attribute/OptionManagement.php @@ -0,0 +1,57 @@ +eavOptionManagement = $eavOptionManagement; + } + + /** + * {@inheritdoc} + * @codeCoverageIgnore + */ + public function getItems($attributeCode) + { + return $this->eavOptionManagement->getItems( + \Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE, + $attributeCode + ); + } +} diff --git a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php new file mode 100644 index 0000000000000..1e87efc19a3a3 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php @@ -0,0 +1,107 @@ +metadataConfig = $metadataConfig; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->filterBuilder = $filterBuilder; + $this->eavAttributeRepository = $eavAttributeRepository; + } + + /** + * {@inheritdoc} + */ + public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) + { + return $this->eavAttributeRepository->getList( + \Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE, + $searchCriteria + ); + } + + /** + * {@inheritdoc} + */ + public function get($attributeCode) + { + return $this->eavAttributeRepository->get( + \Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE, + $attributeCode + ); + } + + /** + * {@inheritdoc} + */ + public function getCustomAttributesMetadata($dataObjectClassName = null) + { + $searchCriteria = $this->searchCriteriaBuilder->addFilter( + [ + $this->filterBuilder + ->setField('attribute_set_id') + ->setValue(\Magento\Catalog\Api\Data\CategoryAttributeInterface::DEFAULT_ATTRIBUTE_SET_ID) + ->create() + ] + ); + + $customAttributes = []; + $entityAttributes = $this->getList($searchCriteria->create())->getItems(); + + foreach ($entityAttributes as $attributeMetadata) { + $customAttributes[] = $attributeMetadata; + } + return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName)); + } +} diff --git a/app/code/Magento/Catalog/Model/Category/Tree.php b/app/code/Magento/Catalog/Model/Category/Tree.php new file mode 100644 index 0000000000000..fa6aa5bb98bb0 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Category/Tree.php @@ -0,0 +1,165 @@ +categoryTree = $categoryTree; + $this->storeManager = $storeManager; + $this->categoryCollection = $categoryCollection; + $this->treeBuilder = $treeBuilder; + } + + /** + * @param \Magento\Catalog\Model\Category|null $category + * @return Node|null + */ + public function getRootNode($category = null) + { + if (!is_null($category) && $category->getId()) { + return $this->getNode($category); + } + + $store = $this->storeManager->getStore(); + $rootId = $store->getRootCategoryId(); + + $tree = $this->categoryTree->load(null); + $this->prepareCollection(); + $tree->addCollectionData($this->categoryCollection); + $root = $tree->getNodeById($rootId); + return $root; + } + + /** + * @param \Magento\Catalog\Model\Category $category + * @return Node + */ + protected function getNode(\Magento\Catalog\Model\Category $category) + { + $nodeId = $category->getId(); + $node = $this->categoryTree->loadNode($nodeId); + $node->loadChildren(); + $this->prepareCollection(); + $this->categoryTree->addCollectionData($this->categoryCollection); + return $node; + } + + /** + * @return void + */ + protected function prepareCollection() + { + $storeId = $this->storeManager->getStore()->getId(); + $this->categoryCollection->addAttributeToSelect( + 'name' + )->addAttributeToSelect( + 'is_active' + )->setProductStoreId( + $storeId + )->setLoadProductCount( + true + )->setStoreId( + $storeId + ); + } + + /** + * @param \Magento\Framework\Data\Tree\Node $node + * @param int $depth + * @param int $currentLevel + * @return \Magento\Catalog\Api\Data\CategoryTreeInterface[] + */ + public function getTree($node, $depth = null, $currentLevel = 0) + { + /** @var \Magento\Catalog\Api\Data\CategoryTreeInterface[] $children */ + $children = $this->getChildren($node, $depth, $currentLevel); + $this->treeBuilder->setId($node->getId()) + ->setParentId($node->getParentId()) + ->setName($node->getName()) + ->setPosition($node->getPosition()) + ->setLevel($node->getLevel()) + ->setIsActive($node->getIsActive()) + ->setProductCount($node->getProductCount()) + ->setChildrenData($children); + return $this->treeBuilder->create(); + } + + /** + * @param \Magento\Framework\Data\Tree\Node $node + * @param int $depth + * @param int $currentLevel + * @return \Magento\Catalog\Api\Data\CategoryTreeInterface[]|[] + */ + protected function getChildren($node, $depth, $currentLevel) + { + if ($node->hasChildren()) { + $children = array(); + foreach ($node->getChildren() as $child) { + if (!is_null($depth) && $depth <= $currentLevel) { + break; + } + $children[] = $this->getTree($child, $depth, $currentLevel + 1); + } + return $children; + } + return []; + } +} diff --git a/app/code/Magento/Catalog/Model/CategoryLinkManagement.php b/app/code/Magento/Catalog/Model/CategoryLinkManagement.php new file mode 100644 index 0000000000000..a287a49044cb3 --- /dev/null +++ b/app/code/Magento/Catalog/Model/CategoryLinkManagement.php @@ -0,0 +1,77 @@ +categoryRepository = $categoryRepository; + $this->productLinkBuilder = $productLinkInterfaceBuilder; + } + + /** + * {@inheritdoc} + */ + public function getAssignedProducts($categoryId) + { + $category = $this->categoryRepository->get($categoryId); + $productsPosition = $category->getProductsPosition(); + + /** @var \Magento\Framework\Data\Collection\Db $products */ + $products = $category->getProductCollection(); + + /** @var \Magento\Catalog\Api\Data\CategoryProductLinkInterface[] $links */ + $links = []; + + /** @var \Magento\Catalog\Model\Product $product */ + foreach ($products->getItems() as $productId => $product) { + $links[] = $this->productLinkBuilder->populateWithArray( + [ + 'sku' => $product->getSku(), + 'position' => $productsPosition[$productId], + 'category_id' => $category->getId() + ] + )->create(); + } + return $links; + } +} diff --git a/app/code/Magento/Catalog/Model/CategoryLinkRepository.php b/app/code/Magento/Catalog/Model/CategoryLinkRepository.php new file mode 100644 index 0000000000000..b18e86cacc129 --- /dev/null +++ b/app/code/Magento/Catalog/Model/CategoryLinkRepository.php @@ -0,0 +1,118 @@ +categoryRepository = $categoryRepository; + $this->productRepository = $productRepository; + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Catalog\Api\Data\CategoryProductLinkInterface $productLink) + { + $category = $this->categoryRepository->get($productLink->getCategoryId()); + $product = $this->productRepository->get($productLink->getSku()); + $productPositions = $category->getProductsPosition(); + $productPositions[$product->getId()] = $productLink->getPosition(); + $category->setPostedProducts($productPositions); + try { + $category->save(); + } catch (\Exception $e) { + throw new CouldNotSaveException( + 'Could not save product "%product_id" with position %position to category %category_id', + [ + 'product_id' => $product->getId(), + 'position' => $productLink->getPosition(), + 'category_id' => $category->getId() + ], + $e + ); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Catalog\Api\Data\CategoryProductLinkInterface $productLink) + { + return $this->deleteByIds($productLink->getCategoryId(), $productLink->getSku()); + } + + /** + * {@inheritdoc} + */ + public function deleteByIds($categoryId, $productSku) + { + $category = $this->categoryRepository->get($categoryId); + $product = $this->productRepository->get($productSku); + $productPositions = $category->getProductsPosition(); + + $productID = $product->getId(); + if (!isset($productPositions[$productID])) { + throw new InputException('Category does not contain specified product'); + } + unset($productPositions[$productID]); + + $category->setPostedProducts($productPositions); + try { + $category->save(); + } catch (\Exception $e) { + throw new CouldNotSaveException( + 'Could not save product "%product_id" with position %position to category %category_id', + [ + 'product_id' => $product->getId(), + 'category_id' => $category->getId() + ], + $e + ); + } + return true; + } +} diff --git a/app/code/Magento/Catalog/Model/CategoryManagement.php b/app/code/Magento/Catalog/Model/CategoryManagement.php new file mode 100644 index 0000000000000..d69ffaaf09681 --- /dev/null +++ b/app/code/Magento/Catalog/Model/CategoryManagement.php @@ -0,0 +1,93 @@ +categoryRepository = $categoryRepository; + $this->categoryTree = $categoryTree; + } + + /** + * {@inheritdoc} + */ + public function getTree($rootCategoryId = null, $depth = null) + { + $category = null; + if (!is_null($rootCategoryId)) { + /** @var \Magento\Catalog\Model\Category $category */ + $category = $this->categoryRepository->get($rootCategoryId); + } + $result = $this->categoryTree->getTree($this->categoryTree->getRootNode($category), $depth); + return $result; + } + + /** + * {@inheritdoc} + */ + public function move($categoryId, $parentId, $afterId = null) + { + $model = $this->categoryRepository->get($categoryId); + $parentCategory = $this->categoryRepository->get($parentId); + + if ($parentCategory->hasChildren()) { + $parentChildren = $parentCategory->getChildren(); + $categoryIds = explode(',', $parentChildren); + $lastId = array_pop($categoryIds); + $afterId = (is_null($afterId) || $afterId > $lastId) ? $lastId : $afterId; + } + + if (strpos($parentCategory->getPath(), $model->getPath()) === 0) { + throw new \Magento\Framework\Model\Exception( + "Operation do not allow to move a parent category to any of children category" + ); + } + try { + $model->move($parentId, $afterId); + } catch (\Exception $e) { + throw new \Magento\Framework\Model\Exception('Could not move category'); + } + return true; + } +} diff --git a/app/code/Magento/Catalog/Model/CategoryProductLink.php b/app/code/Magento/Catalog/Model/CategoryProductLink.php new file mode 100644 index 0000000000000..f743b15eadcfd --- /dev/null +++ b/app/code/Magento/Catalog/Model/CategoryProductLink.php @@ -0,0 +1,53 @@ +_get('sku'); + } + + /** + * {@inheritdoc} + */ + public function getPosition() + { + return $this->_get('position'); + } + + /** + * {@inheritdoc} + */ + public function getCategoryId() + { + return $this->_get('category_id'); + } +} diff --git a/app/code/Magento/Catalog/Model/CategoryRepository.php b/app/code/Magento/Catalog/Model/CategoryRepository.php new file mode 100644 index 0000000000000..cee13223fa879 --- /dev/null +++ b/app/code/Magento/Catalog/Model/CategoryRepository.php @@ -0,0 +1,185 @@ +categoryFactory = $categoryFactory; + $this->categoryResource = $categoryResource; + $this->storeManager = $storeManager; + $this->categoryBuilder = $dataBuilder; + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Catalog\Api\Data\CategoryInterface $category) + { + $existingData = $category->toFlatArray(); + if ($category->getId()) { + $existingCategory = $this->get($category->getId()); + if (isset($existingData['image']) && is_array($existingData['image'])) { + $existingData['image_additional_data'] = $existingData['image']; + unset($existingData['image']); + } + $existingData['id'] = $existingCategory->getId(); + $existingData['parent_id'] = $existingCategory->getParentId(); + $existingData['path'] = $existingCategory->getPath(); + $existingData['is_active'] = $existingCategory->getIsActive(); + $existingData['include_in_menu'] = + isset($existingData['include_in_menu']) ? (bool)$existingData['include_in_menu'] : false; + $category->setData($existingData); + } else { + $parentId = $category->getParentId() ?: $this->storeManager->getStore()->getRootCategoryId(); + $parentCategory = $this->get($parentId); + /** @var $category Category */ + $category->setData($existingData); + $category->setPath($parentCategory->getPath()); + } + try { + $this->validateCategory($category); + $this->categoryResource->save($category); + } catch (\Exception $e) { + throw new CouldNotSaveException('Could not save category: %message', ['message' => $e->getMessage()], $e); + } + return $category; + } + + /** + * {@inheritdoc} + */ + public function get($categoryId) + { + /** @var Category $category */ + $category = $this->categoryFactory->create(); + $category->load($categoryId); + if (!$category->getId()) { + throw NoSuchEntityException::singleField('id', $categoryId); + } + return $category; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Catalog\Api\Data\CategoryInterface $category) + { + try { + $this->categoryResource->delete($category); + } catch (\Exception $e) { + throw new StateException( + 'Cannot delete category with id %category_id', + [ + 'category_id' => $category->getId() + ], + $e + ); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function deleteByIdentifier($categoryId) + { + $category = $this->get($categoryId); + return $this->delete($category); + } + + /** + * Validate category process + * + * @param Category $category + * @return void + * @throws \Magento\Framework\Model\Exception + */ + protected function validateCategory(Category $category) + { + $useConfigFields = []; + foreach ($this->useConfigFields as $field) { + if (!$category->getData($field)) { + $useConfigFields[] = $field; + } + } + $category->setData('use_post_data_config', $useConfigFields); + $validate = $category->validate(); + if ($validate !== true) { + foreach ($validate as $code => $error) { + if ($error === true) { + $attribute = $this->categoryResource->getAttribute($code)->getFrontend()->getLabel(); + throw new \Magento\Framework\Model\Exception(__('Attribute "%1" is required.', $attribute)); + } else { + throw new \Magento\Framework\Model\Exception($error); + } + } + } + $category->unsetData('use_post_data_config'); + } +} diff --git a/app/code/Magento/Catalog/Model/Config/Backend/Category.php b/app/code/Magento/Catalog/Model/Config/Backend/Category.php index 39f201e669de0..deefdfe1ef0fe 100644 --- a/app/code/Magento/Catalog/Model/Config/Backend/Category.php +++ b/app/code/Magento/Catalog/Model/Config/Backend/Category.php @@ -64,7 +64,7 @@ public function __construct( /** * {@inheritdoc} */ - protected function _afterSave() + public function afterSave() { if ($this->getScope() == 'stores') { $rootId = $this->getValue(); diff --git a/app/code/Magento/Catalog/Model/Config/Source/Price/Step.php b/app/code/Magento/Catalog/Model/Config/Source/Price/Step.php index 7aa4dde94c53a..9e3c30891b743 100644 --- a/app/code/Magento/Catalog/Model/Config/Source/Price/Step.php +++ b/app/code/Magento/Catalog/Model/Config/Source/Price/Step.php @@ -23,7 +23,10 @@ */ namespace Magento\Catalog\Model\Config\Source\Price; -class Step implements \Magento\Framework\Option\ArrayInterface +use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory; +use Magento\Framework\Option\ArrayInterface; + +class Step implements ArrayInterface { /** * {@inheritdoc} @@ -34,15 +37,15 @@ public function toOptionArray() { return array( array( - 'value' => \Magento\Catalog\Model\Layer\Filter\Price::RANGE_CALCULATION_AUTO, + 'value' => AlgorithmFactory::RANGE_CALCULATION_AUTO, 'label' => __('Automatic (equalize price ranges)') ), array( - 'value' => \Magento\Catalog\Model\Layer\Filter\Price::RANGE_CALCULATION_IMPROVED, + 'value' => AlgorithmFactory::RANGE_CALCULATION_IMPROVED, 'label' => __('Automatic (equalize product counts)') ), array( - 'value' => \Magento\Catalog\Model\Layer\Filter\Price::RANGE_CALCULATION_MANUAL, + 'value' => AlgorithmFactory::RANGE_CALCULATION_MANUAL, 'label' => __('Manual') ) ); diff --git a/app/code/Magento/Catalog/Model/Entity/Attribute.php b/app/code/Magento/Catalog/Model/Entity/Attribute.php index 1a88eda64605f..74492bbb0432c 100644 --- a/app/code/Magento/Catalog/Model/Entity/Attribute.php +++ b/app/code/Magento/Catalog/Model/Entity/Attribute.php @@ -50,15 +50,11 @@ * @method \Magento\Catalog\Model\Entity\Attribute setIsUsedForPriceRules(int $value) * @method int getIsFilterableInSearch() * @method \Magento\Catalog\Model\Entity\Attribute setIsFilterableInSearch(int $value) - * @method int getUsedInProductListing() * @method \Magento\Catalog\Model\Entity\Attribute setUsedInProductListing(int $value) - * @method int getUsedForSortBy() * @method \Magento\Catalog\Model\Entity\Attribute setUsedForSortBy(int $value) - * @method string getApplyTo() * @method \Magento\Catalog\Model\Entity\Attribute setApplyTo(string $value) * @method int getIsVisibleInAdvancedSearch() * @method \Magento\Catalog\Model\Entity\Attribute setIsVisibleInAdvancedSearch(int $value) - * @method int getPosition() * @method \Magento\Catalog\Model\Entity\Attribute setPosition(int $value) * @method int getIsWysiwygEnabled() * @method \Magento\Catalog\Model\Entity\Attribute setIsWysiwygEnabled(int $value) @@ -91,12 +87,14 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Api\MetadataServiceInterface $metadataService * @param \Magento\Core\Helper\Data $coreData * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Eav\Model\Resource\Helper $resourceHelper * @param \Magento\Framework\Validator\UniversalFactory $universalFactory + * @param \Magento\Eav\Api\Data\AttributeOptionDataBuilder $optionDataBuilder * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList * @param \Magento\Framework\Locale\ResolverInterface $localeResolver @@ -108,12 +106,14 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Framework\Api\MetadataServiceInterface $metadataService, \Magento\Core\Helper\Data $coreData, \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Eav\Model\Resource\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, + \Magento\Eav\Api\Data\AttributeOptionDataBuilder $optionDataBuilder, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList, \Magento\Framework\Locale\ResolverInterface $localeResolver, @@ -126,12 +126,14 @@ public function __construct( parent::__construct( $context, $registry, + $metadataService, $coreData, $eavConfig, $eavTypeFactory, $storeManager, $resourceHelper, $universalFactory, + $optionDataBuilder, $localeDate, $reservedAttributeList, $localeResolver, @@ -147,7 +149,7 @@ public function __construct( * @return \Magento\Framework\Model\AbstractModel * @throws \Magento\Eav\Exception */ - protected function _beforeSave() + public function beforeSave() { try { $this->attrLockValidator->validate($this); @@ -156,7 +158,7 @@ protected function _beforeSave() } $this->setData('modulePrefix', self::MODULE_NAME); - return parent::_beforeSave(); + return parent::beforeSave(); } /** @@ -164,12 +166,12 @@ protected function _beforeSave() * * @return \Magento\Framework\Model\AbstractModel */ - protected function _afterSave() + public function afterSave() { /** * Fix saving attribute in admin */ $this->_eavConfig->clear(); - return parent::_afterSave(); + return parent::afterSave(); } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Flat/System/Config/Mode.php b/app/code/Magento/Catalog/Model/Indexer/Category/Flat/System/Config/Mode.php index 42e5c3be7395e..17feb5a70d48f 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Flat/System/Config/Mode.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Flat/System/Config/Mode.php @@ -64,7 +64,7 @@ public function __construct( * * @return $this */ - protected function _afterSave() + public function afterSave() { $this->_getResource()->addCommitCallback(array($this, 'processValue')); return $this; diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/System/Config/Mode.php b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/System/Config/Mode.php index 0a58e97f2bce6..d6038f80e39bc 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/System/Config/Mode.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/System/Config/Mode.php @@ -68,7 +68,7 @@ public function __construct( * * @return $this */ - protected function _afterSave() + public function afterSave() { $this->_getResource()->addCommitCallback(array($this, 'processValue')); return $this; diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/CustomerGroup.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/CustomerGroup.php index 5e11522d526b6..16d203d4bc52b 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/CustomerGroup.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/CustomerGroup.php @@ -23,33 +23,33 @@ */ namespace Magento\Catalog\Model\Indexer\Product\Price\Plugin; -use Magento\Customer\Service\V1\CustomerGroupServiceInterface; +use Magento\Customer\Api\GroupRepositoryInterface; class CustomerGroup extends AbstractPlugin { /** - * Invalidate the indexer after the group is created. + * Invalidate the indexer after the group is saved. * - * @param CustomerGroupServiceInterface $subject - * @param string $result + * @param GroupRepositoryInterface $subject + * @param string $result * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterCreateGroup(CustomerGroupServiceInterface $subject, $result) + public function afterSave(GroupRepositoryInterface $subject, $result) { $this->invalidateIndexer(); return $result; } /** - * Invalidate the indexer after the group is updated. + * Invalidate the indexer after the group is deleted. * - * @param CustomerGroupServiceInterface $subject - * @param string $result + * @param GroupRepositoryInterface $subject + * @param string $result * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterUpdateGroup(CustomerGroupServiceInterface $subject, $result) + public function afterDelete(GroupRepositoryInterface $subject, $result) { $this->invalidateIndexer(); return $result; @@ -58,12 +58,12 @@ public function afterUpdateGroup(CustomerGroupServiceInterface $subject, $result /** * Invalidate the indexer after the group is deleted. * - * @param CustomerGroupServiceInterface $subject - * @param string $result + * @param GroupRepositoryInterface $subject + * @param string $result * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterDeleteGroup(CustomerGroupServiceInterface $subject, $result) + public function afterDeleteById(GroupRepositoryInterface $subject, $result) { $this->invalidateIndexer(); return $result; diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/System/Config/PriceScope.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/System/Config/PriceScope.php index 5c0235eb97a57..5bba2f9c0b9fd 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/System/Config/PriceScope.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/System/Config/PriceScope.php @@ -58,7 +58,7 @@ public function __construct( * * @return \Magento\Catalog\Model\Indexer\Product\Price\System\Config\PriceScope */ - protected function _afterSave() + public function afterSave() { $this->_getResource()->addCommitCallback(array($this, 'processValue')); return $this; diff --git a/app/code/Magento/Catalog/Model/Layer/Category.php b/app/code/Magento/Catalog/Model/Layer/Category.php index b77a6357be266..fcdf88142b127 100644 --- a/app/code/Magento/Catalog/Model/Layer/Category.php +++ b/app/code/Magento/Catalog/Model/Layer/Category.php @@ -25,14 +25,13 @@ namespace Magento\Catalog\Model\Layer; use Magento\Catalog\Model\CategoryFactory; -use Magento\Catalog\Model\Layer; use Magento\Catalog\Model\Resource; -use Magento\Framework\Object; +use Magento\Catalog\Model\Layer\ContextInterface; class Category extends \Magento\Catalog\Model\Layer { /** - * @param Category\Context $context + * @param ContextInterface $context * @param StateFactory $layerStateFactory * @param CategoryFactory $categoryFactory * @param Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory @@ -42,7 +41,7 @@ class Category extends \Magento\Catalog\Model\Layer * @param array $data */ public function __construct( - Category\Context $context, + ContextInterface $context, StateFactory $layerStateFactory, CategoryFactory $categoryFactory, Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory, diff --git a/app/code/Magento/Catalog/Model/Layer/Category/Context.php b/app/code/Magento/Catalog/Model/Layer/Category/Context.php deleted file mode 100644 index 47b742c0537df..0000000000000 --- a/app/code/Magento/Catalog/Model/Layer/Category/Context.php +++ /dev/null @@ -1,41 +0,0 @@ -collectionFactory = $collectionFactory; $this->storeManager = $storeManager; - $this->layer = $layer; + $this->layer = $layerResolver->get(); } /** diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/AbstractFilter.php b/app/code/Magento/Catalog/Model/Layer/Filter/AbstractFilter.php index c760506c2c0ee..d6797f327aa1f 100644 --- a/app/code/Magento/Catalog/Model/Layer/Filter/AbstractFilter.php +++ b/app/code/Magento/Catalog/Model/Layer/Filter/AbstractFilter.php @@ -25,11 +25,11 @@ /** * Layer category filter abstract model - * - * @author Magento Core Team */ -abstract class AbstractFilter extends \Magento\Framework\Object +abstract class AbstractFilter extends \Magento\Framework\Object implements FilterInterface { + const ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS = 1; + /** * Request variable name with filter value * @@ -65,23 +65,34 @@ abstract class AbstractFilter extends \Magento\Framework\Object */ protected $_filterItemFactory; + /** + * Item Data Builder + * + * @var \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder + */ + protected $itemDataBuilder; + /** * Constructor * * @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer + * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param array $data + * @throws \Magento\Framework\Model\Exception */ public function __construct( \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, + \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, array $data = array() ) { $this->_filterItemFactory = $filterItemFactory; $this->_storeManager = $storeManager; $this->_catalogLayer = $layer; + $this->itemDataBuilder = $itemDataBuilder; parent::__construct($data); if ($this->hasAttributeModel()) { $this->_requestVar = $this->getAttributeModel()->getAttributeCode(); @@ -133,10 +144,10 @@ public function getCleanValue() /** * Apply filter to collection * - * @param \Zend_Controller_Request_Abstract $request + * @param \Magento\Framework\App\RequestInterface $request * @return $this */ - public function apply(\Zend_Controller_Request_Abstract $request) + public function apply(\Magento\Framework\App\RequestInterface $request) { return $this; } @@ -164,6 +175,18 @@ public function getItems() return $this->_items; } + /** + * Set all filter items + * + * @param array $items + * @return $this + */ + public function setItems(array $items) + { + $this->_items = $items; + return $this; + } + /** * Get data array for building filter items * @@ -224,15 +247,11 @@ public function getLayer() */ protected function _createItem($label, $value, $count = 0) { - return $this->_filterItemFactory->create()->setFilter( - $this - )->setLabel( - $label - )->setValue( - $value - )->setCount( - $count - ); + return $this->_filterItemFactory->create() + ->setFilter($this) + ->setLabel($label) + ->setValue($value) + ->setCount($count); } /** @@ -287,6 +306,7 @@ public function getAttributeModel() * Get filter text label * * @return string + * @throws \Magento\Framework\Model\Exception */ public function getName() { @@ -352,4 +372,27 @@ public function getClearLinkText() { return false; } + + /** + * Get option text from frontend model by option id + * + * @param int $optionId + * @throws \Magento\Framework\Model\Exception + * @return string|bool + */ + protected function getOptionText($optionId) + { + return $this->getAttributeModel()->getFrontend()->getOption($optionId); + } + + /** + * Check whether specified attribute can be used in LN + * + * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute + * @return int + */ + protected function getAttributeIsFilterable($attribute) + { + return $attribute->getIsFilterable(); + } } diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Attribute.php b/app/code/Magento/Catalog/Model/Layer/Filter/Attribute.php index d365147d7a47c..8d7e467103268 100644 --- a/app/code/Magento/Catalog/Model/Layer/Filter/Attribute.php +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Attribute.php @@ -30,8 +30,6 @@ */ class Attribute extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter { - const OPTIONS_ONLY_WITH_RESULTS = 1; - /** * Resource instance * @@ -55,6 +53,7 @@ class Attribute extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter * @param ItemFactory $filterItemFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer + * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Catalog\Model\Resource\Layer\Filter\AttributeFactory $filterAttributeFactory * @param \Magento\Framework\Stdlib\String $string * @param \Magento\Framework\Filter\StripTags $tagFilter @@ -64,6 +63,7 @@ public function __construct( \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, + \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Catalog\Model\Resource\Layer\Filter\AttributeFactory $filterAttributeFactory, \Magento\Framework\Stdlib\String $string, \Magento\Framework\Filter\StripTags $tagFilter, @@ -73,7 +73,7 @@ public function __construct( $this->string = $string; $this->_requestVar = 'attribute'; $this->tagFilter = $tagFilter; - parent::__construct($filterItemFactory, $storeManager, $layer, $data); + parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); } /** @@ -86,52 +86,31 @@ protected function _getResource() return $this->_resource; } - /** - * Get option text from frontend model by option id - * - * @param int $optionId - * @return string|bool - */ - protected function _getOptionText($optionId) - { - return $this->getAttributeModel()->getFrontend()->getOption($optionId); - } - /** * Apply attribute option filter to product collection * - * @param \Zend_Controller_Request_Abstract $request + * @param \Magento\Framework\App\RequestInterface $request * @return $this */ - public function apply(\Zend_Controller_Request_Abstract $request) + public function apply(\Magento\Framework\App\RequestInterface $request) { $filter = $request->getParam($this->_requestVar); if (is_array($filter)) { return $this; } - $text = $this->_getOptionText($filter); + $text = $this->getOptionText($filter); if ($filter && strlen($text)) { $this->_getResource()->applyFilterToCollection($this, $filter); $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter)); - $this->_items = array(); + $this->_items = []; } return $this; } - /** - * Check whether specified attribute can be used in LN - * - * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute - * @return bool - */ - protected function _getIsFilterableAttribute($attribute) - { - return $attribute->getIsFilterable(); - } - /** * Get data array for building attribute filter items * + * @throws \Magento\Framework\Model\Exception * @return array */ protected function _getItemsData() @@ -141,31 +120,30 @@ protected function _getItemsData() $options = $attribute->getFrontend()->getSelectOptions(); $optionsCount = $this->_getResource()->getCount($this); - $data = array(); foreach ($options as $option) { if (is_array($option['value'])) { continue; } if ($this->string->strlen($option['value'])) { // Check filter type - if ($this->_getIsFilterableAttribute($attribute) == self::OPTIONS_ONLY_WITH_RESULTS) { + if ($this->getAttributeIsFilterable($attribute) == self::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS) { if (!empty($optionsCount[$option['value']])) { - $data[] = array( - 'label' => $this->tagFilter->filter($option['label']), - 'value' => $option['value'], - 'count' => $optionsCount[$option['value']] + $this->itemDataBuilder->addItemData( + $this->tagFilter->filter($option['label']), + $option['value'], + $optionsCount[$option['value']] ); } } else { - $data[] = array( - 'label' => $this->tagFilter->filter($option['label']), - 'value' => $option['value'], - 'count' => isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0 + $this->itemDataBuilder->addItemData( + $this->tagFilter->filter($option['label']), + $option['value'], + isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0 ); } } } - return $data; + return $this->itemDataBuilder->build(); } } diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Category.php b/app/code/Magento/Catalog/Model/Layer/Filter/Category.php index be76e54f90fa1..fa54cadaddcd3 100644 --- a/app/code/Magento/Catalog/Model/Layer/Filter/Category.php +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Category.php @@ -29,8 +29,12 @@ */ namespace Magento\Catalog\Model\Layer\Filter; +use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; +use Magento\Catalog\Model\Layer\Filter\DataProvider\Category as CategoryDataProvider; + class Category extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter { + /** * Active Category Id * @@ -66,31 +70,35 @@ class Category extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter */ protected $_categoryFactory; + /** + * @var CategoryDataProvider + */ + private $dataProvider; + /** * Construct * * @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer - * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory + * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Framework\Escaper $escaper - * @param \Magento\Framework\Registry $coreRegistry + * @param CategoryFactory $categoryDataProviderFactory * @param array $data */ public function __construct( \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, - \Magento\Catalog\Model\CategoryFactory $categoryFactory, + \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Framework\Escaper $escaper, - \Magento\Framework\Registry $coreRegistry, - array $data = array() + CategoryFactory $categoryDataProviderFactory, + array $data = [] ) { - $this->_categoryFactory = $categoryFactory; $this->_escaper = $escaper; - $this->_coreRegistry = $coreRegistry; - parent::__construct($filterItemFactory, $storeManager, $layer, $data); + parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); $this->_requestVar = 'cat'; + $this->dataProvider = $categoryDataProviderFactory->create(['layer' => $this->getLayer()]); } /** @@ -100,69 +108,33 @@ public function __construct( */ public function getResetValue() { - if ($this->_appliedCategory) { - /** - * Revert path ids - */ - $pathIds = array_reverse($this->_appliedCategory->getPathIds()); - $curCategoryId = $this->getLayer()->getCurrentCategory()->getId(); - if (isset($pathIds[1]) && $pathIds[1] != $curCategoryId) { - return $pathIds[1]; - } - } - return null; + return $this->dataProvider->getResetValue(); } /** * Apply category filter to layer * - * @param \Zend_Controller_Request_Abstract $request + * @param \Magento\Framework\App\RequestInterface $request * @return $this */ - public function apply(\Zend_Controller_Request_Abstract $request) + public function apply(\Magento\Framework\App\RequestInterface $request) { - $filter = (int)$request->getParam($this->getRequestVar()); - if (!$filter) { + $categoryId = (int)$request->getParam($this->getRequestVar()); + if (!$categoryId) { return $this; } - $this->_categoryId = $filter; - $this->_coreRegistry->register('current_category_filter', $this->getCategory(), true); - $this->_appliedCategory = $this->_categoryFactory->create()->setStoreId( - $this->_storeManager->getStore()->getId() - )->load( - $filter - ); + $this->dataProvider->setCategoryId($categoryId); - if ($this->_isValidCategory($this->_appliedCategory)) { - $this->getLayer()->getProductCollection()->addCategoryFilter($this->_appliedCategory); - - $this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter)); + if ($this->dataProvider->isValid()) { + $category = $this->dataProvider->getCategory(); + $this->getLayer()->getProductCollection()->addCategoryFilter($category); + $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $categoryId)); } return $this; } - /** - * Validate category for be using as filter - * - * @param \Magento\Catalog\Model\Category $category - * @return mixed - */ - protected function _isValidCategory($category) - { - if ($category->getId()) { - while ($category->getLevel() != 0) { - if (!$category->getIsActive()) { - return false; - } - $category = $category->getParentCategory(); - } - return true; - } - return false; - } - /** * Get filter name * @@ -173,23 +145,6 @@ public function getName() return __('Category'); } - /** - * Get selected category object - * - * @return \Magento\Catalog\Model\Category - */ - public function getCategory() - { - if (!is_null($this->_categoryId)) { - /** @var \Magento\Catalog\Model\Category $category */ - $category = $this->_categoryFactory->create()->load($this->_categoryId); - if ($category->getId()) { - return $category; - } - } - return $this->getLayer()->getCurrentCategory(); - } - /** * Get data array for building category filter items * @@ -197,23 +152,22 @@ public function getCategory() */ protected function _getItemsData() { - $category = $this->getCategory(); + $category = $this->dataProvider->getCategory(); $categories = $category->getChildrenCategories(); $this->getLayer()->getProductCollection()->addCountToCategories($categories); - $data = array(); if ($category->getIsActive()) { foreach ($categories as $category) { if ($category->getIsActive() && $category->getProductCount()) { - $data[] = array( - 'label' => $this->_escaper->escapeHtml($category->getName()), - 'value' => $category->getId(), - 'count' => $category->getProductCount() + $this->itemDataBuilder->addItemData( + $this->_escaper->escapeHtml($category->getName()), + $category->getId(), + $category->getProductCount() ); } } } - return $data; + return $this->itemDataBuilder->build(); } } diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Category.php b/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Category.php new file mode 100644 index 0000000000000..4264d4724ba62 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Category.php @@ -0,0 +1,185 @@ +coreRegistry = $coreRegistry; + $this->layer = $layer; + $this->categoryFactory = $categoryFactory; + } + + /** + * Validate category for using as filter + * + * @return mixed + */ + public function isValid() + { + $category = $this->getCategory(); + if ($category->getId()) { + while ($category->getLevel() != 0) { + if (!$category->getIsActive()) { + return false; + } + $category = $category->getParentCategory(); + } + + return true; + } + + return false; + } + + /** + * @param int $categoryId + * @return $this + */ + public function setCategoryId($categoryId) + { + $this->isApplied = true; + $this->category = null; + $this->categoryId = $categoryId; + + return $this; + } + + /** + * @return boolean + */ + private function isApplied() + { + return $this->isApplied; + } + + /** + * Get selected category object + * + * @return CategoryModel + */ + public function getCategory() + { + if (is_null($this->category)) { + /** @var CategoryModel|null $category */ + $category = null; + if (!is_null($this->categoryId)) { + $category = $this->categoryFactory->create() + ->setStoreId( + $this->getLayer() + ->getCurrentStore() + ->getId() + ) + ->load($this->categoryId); + } + + if (is_null($category) || !$category->getId()) { + $category = $this->getLayer() + ->getCurrentCategory(); + } + + $this->coreRegistry->register('current_category_filter', $category, true); + $this->category = $category; + } + + return $this->category; + } + + /** + * Get filter value for reset current filter state + * + * @return mixed|null + */ + public function getResetValue() + { + if ($this->isApplied()) { + /** + * Revert path ids + */ + $category = $this->getCategory(); + $pathIds = array_reverse($category->getPathIds()); + $curCategoryId = $this->getLayer() + ->getCurrentCategory() + ->getId(); + if (isset($pathIds[1]) && $pathIds[1] != $curCategoryId) { + return $pathIds[1]; + } + } + + return null; + } + + /** + * @return Layer + */ + private function getLayer() + { + return $this->layer; + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Decimal.php b/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Decimal.php new file mode 100644 index 0000000000000..6c4ed1724dcc3 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Decimal.php @@ -0,0 +1,165 @@ +resource = $resource; + } + + /** + * @param FilterInterface $filter + * @return int + */ + public function getRange(FilterInterface $filter) + { + $range = $this->range; + if (!$range) { + $maxValue = $this->getMaxValue($filter); + $index = 1; + do { + $range = pow(10, strlen(floor($maxValue)) - $index); + $items = $this->getRangeItemCounts($range, $filter); + $index++; + } while ($range > self::MIN_RANGE_POWER && count($items) < 2); + $this->range = $range; + } + + return $range; + } + + /** + * @param int $range + * @return void + */ + public function setRange($range) + { + $this->range = $range; + } + + /** + * Retrieve maximum value from layer products set + * + * @param FilterInterface $filter + * @return float + */ + public function getMaxValue(FilterInterface $filter) + { + if (is_null($this->max)) { + $this->loadValues($filter); + } + + return $this->max; + } + + /** + * Retrieve minimal value from layer products set + * + * @param FilterInterface $filter + * @return float + */ + public function getMinValue(FilterInterface $filter) + { + if (is_null($this->min)) { + $this->loadValues($filter); + } + + return $this->min; + } + + /** + * Retrieve information about products count in range + * + * @param int $range + * @param FilterInterface $filter + * @return mixed + */ + public function getRangeItemCounts($range, FilterInterface $filter) + { + $count = array_key_exists($range, $this->rangeItemsCount) ? $this->rangeItemsCount[$range] : null; + if (is_null($count)) { + $count = $this->getResource() + ->getCount($filter, $range); + $this->rangeItemsCount[$range] = $count; + } + + return $count; + } + + /** + * @return \Magento\Catalog\Model\Resource\Layer\Filter\Decimal + */ + public function getResource() + { + return $this->resource; + } + + /** + * @param FilterInterface $filter + * @return mixed + */ + private function loadValues(FilterInterface $filter) + { + list($min, $max) = $this->getResource() + ->getMinMax($filter); + $this->min = $min; + $this->max = $max; + + return $this; + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Price.php b/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Price.php new file mode 100644 index 0000000000000..fe3ddc639c60c --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Price.php @@ -0,0 +1,400 @@ +layer = $layer; + $this->coreRegistry = $coreRegistry; + $this->scopeConfig = $scopeConfig; + $this->resource = $resource; + } + + /** + * @return array + */ + public function getInterval() + { + return $this->interval; + } + + /** + * @param array $interval + * @return void + */ + public function setInterval($interval) + { + $this->interval = $interval; + } + + /** + * @return mixed + */ + public function getRangeCalculationValue() + { + return $this->scopeConfig->getValue( + self::XML_PATH_RANGE_CALCULATION, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * @return mixed + */ + public function getRangeStepValue() + { + return $this->scopeConfig->getValue( + self::XML_PATH_RANGE_STEP, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * @return mixed + */ + public function getOnePriceIntervalValue() + { + return $this->scopeConfig->getValue( + self::XML_PATH_ONE_PRICE_INTERVAL, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * Get interval division limit + * + * @return int + */ + public function getIntervalDivisionLimitValue() + { + return $this->scopeConfig->getValue( + self::XML_PATH_INTERVAL_DIVISION_LIMIT, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * Get maximum number of intervals + * + * @return mixed + */ + public function getRangeMaxIntervalsValue() + { + return $this->scopeConfig->getValue( + self::XML_PATH_RANGE_MAX_INTERVALS, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * @return Layer + */ + public function getLayer() + { + return $this->layer; + } + + /** + * Get price range for building filter steps + * + * @return int + */ + public function getPriceRange() + { + $range = $this->priceRange; + if (!$range) { + $currentCategory = $this->coreRegistry->registry('current_category_filter'); + if ($currentCategory) { + $range = $currentCategory->getFilterPriceRange(); + } else { + $range = $this->getLayer() + ->getCurrentCategory() + ->getFilterPriceRange(); + } + + if (!$range) { + $maxPrice = $this->getMaxPrice(); + $calculation = $this->getRangeCalculationValue(); + if ($calculation == self::RANGE_CALCULATION_AUTO) { + $index = 1; + do { + $range = pow(10, strlen(floor($maxPrice)) - $index); + $items = $this->getRangeItemCounts($range); + $index++; + } while ($range > self::MIN_RANGE_POWER && count($items) < 2); + } else { + $range = (double)$this->getRangeStepValue(); + } + } + + $this->priceRange = $range; + } + + return $range; + } + + /** + * Get information about products count in range + * + * @param int $range + * @return int + */ + public function getRangeItemCounts($range) + { + $items = array_key_exists($range, $this->rangeItemCounts) ? $this->rangeItemCounts[$range] : null; + if (is_null($items)) { + $items = $this->resource->getCount($range); + // checking max number of intervals + $i = 0; + $lastIndex = null; + $maxIntervalsNumber = $this->getRangeMaxIntervalsValue(); + $calculation = $this->getRangeCalculationValue(); + foreach ($items as $k => $v) { + ++$i; + if ($calculation == self::RANGE_CALCULATION_MANUAL && $i > 1 && $i > $maxIntervalsNumber) { + $items[$lastIndex] += $v; + unset($items[$k]); + } else { + $lastIndex = $k; + } + } + $this->rangeItemCounts[$range] = $items; + } + + return $items; + } + + /** + * Get maximum price from layer products set + * + * @return float + */ + public function getMaxPrice() + { + $maxPrice = $this->maxPrice; + if (is_null($maxPrice)) { + $maxPrice = $this->getLayer() + ->getProductCollection() + ->getMaxPrice(); + $maxPrice = floor($maxPrice); + $this->maxPrice = $maxPrice; + } + + return $maxPrice; + } + + /** + * @param string $filterParams + * @return array + */ + public function getPriorFilters($filterParams) + { + $priorFilters = []; + for ($i = 1; $i < count($filterParams); ++$i) { + $priorFilter = $this->validateFilter($filterParams[$i]); + if ($priorFilter) { + $priorFilters[] = $priorFilter; + } else { + //not valid data + $priorFilters = []; + break; + } + } + + return $priorFilters; + } + + /** + * Validate and parse filter request param + * + * @param string $filter + * @return array|bool + */ + public function validateFilter($filter) + { + $filter = explode('-', $filter); + if (count($filter) != 2) { + return false; + } + foreach ($filter as $v) { + if ($v !== '' && $v !== '0' && (double)$v <= 0 || is_infinite((double)$v)) { + return false; + } + } + + return $filter; + } + + /** + * Get filter value for reset current filter state + * + * @return null|string + */ + public function getResetValue() + { + $priorIntervals = $this->getPriorIntervals(); + $value = []; + if ($priorIntervals) { + foreach ($priorIntervals as $priorInterval) { + $value[] = implode('-', $priorInterval); + } + + return implode(',', $value); + } + + return null; + } + + /** + * @return array + */ + public function getPriorIntervals() + { + return $this->priorIntervals; + } + + /** + * @param array $priorInterval + * @return void + */ + public function setPriorIntervals($priorInterval) + { + $this->priorIntervals = $priorInterval; + } + + /** + * @return \Magento\Catalog\Model\Resource\Layer\Filter\Price + */ + public function getResource() + { + return $this->resource; + } + + /** + * @return string + */ + public function getAdditionalRequestData() + { + $result = ''; + $appliedInterval = $this->getInterval(); + if ($appliedInterval) { + $result = ',' . $appliedInterval[0] . '-' . $appliedInterval[1]; + $priorIntervals = $this->getResetValue(); + if ($priorIntervals) { + $result .= ',' . $priorIntervals; + } + } + + return $result; + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Decimal.php b/app/code/Magento/Catalog/Model/Layer/Filter/Decimal.php index 9e2bc26c6c05f..ddc08611a2b37 100644 --- a/app/code/Magento/Catalog/Model/Layer/Filter/Decimal.php +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Decimal.php @@ -22,7 +22,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Catalog Layer Decimal Attribute Filter Model * @@ -32,7 +31,6 @@ class Decimal extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter { - const MIN_RANGE_POWER = 10; /** * Resource instance @@ -46,10 +44,16 @@ class Decimal extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter */ protected $priceCurrency; + /** + * @var DataProvider\Decimal + */ + private $dataProvider; + /** * @param ItemFactory $filterItemFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer + * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Catalog\Model\Resource\Layer\Filter\DecimalFactory $filterDecimalFactory * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param array $data @@ -58,33 +62,24 @@ public function __construct( \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, - \Magento\Catalog\Model\Resource\Layer\Filter\DecimalFactory $filterDecimalFactory, + \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, + \Magento\Catalog\Model\Layer\Filter\DataProvider\DecimalFactory $dataProviderFactory, array $data = array() ) { - $this->_resource = $filterDecimalFactory->create(); $this->_requestVar = 'decimal'; $this->priceCurrency = $priceCurrency; - parent::__construct($filterItemFactory, $storeManager, $layer, $data); - } - - /** - * Retrieve resource instance - * - * @return \Magento\Catalog\Model\Resource\Layer\Filter\Decimal - */ - protected function _getResource() - { - return $this->_resource; + parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); + $this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]); } /** * Apply decimal range filter to product collection * - * @param \Zend_Controller_Request_Abstract $request + * @param \Magento\Framework\App\RequestInterface $request * @return $this */ - public function apply(\Zend_Controller_Request_Abstract $request) + public function apply(\Magento\Framework\App\RequestInterface $request) { parent::apply($request); @@ -103,30 +98,19 @@ public function apply(\Zend_Controller_Request_Abstract $request) list($index, $range) = $filter; if ((int)$index && (int)$range) { - $this->setRange((int)$range); + $this->dataProvider->setRange((int)$range); - $this->_getResource()->applyFilterToCollection($this, $range, $index); + $this->dataProvider->getResource()->applyFilterToCollection($this, $range, $index); $this->getLayer()->getState()->addFilter( $this->_createItem($this->_renderItemLabel($range, $index), $filter) ); - $this->_items = array(); + $this->_items = []; } return $this; } - /** - * Retrieve price aggreagation data cache key - * - * @return string - */ - protected function _getCacheKey() - { - $key = $this->getLayer()->getStateKey() . '_ATTR_' . $this->getAttributeModel()->getAttributeCode(); - return $key; - } - /** * Prepare text of item label * @@ -141,77 +125,6 @@ protected function _renderItemLabel($range, $value) return __('%1 - %2', $from, $to); } - /** - * Retrieve maximum value from layer products set - * - * @return float - */ - public function getMaxValue() - { - $max = $this->getData('max_value'); - if (is_null($max)) { - list($min, $max) = $this->_getResource()->getMinMax($this); - $this->setData('max_value', $max); - $this->setData('min_value', $min); - } - return $max; - } - - /** - * Retrieve minimal value from layer products set - * - * @return float - */ - public function getMinValue() - { - $min = $this->getData('min_value'); - if (is_null($min)) { - list($min, $max) = $this->_getResource()->getMinMax($this); - $this->setData('max_value', $max); - $this->setData('min_value', $min); - } - return $min; - } - - /** - * Retrieve range for building filter steps - * - * @return int - */ - public function getRange() - { - $range = $this->getData('range'); - if (!$range) { - $maxValue = $this->getMaxValue(); - $index = 1; - do { - $range = pow(10, strlen(floor($maxValue)) - $index); - $items = $this->getRangeItemCounts($range); - $index++; - } while ($range > self::MIN_RANGE_POWER && count($items) < 2); - $this->setData('range', $range); - } - - return $range; - } - - /** - * Retrieve information about products count in range - * - * @param int $range - * @return int - */ - public function getRangeItemCounts($range) - { - $rangeKey = 'range_item_counts_' . $range; - $items = $this->getData($rangeKey); - if (is_null($items)) { - $items = $this->_getResource()->getCount($this, $range); - $this->setData($rangeKey, $items); - } - return $items; - } - /** * Retrieve data for build decimal filter items * @@ -219,18 +132,17 @@ public function getRangeItemCounts($range) */ protected function _getItemsData() { - $data = array(); - $range = $this->getRange(); - $dbRanges = $this->getRangeItemCounts($range); + $range = $this->dataProvider->getRange($this); + $dbRanges = $this->dataProvider->getRangeItemCounts($range, $this); foreach ($dbRanges as $index => $count) { - $data[] = array( - 'label' => $this->_renderItemLabel($range, $index), - 'value' => $index . ',' . $range, - 'count' => $count + $this->itemDataBuilder->addItemData( + $this->_renderItemLabel($range, $index), + $index . ',' . $range, + $count ); } - return $data; + return $this->itemDataBuilder->build(); } } diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/AlgorithmFactory.php b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/AlgorithmFactory.php new file mode 100644 index 0000000000000..7fa24605bc649 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/AlgorithmFactory.php @@ -0,0 +1,99 @@ +objectManager = $objectManager; + $this->scopeConfig = $scopeConfig; + $this->algorithms = $algorithms; + } + + /** + * Create algorithm + * + * @param array $data + * @return AlgorithmInterface + * @throws Exception + */ + public function create(array $data = []) + { + $calculationType = $this->scopeConfig->getValue(self::XML_PATH_RANGE_CALCULATION, ScopeInterface::SCOPE_STORE); + + if (!isset($this->algorithms[$calculationType])) { + throw new Exception($calculationType . ' was not found in algorithms'); + } + + $className = $this->algorithms[$calculationType]; + $model = $this->objectManager->create($className, $data); + + if (!$model instanceof AlgorithmInterface) { + throw new Exception( + $className . ' doesn\'t extends \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmInterface' + ); + } + + return $model; + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/AlgorithmInterface.php b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/AlgorithmInterface.php new file mode 100644 index 0000000000000..bdd84ec247177 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/AlgorithmInterface.php @@ -0,0 +1,34 @@ +algorithm = $algorithm; + $this->layer = $layerResolver->get(); + $this->scopeConfig = $scopeConfig; + $this->render = $render; + $this->coreRegistry = $coreRegistry; + $this->range = $range; + $this->resource = $resource; + } + + /** + * {@inheritdoc} + */ + public function getItemsData(array $intervals = [], $additionalRequestData = '') + { + $data = []; + if (empty($intervals)) { + $range = $this->range->getPriceRange(); + if (!$range) { + $range = $this->getRange(); + $dbRanges = $this->resource->getCount($range); + $data = $this->render->renderRangeData($range, $dbRanges); + } + } + + return $data; + } + + /** + * @return number + */ + private function getRange() + { + $maxPrice = $this->getMaxPriceInt(); + $index = 1; + do { + $range = pow(10, strlen(floor($maxPrice)) - $index); + $items = $this->resource->getCount($range); + $index++; + } while ($range > self::MIN_RANGE_POWER && count($items) < 2); + + return $range; + } + + /** + * Get maximum price from layer products set + * + * @return float + */ + public function getMaxPriceInt() + { + $maxPrice = $this->layer->getProductCollection() + ->getMaxPrice(); + $maxPrice = floor($maxPrice); + + return $maxPrice; + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/Improved.php b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/Improved.php new file mode 100644 index 0000000000000..a81845a4045ef --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/Improved.php @@ -0,0 +1,128 @@ +algorithm = $algorithm; + $this->layer = $layerResolver->get(); + $this->scopeConfig = $scopeConfig; + $this->render = $render; + $this->intervalFactory = $intervalFactory; + } + + /** + * {@inheritdoc} + */ + public function getItemsData(array $intervals = [], $additionalRequestData = '') + { + $collection = $this->layer->getProductCollection(); + $appliedInterval = $intervals; + if ($appliedInterval && $collection->getPricesCount() <= $this->getIntervalDivisionLimit()) { + return array(); + } + $this->algorithm->setStatistics( + $collection->getMinPrice(), + $collection->getMaxPrice(), + $collection->getPriceStandardDeviation(), + $collection->getPricesCount() + ); + + if ($appliedInterval) { + if ($appliedInterval[0] == $appliedInterval[1] || $appliedInterval[1] === '0') { + return array(); + } + $this->algorithm->setLimits($appliedInterval[0], $appliedInterval[1]); + } + $interval = $this->intervalFactory->create(); + $items = array(); + foreach ($this->algorithm->calculateSeparators($interval) as $separator) { + $items[] = array( + 'label' => $this->render->renderRangeLabel($separator['from'], $separator['to']), + 'value' => ($separator['from'] == 0 ? '' + : $separator['from']) . '-' . $separator['to'] . $additionalRequestData, + 'count' => $separator['count'] + ); + } + + return $items; + } + + /** + * Get interval division limit + * + * @return int + */ + private function getIntervalDivisionLimit() + { + return (int)$this->scopeConfig->getValue(self::XML_PATH_INTERVAL_DIVISION_LIMIT, ScopeInterface::SCOPE_STORE); + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/Manual.php b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/Manual.php new file mode 100644 index 0000000000000..cf7d195bc695a --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Dynamic/Manual.php @@ -0,0 +1,120 @@ +algorithm = $algorithm; + $this->layer = $layerResolver->get(); + $this->scopeConfig = $scopeConfig; + $this->render = $render; + $this->coreRegistry = $coreRegistry; + $this->range = $range; + $this->resource = $resource; + } + + /** + * @param int[] $intervals + * @param string $additionalRequestData + * @return array + */ + public function getItemsData(array $intervals = [], $additionalRequestData = '') + { + $data = []; + if (empty($intervals)) { + $range = $this->range->getPriceRange(); + if (!$range) { + $range = $this->range->getConfigRangeStep(); + $dbRanges = $this->resource->getCount($range); + $dbRanges = $this->processRange($dbRanges); + $data = $this->render->renderRangeData($range, $dbRanges); + } + } + + return $data; + } + + /** + * @param array $items + * @return array + */ + private function processRange($items) + { + $i = 0; + $lastIndex = null; + $maxIntervalsNumber = $this->getMaxIntervalsNumber(); + foreach ($items as $k => $v) { + ++$i; + if ($i > 1 && $i > $maxIntervalsNumber) { + $items[$lastIndex] += $v; + unset($items[$k]); + } else { + $lastIndex = $k; + } + } + return $items; + } + + /** + * Get maximum number of intervals + * + * @return int + */ + public function getMaxIntervalsNumber() + { + return (int)$this->scopeConfig->getValue( + self::XML_PATH_RANGE_MAX_INTERVALS, + ScopeInterface::SCOPE_STORE + ); + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/FilterInterface.php b/app/code/Magento/Catalog/Model/Layer/Filter/FilterInterface.php new file mode 100644 index 0000000000000..d1308b8b0ed5d --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/FilterInterface.php @@ -0,0 +1,157 @@ + array( + * 'label' => $label, + * 'value' => $value, + * 'count' => $count + * ) + * ) + * + * @return array + */ + protected $_itemsData = []; + + /** + * Add Item Data + * + * @param string $label + * @param string $label + * @param int $count + * @return void + */ + public function addItemData($label, $value, $count) + { + $this->_itemsData[] = array( + 'label' => $label, + 'value' => $value, + 'count' => $count + ); + } + + /** + * Get Items Data + * + * @return array + */ + public function build() + { + $result = $this->_itemsData; + $this->_itemsData = []; + return $result; + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Price.php b/app/code/Magento/Catalog/Model/Layer/Filter/Price.php index 9fd739a5bb475..a4222ebddec5b 100644 --- a/app/code/Magento/Catalog/Model/Layer/Filter/Price.php +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Price.php @@ -30,34 +30,6 @@ */ class Price extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter { - /** - * XML configuration paths for Price Layered Navigation - */ - const XML_PATH_RANGE_CALCULATION = 'catalog/layered_navigation/price_range_calculation'; - - const XML_PATH_RANGE_STEP = 'catalog/layered_navigation/price_range_step'; - - const XML_PATH_RANGE_MAX_INTERVALS = 'catalog/layered_navigation/price_range_max_intervals'; - - const XML_PATH_ONE_PRICE_INTERVAL = 'catalog/layered_navigation/one_price_interval'; - - const XML_PATH_INTERVAL_DIVISION_LIMIT = 'catalog/layered_navigation/interval_division_limit'; - - /** - * Price layered navigation modes: Automatic (equalize price ranges), Automatic (equalize product counts), Manual - */ - const RANGE_CALCULATION_AUTO = 'auto'; - - // equalize price ranges - const RANGE_CALCULATION_IMPROVED = 'improved'; - - // equalize product counts - const RANGE_CALCULATION_MANUAL = 'manual'; - - /** - * Minimal size of the range - */ - const MIN_RANGE_POWER = 10; /** * Resource instance @@ -97,309 +69,57 @@ class Price extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter */ protected $priceCurrency; + /** + * @var Dynamic\AlgorithmFactory + */ + private $algorithmFactory; + + /** @var DataProvider\Price */ + private $dataProvider; + /** * @param ItemFactory $filterItemFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Layer $layer + * @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder * @param \Magento\Catalog\Model\Resource\Layer\Filter\Price $resource * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Framework\Search\Dynamic\Algorithm $priceAlgorithm - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency + * @param Dynamic\AlgorithmFactory $algorithmFactory + * @param DataProvider\PriceFactory $dataProviderFactory * @param array $data */ public function __construct( \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Layer $layer, + \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder, \Magento\Catalog\Model\Resource\Layer\Filter\Price $resource, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Search\Dynamic\Algorithm $priceAlgorithm, - \Magento\Framework\Registry $coreRegistry, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, - array $data = array() + \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory $algorithmFactory, + \Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory, + array $data = [] ) { $this->priceCurrency = $priceCurrency; $this->_resource = $resource; $this->_customerSession = $customerSession; $this->_priceAlgorithm = $priceAlgorithm; - $this->_coreRegistry = $coreRegistry; - $this->_scopeConfig = $scopeConfig; - parent::__construct($filterItemFactory, $storeManager, $layer, $data); + parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); $this->_requestVar = 'price'; - } - - /** - * Retrieve resource instance - * - * @return \Magento\Catalog\Model\Resource\Layer\Filter\Price - */ - protected function _getResource() - { - return $this->_resource; - } - - /** - * Get price range for building filter steps - * - * @return int - */ - public function getPriceRange() - { - $range = $this->getData('price_range'); - if (!$range) { - $currentCategory = $this->_coreRegistry->registry('current_category_filter'); - if ($currentCategory) { - $range = $currentCategory->getFilterPriceRange(); - } else { - $range = $this->getLayer()->getCurrentCategory()->getFilterPriceRange(); - } - - $maxPrice = $this->getMaxPriceInt(); - if (!$range) { - $calculation = $this->_scopeConfig->getValue( - self::XML_PATH_RANGE_CALCULATION, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - if ($calculation == self::RANGE_CALCULATION_AUTO) { - $index = 1; - do { - $range = pow(10, strlen(floor($maxPrice)) - $index); - $items = $this->getRangeItemCounts($range); - $index++; - } while ($range > self::MIN_RANGE_POWER && count($items) < 2); - } else { - $range = (double)$this->_scopeConfig->getValue( - self::XML_PATH_RANGE_STEP, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - } - } - - $this->setData('price_range', $range); - } - - return $range; - } - - /** - * Get maximum price from layer products set - * - * @return float - */ - public function getMaxPriceInt() - { - $maxPrice = $this->getData('max_price_int'); - if (is_null($maxPrice)) { - $maxPrice = $this->getLayer()->getProductCollection()->getMaxPrice(); - $maxPrice = floor($maxPrice); - $this->setData('max_price_int', $maxPrice); - } - - return $maxPrice; - } - - /** - * Get information about products count in range - * - * @param int $range - * @return int - */ - public function getRangeItemCounts($range) - { - $rangeKey = 'range_item_counts_' . $range; - $items = $this->getData($rangeKey); - if (is_null($items)) { - $items = $this->_getResource()->getCount($range); - // checking max number of intervals - $i = 0; - $lastIndex = null; - $maxIntervalsNumber = $this->getMaxIntervalsNumber(); - $calculation = $this->_scopeConfig->getValue( - self::XML_PATH_RANGE_CALCULATION, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - foreach ($items as $k => $v) { - ++$i; - if ($calculation == self::RANGE_CALCULATION_MANUAL && $i > 1 && $i > $maxIntervalsNumber) { - $items[$lastIndex] += $v; - unset($items[$k]); - } else { - $lastIndex = $k; - } - } - $this->setData($rangeKey, $items); - } - - return $items; - } - - /** - * Prepare text of range label - * - * @param float|string $fromPrice - * @param float|string $toPrice - * @return string - */ - protected function _renderRangeLabel($fromPrice, $toPrice) - { - $formattedFromPrice = $this->priceCurrency->format($fromPrice); - if ($toPrice === '') { - return __('%1 and above', $formattedFromPrice); - } elseif ($fromPrice == $toPrice && $this->_scopeConfig->getValue( - self::XML_PATH_ONE_PRICE_INTERVAL, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) - ) { - return $formattedFromPrice; - } else { - if ($fromPrice != $toPrice) { - $toPrice -= .01; - } - return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice)); - } - } - - /** - * Get additional request param data - * - * @return string - */ - protected function _getAdditionalRequestData() - { - $result = ''; - $appliedInterval = $this->getInterval(); - if ($appliedInterval) { - $result = ',' . $appliedInterval[0] . '-' . $appliedInterval[1]; - $priorIntervals = $this->getResetValue(); - if ($priorIntervals) { - $result .= ',' . $priorIntervals; - } - } - - return $result; - } - - /** - * Get data generated by algorithm for build price filter items - * - * @return array - */ - protected function _getCalculatedItemsData() - { - $collection = $this->getLayer()->getProductCollection(); - $appliedInterval = $this->getInterval(); - if ($appliedInterval && $collection->getPricesCount() <= $this->getIntervalDivisionLimit()) { - return array(); - } - $this->_priceAlgorithm->setStatistics( - $collection->getMinPrice(), - $collection->getMaxPrice(), - $collection->getPriceStandardDeviation(), - $collection->getPricesCount() - ); - - if ($appliedInterval) { - if ($appliedInterval[0] == $appliedInterval[1] || $appliedInterval[1] === '0') { - return array(); - } - $this->_priceAlgorithm->setLimits($appliedInterval[0], $appliedInterval[1]); - } - - $items = array(); - foreach ($this->_priceAlgorithm->calculateSeparators() as $separator) { - $items[] = array( - 'label' => $this->_renderRangeLabel($separator['from'], $separator['to']), - 'value' => ($separator['from'] == - 0 ? '' : $separator['from']) . '-' . $separator['to'] . $this->_getAdditionalRequestData(), - 'count' => $separator['count'] - ); - } - - return $items; - } - - /** - * Get data for build price filter items - * - * @return array - */ - protected function _getItemsData() - { - if ($this->_scopeConfig->getValue( - self::XML_PATH_RANGE_CALCULATION, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == self::RANGE_CALCULATION_IMPROVED - ) { - return $this->_getCalculatedItemsData(); - } elseif ($this->getInterval()) { - return array(); - } - - $range = $this->getPriceRange(); - $dbRanges = $this->getRangeItemCounts($range); - $data = array(); - - if (!empty($dbRanges)) { - $lastIndex = array_keys($dbRanges); - $lastIndex = $lastIndex[count($lastIndex) - 1]; - - foreach ($dbRanges as $index => $count) { - $fromPrice = $index == 1 ? '' : ($index - 1) * $range; - $toPrice = $index == $lastIndex ? '' : $index * $range; - - $data[] = array( - 'label' => $this->_renderRangeLabel($fromPrice, $toPrice), - 'value' => $fromPrice . '-' . $toPrice, - 'count' => $count - ); - } - } - - return $data; - } - - /** - * Apply price range filter to collection - * - * @return $this - */ - protected function _applyPriceRange() - { - $this->_getResource()->applyPriceRange($this); - return $this; - } - - /** - * Validate and parse filter request param - * - * @param string $filter - * @return array|bool - */ - protected function _validateFilter($filter) - { - $filter = explode('-', $filter); - if (count($filter) != 2) { - return false; - } - foreach ($filter as $v) { - if ($v !== '' && $v !== '0' && (double)$v <= 0 || is_infinite((double)$v)) { - return false; - } - } - - return $filter; + $this->algorithmFactory = $algorithmFactory; + $this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]); } /** * Apply price range filter * - * @param \Zend_Controller_Request_Abstract $request + * @param \Magento\Framework\App\RequestInterface $request * @return $this */ - public function apply(\Zend_Controller_Request_Abstract $request) + public function apply(\Magento\Framework\App\RequestInterface $request) { /** * Filter must be string: $fromPrice-$toPrice @@ -411,34 +131,26 @@ public function apply(\Zend_Controller_Request_Abstract $request) //validate filter $filterParams = explode(',', $filter); - $filter = $this->_validateFilter($filterParams[0]); + $filter = $this->dataProvider->validateFilter($filterParams[0]); if (!$filter) { return $this; } list($from, $to) = $filter; - $this->setInterval(array($from, $to)); - - $priorFilters = array(); - for ($i = 1; $i < count($filterParams); ++$i) { - $priorFilter = $this->_validateFilter($filterParams[$i]); - if ($priorFilter) { - $priorFilters[] = $priorFilter; - } else { - //not valid data - $priorFilters = array(); - break; - } - } + $this->dataProvider->setInterval([$from, $to]); + + $priorFilters = $this->dataProvider->getPriorFilters($filterParams); if ($priorFilters) { - $this->setPriorIntervals($priorFilters); + $this->dataProvider->setPriorIntervals($priorFilters); } $this->_applyPriceRange(); - $this->getLayer()->getState()->addFilter( - $this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter) - ); + $this->getLayer() + ->getState() + ->addFilter( + $this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter) + ); return $this; } @@ -454,6 +166,7 @@ public function getCustomerGroupId() if (is_null($customerGroupId)) { $customerGroupId = $this->_customerSession->getCustomerGroupId(); } + return $customerGroupId; } @@ -477,11 +190,13 @@ public function getCurrencyRate() { $rate = $this->_getData('currency_rate'); if (is_null($rate)) { - $rate = $this->_storeManager->getStore($this->getStoreId())->getCurrentCurrencyRate(); + $rate = $this->_storeManager->getStore($this->getStoreId()) + ->getCurrentCurrencyRate(); } if (!$rate) { $rate = 1; } + return $rate; } @@ -497,64 +212,95 @@ public function setCurrencyRate($rate) } /** - * Get maximum number of intervals + * Get filter value for reset current filter state * - * @return int + * @return null|string */ - public function getMaxIntervalsNumber() + public function getResetValue() { - return (int)$this->_scopeConfig->getValue( - self::XML_PATH_RANGE_MAX_INTERVALS, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + return $this->dataProvider->getResetValue(); } /** - * Get interval division limit + * Get 'clear price' link text * - * @return int + * @return false|string */ - public function getIntervalDivisionLimit() + public function getClearLinkText() { - return (int)$this->_scopeConfig->getValue( - self::XML_PATH_INTERVAL_DIVISION_LIMIT, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); + if ($this->dataProvider->getPriorIntervals() + ) { + return __('Clear Price'); + } + + return parent::getClearLinkText(); } /** - * Get filter value for reset current filter state + * Prepare text of range label * - * @return null|string + * @param float|string $fromPrice + * @param float|string $toPrice + * @return string */ - public function getResetValue() + protected function _renderRangeLabel($fromPrice, $toPrice) { - $priorIntervals = $this->getPriorIntervals(); - $value = array(); - if ($priorIntervals) { - foreach ($priorIntervals as $priorInterval) { - $value[] = implode('-', $priorInterval); + $formattedFromPrice = $this->priceCurrency->format($fromPrice); + if ($toPrice === '') { + return __('%1 and above', $formattedFromPrice); + } elseif ($fromPrice == $toPrice && $this->dataProvider->getOnePriceIntervalValue() + ) { + return $formattedFromPrice; + } else { + if ($fromPrice != $toPrice) { + $toPrice -= .01; } - return implode(',', $value); + + return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice)); } - return parent::getResetValue(); } /** - * Get 'clear price' link text + * Get additional request param data * - * @return false|string + * @return string */ - public function getClearLinkText() + protected function _getAdditionalRequestData() { - if ($this->_scopeConfig->getValue( - self::XML_PATH_RANGE_CALCULATION, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) == self::RANGE_CALCULATION_IMPROVED && $this->getPriorIntervals() - ) { - return __('Clear Price'); + $result = ''; + $appliedInterval = $this->dataProvider->getInterval(); + if ($appliedInterval) { + $result = ',' . $appliedInterval[0] . '-' . $appliedInterval[1]; + $priorIntervals = $this->getResetValue(); + if ($priorIntervals) { + $result .= ',' . $priorIntervals; + } } - return parent::getClearLinkText(); + return $result; + } + + /** + * Get data for build price filter items + * @return array + * @throws \Magento\Framework\Model\Exception + */ + protected function _getItemsData() + { + $algorithm = $this->algorithmFactory->create(); + + return $algorithm->getItemsData((array)$this->dataProvider->getInterval(), $this->dataProvider->getAdditionalRequestData()); + } + + /** + * Apply price range filter to collection + * + * @return $this + */ + protected function _applyPriceRange() + { + $this->dataProvider->getResource()->applyPriceRange($this, $this->dataProvider->getInterval()); + + return $this; } } diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Price/Range.php b/app/code/Magento/Catalog/Model/Layer/Filter/Price/Range.php new file mode 100644 index 0000000000000..088fb2399d448 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Price/Range.php @@ -0,0 +1,80 @@ +registry = $registry; + $this->scopeConfig = $scopeConfig; + $this->layer = $layerResolver->get(); + } + + /** + * @return array + */ + public function getPriceRange() + { + $currentCategory = $this->registry->registry('current_category_filter') ?: $this->layer->getCurrentCategory(); + + return $currentCategory->getFilterPriceRange(); + } + + /** + * @return float + */ + public function getConfigRangeStep() + { + return (double)$this->scopeConfig->getValue(self::XML_PATH_RANGE_STEP, ScopeInterface::SCOPE_STORE); + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php b/app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php new file mode 100644 index 0000000000000..d39f38b13d168 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php @@ -0,0 +1,116 @@ +priceCurrency = $priceCurrency; + $this->scopeConfig = $scopeConfig; + $this->itemDataBuilder = $itemDataBuilder; + } + + /** + * Prepare text of range label + * + * @param float|string $fromPrice + * @param float|string $toPrice + * @return string + */ + public function renderRangeLabel($fromPrice, $toPrice) + { + $formattedFromPrice = $this->priceCurrency->format($fromPrice); + $priceInterval = $this->scopeConfig->getValue( + self::XML_PATH_ONE_PRICE_INTERVAL, + ScopeInterface::SCOPE_STORE + ); + if ($toPrice === '') { + return __('%1 and above', $formattedFromPrice); + } elseif ($fromPrice == $toPrice && $priceInterval) { + return $formattedFromPrice; + } else { + if ($fromPrice != $toPrice) { + $toPrice -= .01; + } + + return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice)); + } + } + + /** + * @param int $range + * @param int[] $dbRanges + * @return array + */ + public function renderRangeData($range, $dbRanges) + { + if (empty($dbRanges)) { + return []; + } + $lastIndex = array_keys($dbRanges); + $lastIndex = $lastIndex[count($lastIndex) - 1]; + + foreach ($dbRanges as $index => $count) { + $fromPrice = $index == 1 ? '' : ($index - 1) * $range; + $toPrice = $index == $lastIndex ? '' : $index * $range; + $this->itemDataBuilder->addItemData( + $this->renderRangeLabel($fromPrice, $toPrice), + $fromPrice . '-' . $toPrice, + $count + ); + } + return $this->itemDataBuilder->build(); + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/FilterList.php b/app/code/Magento/Catalog/Model/Layer/FilterList.php index 705168e9418da..17f2ab1c53590 100644 --- a/app/code/Magento/Catalog/Model/Layer/FilterList.php +++ b/app/code/Magento/Catalog/Model/Layer/FilterList.php @@ -89,8 +89,8 @@ public function getFilters(\Magento\Catalog\Model\Layer $layer) $this->filters = array( $this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], array('layer' => $layer)), ); - foreach ($this->filterableAttributes->getList() as $attibute) { - $this->filters[] = $this->createAttributeFilter($attibute, $layer); + foreach ($this->filterableAttributes->getList() as $attribute) { + $this->filters[] = $this->createAttributeFilter($attribute, $layer); } } return $this->filters; @@ -101,12 +101,29 @@ public function getFilters(\Magento\Catalog\Model\Layer $layer) * * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @param \Magento\Catalog\Model\Layer $layer - * @return mixed + * @return \Magento\Catalog\Model\Layer\Filter\AbstractFilter */ protected function createAttributeFilter( \Magento\Catalog\Model\Resource\Eav\Attribute $attribute, \Magento\Catalog\Model\Layer $layer ) { + $filterClassName = $this->getAttributeFilterClass($attribute); + + $filter = $this->objectManager->create( + $filterClassName, + array('data' => array('attribute_model' => $attribute), 'layer' => $layer) + ); + return $filter; + } + + /** + * Get Attribute Filter Class Name + * + * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute + * @return string + */ + protected function getAttributeFilterClass(\Magento\Catalog\Model\Resource\Eav\Attribute $attribute) + { $filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER]; if ($attribute->getAttributeCode() == 'price') { @@ -115,10 +132,6 @@ protected function createAttributeFilter( $filterClassName = $this->filterTypes[self::DECIMAL_FILTER]; } - $filter = $this->objectManager->create( - $filterClassName, - array('data' => array('attribute_model' => $attribute), 'layer' => $layer) - ); - return $filter; + return $filterClassName; } } diff --git a/app/code/Magento/Catalog/Model/Layer/Resolver.php b/app/code/Magento/Catalog/Model/Layer/Resolver.php new file mode 100644 index 0000000000000..d5625106a3f59 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Layer/Resolver.php @@ -0,0 +1,92 @@ +objectManager = $objectManager; + $this->layersPool = $layersPool; + } + + /** + * Create Catalog Layer by specified type + * + * @param string $layerType + * @return void + */ + public function create($layerType) + { + if (isset($this->layer)) { + throw new \RuntimeException('Catalog Layer has been already created'); + } + if (!isset($this->layersPool[$layerType])) { + throw new \InvalidArgumentException($layerType . ' does not belong to any registered layer'); + } + $this->layer = $this->objectManager->create($this->layersPool[$layerType]); + } + + /** + * Get current Catalog Layer + * + * @return \Magento\Catalog\Model\Layer + */ + public function get() + { + if (!isset($this->layer)) { + $this->layer = $this->objectManager->create($this->layersPool[self::CATALOG_LAYER_CATEGORY]); + } + return $this->layer; + } +} diff --git a/app/code/Magento/Catalog/Model/Layer/Search.php b/app/code/Magento/Catalog/Model/Layer/Search.php index a5d8f3a1e07c8..7956accc655d0 100644 --- a/app/code/Magento/Catalog/Model/Layer/Search.php +++ b/app/code/Magento/Catalog/Model/Layer/Search.php @@ -28,11 +28,12 @@ use Magento\Catalog\Model\Layer; use Magento\Catalog\Model\Resource; use Magento\Framework\Object; +use Magento\Catalog\Model\Layer\ContextInterface; class Search extends \Magento\Catalog\Model\Layer { /** - * @param Search\Context $context + * @param ContextInterface $context * @param StateFactory $layerStateFactory * @param CategoryFactory $categoryFactory * @param Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory @@ -42,7 +43,7 @@ class Search extends \Magento\Catalog\Model\Layer * @param array $data */ public function __construct( - Search\Context $context, + ContextInterface $context, StateFactory $layerStateFactory, CategoryFactory $categoryFactory, Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory, diff --git a/app/code/Magento/Catalog/Model/Layer/Search/AvailabilityFlag.php b/app/code/Magento/Catalog/Model/Layer/Search/AvailabilityFlag.php deleted file mode 100644 index bdc7146d4ab42..0000000000000 --- a/app/code/Magento/Catalog/Model/Layer/Search/AvailabilityFlag.php +++ /dev/null @@ -1,31 +0,0 @@ -getIsFilterableInSearch(); } diff --git a/app/code/Magento/Catalog/Model/Layer/Search/FilterableAttributeList.php b/app/code/Magento/Catalog/Model/Layer/Search/FilterableAttributeList.php index df8d2dd170901..db0cae20c7af7 100644 --- a/app/code/Magento/Catalog/Model/Layer/Search/FilterableAttributeList.php +++ b/app/code/Magento/Catalog/Model/Layer/Search/FilterableAttributeList.php @@ -30,14 +30,14 @@ class FilterableAttributeList extends \Magento\Catalog\Model\Layer\Category\Filt /** * @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $collectionFactory * @param \Magento\Framework\StoreManagerInterface $storeManager - * @param \Magento\Catalog\Model\Layer\Search $layer + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver */ public function __construct( \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $collectionFactory, \Magento\Framework\StoreManagerInterface $storeManager, - \Magento\Catalog\Model\Layer\Search $layer + \Magento\Catalog\Model\Layer\Resolver $layerResolver ) { - parent::__construct($collectionFactory, $storeManager, $layer); + parent::__construct($collectionFactory, $storeManager, $layerResolver); } /** diff --git a/app/code/Magento/Catalog/Model/Observer.php b/app/code/Magento/Catalog/Model/Observer.php index 8ef26b5e73b01..864a5357d934c 100644 --- a/app/code/Magento/Catalog/Model/Observer.php +++ b/app/code/Magento/Catalog/Model/Observer.php @@ -83,7 +83,7 @@ class Observer * @param \Magento\Catalog\Model\Resource\Category $categoryResource * @param \Magento\Catalog\Model\Resource\Product $catalogProduct * @param \Magento\Framework\StoreManagerInterface $storeManager - * @param \Magento\Catalog\Model\Layer\Category $catalogLayer + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param \Magento\Catalog\Helper\Category $catalogCategory * @param \Magento\Catalog\Helper\Data $catalogData * @param Indexer\Category\Flat\State $categoryFlatState @@ -93,7 +93,7 @@ public function __construct( \Magento\Catalog\Model\Resource\Category $categoryResource, \Magento\Catalog\Model\Resource\Product $catalogProduct, \Magento\Framework\StoreManagerInterface $storeManager, - \Magento\Catalog\Model\Layer\Category $catalogLayer, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Catalog\Helper\Category $catalogCategory, \Magento\Catalog\Helper\Data $catalogData, \Magento\Catalog\Model\Indexer\Category\Flat\State $categoryFlatState, @@ -102,7 +102,7 @@ public function __construct( $this->_categoryResource = $categoryResource; $this->_catalogProduct = $catalogProduct; $this->_storeManager = $storeManager; - $this->_catalogLayer = $catalogLayer; + $this->_catalogLayer = $layerResolver->get(); $this->_catalogCategory = $catalogCategory; $this->_catalogData = $catalogData; $this->categoryFlatConfig = $categoryFlatState; diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 26bab0eb2d061..d9f6376483d01 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -26,6 +26,8 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Pricing\Object\SaleableInterface; use Magento\Framework\Object\IdentityInterface; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Framework\Convert\ConvertArray; /** * Catalog product model @@ -45,7 +47,10 @@ * * @SuppressWarnings(PHPMD.LongVariable) */ -class Product extends \Magento\Catalog\Model\AbstractModel implements IdentityInterface, SaleableInterface +class Product extends \Magento\Catalog\Model\AbstractModel implements + IdentityInterface, + SaleableInterface, + ProductInterface { /** * Entity code. @@ -262,6 +267,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements IdentityIn /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataService * @param \Magento\Framework\StoreManagerInterface $storeManager * @param Product\Url $url * @param Product\Link $productLink @@ -291,6 +297,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements IdentityIn public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataService, \Magento\Framework\StoreManagerInterface $storeManager, Product\Url $url, Product\Link $productLink, @@ -334,7 +341,15 @@ public function __construct( $this->_productFlatIndexerProcessor = $productFlatIndexerProcessor; $this->_productPriceIndexerProcessor = $productPriceIndexerProcessor; $this->_productEavIndexerProcessor = $productEavIndexerProcessor; - parent::__construct($context, $registry, $storeManager, $resource, $resourceCollection, $data); + parent::__construct( + $context, + $registry, + $metadataService, + $storeManager, + $resource, + $resourceCollection, + $data + ); } /** @@ -421,6 +436,47 @@ public function getPrice() } } + /** + * Get visibility status + * @see \Magento\Catalog\Model\Product\Visibility + * + * @return int + */ + public function getVisibility() + { + return $this->_getData('visibility'); + } + + /** + * Get product attribute set id + * + * @return int + */ + public function getAttributeSetId() + { + return $this->_getData('attribute_set_id'); + } + + /** + * Get product creation date + * + * @return string + */ + public function getCreatedAt() + { + return $this->_getData('created_at'); + } + + /** + * Get previous product update date + * + * @return string + */ + public function getUpdatedAt() + { + return $this->_getData('updated_at'); + } + /** * Set Price calculation flag * @@ -628,7 +684,7 @@ public function getAttributes($groupId = null, $skipSuper = false) * * @return void */ - protected function _beforeSave() + public function beforeSave() { $this->cleanCache(); $this->setTypeHasOptions(false); @@ -685,7 +741,7 @@ protected function _beforeSave() $this->setOrigData('website_ids', $websiteIds); } - parent::_beforeSave(); + parent::beforeSave(); } /** @@ -708,7 +764,7 @@ public function canAffectOptions($value = null) * * @return \Magento\Catalog\Model\Product */ - protected function _afterSave() + public function afterSave() { $this->getLinkInstance()->saveProductRelations($this); $this->getTypeInstance()->save($this); @@ -727,7 +783,7 @@ protected function _afterSave() $this->getOptionInstance()->setProduct($this)->saveOptions(); } - $result = parent::_afterSave(); + $result = parent::afterSave(); $this->_getResource()->addCommitCallback(array($this, 'reindex')); $this->reloadPriceInfo(); @@ -801,10 +857,10 @@ public function reindex() * * @return \Magento\Catalog\Model\Product */ - protected function _beforeDelete() + public function beforeDelete() { $this->cleanCache(); - return parent::_beforeDelete(); + return parent::beforeDelete(); } /** @@ -812,11 +868,11 @@ protected function _beforeDelete() * * @return void */ - protected function _afterDeleteCommit() + public function afterDeleteCommit() { $this->reindex(); $this->_productPriceIndexerProcessor->reindexRow($this->getId()); - parent::_afterDeleteCommit(); + parent::afterDeleteCommit(); } /** @@ -1391,8 +1447,8 @@ public function getIsSalable() if (method_exists($productType, 'getIsSalable')) { return $productType->getIsSalable($this); } - if ($this->hasData('is_salable')) { - return $this->getData('is_salable'); + if ($this->hasData('is_saleable')) { + return $this->getData('is_saleable'); } return $this->isSalable(); @@ -1547,21 +1603,6 @@ public function fromArray(array $data) return $this; } - /** - * Delete product - * - * @return \Magento\Catalog\Model\Product - */ - public function delete() - { - parent::delete(); - $this->_eventManager->dispatch( - $this->_eventPrefix . '_delete_after_done', - array($this->_eventObject => $this) - ); - return $this; - } - /** * Returns request path * @@ -2028,4 +2069,51 @@ public function reloadPriceInfo() return $this->getPriceInfo(); } } + + /** + * Return Data Object data in array format. + * + * @return array + */ + public function __toArray() + { + $data = $this->_data; + $hasToArray = function ($model) { + return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']); + }; + foreach ($data as $key => $value) { + if ($hasToArray($value)) { + $data[$key] = $value->__toArray(); + } elseif (is_array($value)) { + foreach ($value as $nestedKey => $nestedValue) { + if ($hasToArray($nestedValue)) { + $value[$nestedKey] = $nestedValue->__toArray(); + } + } + $data[$key] = $value; + } + } + return $data; + } + + /** + * Convert Category model into flat array. + * + * @return array + */ + public function toFlatArray() + { + $dataArray = $this->__toArray(); + //process custom attributes if present + if (array_key_exists('custom_attributes', $dataArray) && !empty($dataArray['custom_attributes'])) { + /** @var \Magento\Framework\Api\AttributeInterface[] $customAttributes */ + $customAttributes = $dataArray['custom_attributes']; + unset ($dataArray['custom_attributes']); + foreach ($customAttributes as $attributeValue) { + $dataArray[$attributeValue[\Magento\Framework\Api\AttributeInterface::ATTRIBUTE_CODE]] + = $attributeValue[\Magento\Framework\Api\AttributeInterface::VALUE]; + } + } + return $dataArray; + } } diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice.php index 03a9da41cc411..d73024f635dab 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice.php @@ -43,6 +43,7 @@ class Groupprice extends \Magento\Catalog\Model\Product\Attribute\Backend\Groupp * @param \Magento\Catalog\Helper\Data $catalogData * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Catalog\Model\Product\Type $catalogProductType + * @param \Magento\Customer\Api\GroupManagementInterface $groupManagement * @param \Magento\Catalog\Model\Resource\Product\Attribute\Backend\Groupprice $productAttributeBackendGroupprice */ public function __construct( @@ -51,10 +52,18 @@ public function __construct( \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Catalog\Model\Product\Type $catalogProductType, + \Magento\Customer\Api\GroupManagementInterface $groupManagement, \Magento\Catalog\Model\Resource\Product\Attribute\Backend\Groupprice $productAttributeBackendGroupprice ) { $this->_productAttributeBackendGroupprice = $productAttributeBackendGroupprice; - parent::__construct($currencyFactory, $storeManager, $catalogData, $config, $catalogProductType); + parent::__construct( + $currencyFactory, + $storeManager, + $catalogData, + $config, + $catalogProductType, + $groupManagement + ); } /** diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice/AbstractGroupprice.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice/AbstractGroupprice.php index c83318bcf6866..2b27ec570cd4c 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice/AbstractGroupprice.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Groupprice/AbstractGroupprice.php @@ -24,7 +24,7 @@ namespace Magento\Catalog\Model\Product\Attribute\Backend\Groupprice; use Magento\Catalog\Model\Product\Attribute\Backend\Price; -use Magento\Customer\Service\V1\CustomerGroupServiceInterface; +use Magento\Customer\Api\GroupManagementInterface; /** * Catalog product abstract group price backend attribute model @@ -53,21 +53,29 @@ abstract protected function _getDuplicateErrorMessage(); */ protected $_catalogProductType; + /** + * @var GroupManagementInterface + */ + protected $_groupManagement; + /** * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Helper\Data $catalogData * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Catalog\Model\Product\Type $catalogProductType + * @param GroupManagementInterface $groupManagement */ public function __construct( \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Catalog\Model\Product\Type $catalogProductType + \Magento\Catalog\Model\Product\Type $catalogProductType, + GroupManagementInterface $groupManagement ) { $this->_catalogProductType = $catalogProductType; + $this->_groupManagement = $groupManagement; parent::__construct($currencyFactory, $storeManager, $catalogData, $config); } @@ -271,7 +279,7 @@ public function afterLoad($object) foreach ($data as $k => $v) { $data[$k]['website_price'] = $v['price']; if ($v['all_groups']) { - $data[$k]['cust_group'] = CustomerGroupServiceInterface::CUST_GROUP_ALL; + $data[$k]['cust_group'] = $this->_groupManagement->getAllCustomersGroup()->getId(); } } @@ -356,7 +364,7 @@ public function afterSave($object) array_merge(array($data['website_id'], $data['cust_group']), $this->_getAdditionalUniqueFields($data)) ); - $useForAllGroups = $data['cust_group'] == CustomerGroupServiceInterface::CUST_GROUP_ALL; + $useForAllGroups = $data['cust_group'] == $this->_groupManagement->getAllCustomersGroup()->getId(); $customerGroupId = !$useForAllGroups ? $data['cust_group'] : 0; $new[$key] = array_merge( diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php index 6b1b2cc597438..2a0d11c121193 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php @@ -45,6 +45,7 @@ class Tierprice extends \Magento\Catalog\Model\Product\Attribute\Backend\Grouppr * @param \Magento\Catalog\Helper\Data $catalogData * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Catalog\Model\Product\Type $catalogProductType + * @param \Magento\Customer\Api\GroupManagementInterface $groupManagement * @param \Magento\Catalog\Model\Resource\Product\Attribute\Backend\Tierprice $productAttributeTierprice */ public function __construct( @@ -53,10 +54,18 @@ public function __construct( \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Catalog\Model\Product\Type $catalogProductType, + \Magento\Customer\Api\GroupManagementInterface $groupManagement, \Magento\Catalog\Model\Resource\Product\Attribute\Backend\Tierprice $productAttributeTierprice ) { $this->_productAttributeBackendTierprice = $productAttributeTierprice; - parent::__construct($currencyFactory, $storeManager, $catalogData, $config, $catalogProductType); + parent::__construct( + $currencyFactory, + $storeManager, + $catalogData, + $config, + $catalogProductType, + $groupManagement + ); } /** diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Group.php b/app/code/Magento/Catalog/Model/Product/Attribute/Group.php index 7a6a5e4314d5c..298799eaf7509 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Group.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Group.php @@ -36,6 +36,7 @@ class Group extends \Magento\Eav\Model\Entity\Attribute\Group /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Api\MetadataServiceInterface $metadataService * @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\Db $resourceCollection @@ -44,13 +45,14 @@ class Group extends \Magento\Eav\Model\Entity\Attribute\Group public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Framework\Api\MetadataServiceInterface $metadataService, \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = array() ) { $this->_attributeCollectionFactory = $attributeCollectionFactory; - parent::__construct($context, $registry, $resource, $resourceCollection, $data); + parent::__construct($context, $registry, $metadataService, $resource, $resourceCollection, $data); } /** diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Management.php b/app/code/Magento/Catalog/Model/Product/Attribute/Management.php new file mode 100644 index 0000000000000..288600b891cdb --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Management.php @@ -0,0 +1,75 @@ +eavAttributeManagement = $eavAttributeManagement; + } + + /** + * {@inheritdoc} + */ + public function assign($attributeSetId, $attributeGroupId, $attributeCode, $sortOrder) + { + return $this->eavAttributeManagement->assign( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $attributeSetId, + $attributeGroupId, + $attributeCode, + $sortOrder + ); + } + + /** + * {@inheritdoc} + */ + public function unassign($attributeSetId, $attributeCode) + { + return $this->eavAttributeManagement->unassign($attributeSetId, $attributeCode); + } + + /** + * {@inheritdoc} + */ + public function getAttributes($attributeSetId) + { + return $this->eavAttributeManagement->getAttributes( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $attributeSetId + ); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/OptionManagement.php b/app/code/Magento/Catalog/Model/Product/Attribute/OptionManagement.php new file mode 100644 index 0000000000000..e31255acf139c --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/OptionManagement.php @@ -0,0 +1,83 @@ + + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +namespace Magento\Catalog\Model\Product\Attribute; + +use Magento\Framework\Exception\InputException; + +class OptionManagement implements \Magento\Catalog\Api\ProductAttributeOptionManagementInterface +{ + /** + * @var \Magento\Eav\Api\AttributeOptionManagementInterface + */ + protected $eavOptionManagement; + + /** + * @param \Magento\Eav\Api\AttributeOptionManagementInterface $eavOptionManagement + */ + public function __construct( + \Magento\Eav\Api\AttributeOptionManagementInterface $eavOptionManagement + ) { + $this->eavOptionManagement = $eavOptionManagement; + } + + /** + * {@inheritdoc} + */ + public function getItems($attributeCode) + { + return $this->eavOptionManagement->getItems( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $attributeCode + ); + } + + /** + * {@inheritdoc} + */ + public function add($attributeCode, $option) + { + return $this->eavOptionManagement->add( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $attributeCode, + $option + ); + } + + /** + * {@inheritdoc} + */ + public function delete($attributeCode, $optionId) + { + if (empty($optionId)) { + throw new InputException(sprintf('Invalid option id %s', $optionId)); + } + + return $this->eavOptionManagement->delete( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $attributeCode, + $optionId + ); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Repository.php b/app/code/Magento/Catalog/Model/Product/Attribute/Repository.php new file mode 100644 index 0000000000000..6d8deca5bfecc --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Repository.php @@ -0,0 +1,306 @@ +attributeResource = $attributeResource; + $this->attributeBuilder = $attributeBuilder; + $this->productHelper = $productHelper; + $this->filterManager = $filterManager; + $this->eavAttributeRepository = $eavAttributeRepository; + $this->eavConfig = $eavConfig; + $this->inputtypeValidatorFactory = $validatorFactory; + $this->metadataConfig = $metadataConfig; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->filterBuilder = $filterBuilder; + } + + /** + * {@inheritdoc} + */ + public function get($attributeCode) + { + return $this->eavAttributeRepository->get( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $attributeCode + ); + } + + /** + * {@inheritdoc} + */ + public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) + { + return $this->eavAttributeRepository->getList( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $searchCriteria + ); + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute) + { + $this->attributeBuilder->populate($attribute); + + if ($attribute->getAttributeId()) { + $existingModel = $this->get($attribute->getAttributeCode()); + + if (!$existingModel->getAttributeId()) { + throw NoSuchEntityException::singleField('attribute_code', $existingModel->getAttributeCode()); + } + + $this->attributeBuilder->setAttributeId($existingModel->getAttributeId()); + $this->attributeBuilder->setIsUserDefined($existingModel->getIsUserDefined()); + $this->attributeBuilder->setFrontendInput($existingModel->getFrontendInput()); + + if (is_array($attribute->getFrontendLabels())) { + $frontendLabel[0] = $existingModel->getDefaultFrontendLabel(); + foreach ($attribute->getFrontendLabels() as $item) { + $frontendLabel[$item->getStoreId()] = $item->getLabel(); + } + $this->attributeBuilder->setDefaultFrontendLabel($frontendLabel); + } + if (!$attribute->getIsUserDefined()) { + // Unset attribute field for system attributes + $this->attributeBuilder->setApplyTo(null); + } + } else { + $this->attributeBuilder->setAttributeId(null); + + if (!$attribute->getFrontendLabels() && !$attribute->getDefaultFrontendLabel()) { + throw InputException::requiredField('frontend_label'); + } + + $frontendLabels = []; + if ($attribute->getDefaultFrontendLabel()) { + $frontendLabels[0] = $attribute->getDefaultFrontendLabel(); + } + if ($attribute->getFrontendLabels() && is_array($attribute->getFrontendLabels())) { + foreach ($attribute->getFrontendLabels() as $label) { + $frontendLabels[$label->getStoreId()] = $label->getLabel(); + } + if (!isset($frontendLabels[0]) || !$frontendLabels[0]) { + throw InputException::invalidFieldValue('frontend_label', null); + } + + $this->attributeBuilder->setDefaultFrontendLabel($frontendLabels); + } + $this->attributeBuilder->setAttributeCode( + $attribute->getAttributeCode() ?: $this->generateCode($frontendLabels[0]) + ); + $this->validateCode($attribute->getAttributeCode()); + $this->validateFrontendInput($attribute->getFrontendInput()); + + $this->attributeBuilder->setBackendType( + $attribute->getBackendTypeByInput($attribute->getFrontendInput()) + ); + $this->attributeBuilder->setSourceModel( + $this->productHelper->getAttributeSourceModelByInputType($attribute->getFrontendInput()) + ); + $this->attributeBuilder->setBackendModel( + $this->productHelper->getAttributeBackendModelByInputType($attribute->getFrontendInput()) + ); + $this->attributeBuilder->setEntityTypeId( + $this->eavConfig + ->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE) + ->getId() + ); + $this->attributeBuilder->setIsUserDefined(1); + } + $attribute = $this->attributeBuilder->create(); + $this->attributeResource->save($attribute); + return $attribute; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute) + { + $this->attributeResource->delete($attribute); + return true; + } + + /** + * {@inheritdoc} + */ + public function deleteById($attributeCode) + { + $this->delete( + $this->get($attributeCode) + ); + return true; + } + + /** + * {@inheritdoc} + */ + public function getCustomAttributesMetadata($dataObjectClassName = null) + { + $searchCriteria = $this->searchCriteriaBuilder->addFilter( + [ + $this->filterBuilder + ->setField('attribute_set_id') + ->setValue(\Magento\Catalog\Api\Data\ProductAttributeInterface::DEFAULT_ATTRIBUTE_SET_ID) + ->create() + ] + ); + + $customAttributes = []; + $entityAttributes = $this->getList($searchCriteria->create())->getItems(); + + foreach ($entityAttributes as $attributeMetadata) { + $customAttributes[] = $attributeMetadata; + } + return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName)); + } + + /** + * Generate code from label + * + * @param string $label + * @return string + */ + protected function generateCode($label) + { + $code = substr(preg_replace('/[^a-z_0-9]/', '_', $this->filterManager->translitUrl($label)), 0, 30); + $validatorAttrCode = new \Zend_Validate_Regex(['pattern' => '/^[a-z][a-z_0-9]{0,29}[a-z0-9]$/']); + if (!$validatorAttrCode->isValid($code)) { + $code = 'attr_' . ($code ?: substr(md5(time()), 0, 8)); + } + return $code; + } + + /** + * Validate attribute code + * + * @param string $code + * @return void + * @throws \Magento\Framework\Exception\InputException + */ + protected function validateCode($code) + { + $validatorAttrCode = new \Zend_Validate_Regex(['pattern' => '/^[a-z][a-z_0-9]{0,30}$/']); + if (!$validatorAttrCode->isValid($code)) { + throw InputException::invalidFieldValue('attribute_code', $code); + } + } + + /** + * Validate Frontend Input Type + * + * @param string $frontendInput + * @return void + * @throws \Magento\Framework\Exception\InputException + */ + protected function validateFrontendInput($frontendInput) + { + /** @var \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator $validator */ + $validator = $this->inputtypeValidatorFactory->create(); + if (!$validator->isValid($frontendInput)) { + throw InputException::invalidFieldValue('frontend_input', $frontendInput); + } + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/SetManagement.php b/app/code/Magento/Catalog/Model/Product/Attribute/SetManagement.php new file mode 100644 index 0000000000000..ea1d8f77d2c42 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/SetManagement.php @@ -0,0 +1,91 @@ +attributeSetManagement = $attributeSetManagement; + $this->attributeSetRepository = $attributeSetRepository; + $this->eavConfig = $eavConfig; + } + + /** + * {@inheritdoc} + */ + public function create(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet, $skeletonId) + { + $this->validateSkeletonSet($skeletonId); + return $this->attributeSetManagement->create( + \Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, + $attributeSet, + $skeletonId + ); + } + + /** + * @param int $skeletonId + * @return void + * @throws StateException + */ + protected function validateSkeletonSet($skeletonId) + { + try { + $skeletonSet = $this->attributeSetRepository->get($skeletonId); + $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); + if ($skeletonSet->getEntityTypeId() != $productEntityId) { + throw new StateException('Can not create attribute set based on non product attribute set.'); + } + } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) { + throw new StateException('Can not create attribute set based on not existing attribute set'); + } + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php new file mode 100644 index 0000000000000..32c31ada56979 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/SetRepository.php @@ -0,0 +1,139 @@ +attributeSetRepository = $attributeSetRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->filterBuilder = $filterBuilder; + $this->eavConfig = $eavConfig; + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet) + { + $this->validate($attributeSet); + return $this->attributeSetRepository->save($attributeSet); + } + + /** + * {@inheritdoc} + */ + public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) + { + $this->searchCriteriaBuilder->addFilter( + [ + $this->filterBuilder + ->setField('entity_type_code') + ->setValue(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE) + ->setConditionType('eq') + ->create() + ] + ); + $this->searchCriteriaBuilder->setCurrentPage($searchCriteria->getCurrentPage()); + $this->searchCriteriaBuilder->setPageSize($searchCriteria->getPageSize()); + return $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create()); + } + + /** + * {@inheritdoc} + */ + public function get($attributeSetId) + { + $attributeSet = $this->attributeSetRepository->get($attributeSetId); + $this->validate($attributeSet); + return $attributeSet; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet) + { + $this->validate($attributeSet); + return $this->attributeSetRepository->delete($attributeSet); + } + + /** + * {@inheritdoc} + */ + public function deleteById($attributeSetId) + { + $this->get($attributeSetId); + return $this->attributeSetRepository->deleteById($attributeSetId); + } + + /** + * Validate Frontend Input Type + * + * @param \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet + * @return void + * @throws \Magento\Framework\Exception\InputException + */ + protected function validate(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet) + { + $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); + if ($attributeSet->getEntityTypeId() != $productEntityId) { + throw new \Magento\Framework\Exception\StateException('Provided Attribute set non product Attribute set.'); + } + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Type.php b/app/code/Magento/Catalog/Model/Product/Attribute/Type.php new file mode 100644 index 0000000000000..6fdfe58fabb0e --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Type.php @@ -0,0 +1,45 @@ +getData('value'); + } + + /** + * {@inheritdoc} + */ + public function getLabel() + { + return $this->getData(self::LABEL); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/TypesList.php b/app/code/Magento/Catalog/Model/Product/Attribute/TypesList.php new file mode 100644 index 0000000000000..27781021923a1 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Attribute/TypesList.php @@ -0,0 +1,68 @@ +inputTypeFactory = $inputTypeFactory; + $this->attributeTypeBuilder = $attributeTypeBuilder; + } + + /** + * {@inheritdoc} + */ + public function getItems() + { + $types = []; + $inputType = $this->inputTypeFactory->create(); + + foreach ($inputType->toOptionArray() as $option) { + $types[] = $this->attributeTypeBuilder->populateWithArray($option)->create(); + } + return $types; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/AttributeSet/AlreadyExistsException.php b/app/code/Magento/Catalog/Model/Product/AttributeSet/AlreadyExistsException.php new file mode 100644 index 0000000000000..ac3dda6de65dd --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/AttributeSet/AlreadyExistsException.php @@ -0,0 +1,29 @@ +attributeSetFactory = $attributeSetFactory; + } + + /** + * @param int $entityTypeId + * @return $this + */ + public function setEntityTypeId($entityTypeId) + { + $this->entityTypeId = (int)$entityTypeId; + return $this; + } + + /** + * @param int $skeletonId + * @return $this + */ + public function setSkeletonId($skeletonId) + { + $this->skeletonId = (int)$skeletonId; + return $this; + } + + /** + * @param string $setName + * @return $this + */ + public function setName($setName) + { + $this->name = $setName; + return $this; + } + + /** + * @return \Magento\Eav\Model\Entity\Attribute\Set + * @throws AlreadyExistsException + */ + public function getAttributeSet() + { + $this->validateParameters(); + /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */ + $attributeSet = $this->attributeSetFactory->create(); + $attributeSet->setEntityTypeId($this->entityTypeId)->load($this->name, 'attribute_set_name'); + if ($attributeSet->getId()) { + throw new AlreadyExistsException(); + } + + $attributeSet->setAttributeSetName($this->name)->validate(); + $attributeSet->save(); + $attributeSet->initFromSkeleton($this->skeletonId)->save(); + + return $attributeSet; + } + + /** + * @trows \InvalidArgumentException + * @return void + */ + protected function validateParameters() + { + if (empty($this->name)) { + throw new \InvalidArgumentException(); + } elseif (empty($this->skeletonId)) { + throw new \InvalidArgumentException(); + } elseif (empty($this->entityTypeId)) { + throw new \InvalidArgumentException(); + } + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Compare/Item.php b/app/code/Magento/Catalog/Model/Product/Compare/Item.php index e4db0341e799f..77f3459bf5155 100644 --- a/app/code/Magento/Catalog/Model/Product/Compare/Item.php +++ b/app/code/Magento/Catalog/Model/Product/Compare/Item.php @@ -141,9 +141,9 @@ protected function _getResource() * * @return $this */ - protected function _beforeSave() + public function beforeSave() { - parent::_beforeSave(); + parent::beforeSave(); if (!$this->hasStoreId()) { $this->setStoreId($this->_storeManager->getStore()->getId()); } diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/ContentValidator.php b/app/code/Magento/Catalog/Model/Product/Gallery/ContentValidator.php new file mode 100644 index 0000000000000..986c23402cf1a --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Gallery/ContentValidator.php @@ -0,0 +1,108 @@ +allowedMimeTypes = array_merge($this->defaultMimeTypes, $allowedMimeTypes); + } + + /** + * Check if gallery entry content is valid + * + * @param ProductAttributeMediaGalleryEntryContentInterface $entryContent + * @return bool + * @throws InputException + */ + public function isValid(ProductAttributeMediaGalleryEntryContentInterface $entryContent) + { + $fileContent = @base64_decode($entryContent->getEntryData(), true); + if (empty($fileContent)) { + throw new InputException('The image content must be valid base64 encoded data.'); + } + $imageProperties = @getimagesizefromstring($fileContent); + if (empty($imageProperties)) { + throw new InputException('The image content must be valid base64 encoded data.'); + } + $sourceMimeType = $imageProperties['mime']; + if ($sourceMimeType != $entryContent->getMimeType() || !$this->isMimeTypeValid($sourceMimeType)) { + throw new InputException('The image MIME type is not valid or not supported.'); + } + if (!$this->isNameValid($entryContent->getName())) { + throw new InputException('Provided image name contains forbidden characters.'); + } + return true; + } + + /** + * Check if given mime type is valid + * + * @param string $mimeType + * @return bool + */ + protected function isMimeTypeValid($mimeType) + { + return in_array($mimeType, $this->allowedMimeTypes); + } + + /** + * Check if given filename is valid + * + * @param string $name + * @return bool + */ + protected function isNameValid($name) + { + // Cannot contain \ / : * ? " < > | + if (!preg_match('/^[^\\/?*:";<>()|{}\\\\]+$/', $name)) { + return false; + } + return true; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/Entry.php b/app/code/Magento/Catalog/Model/Product/Gallery/Entry.php new file mode 100644 index 0000000000000..fcbba1ed3d0db --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Gallery/Entry.php @@ -0,0 +1,89 @@ +getData(self::ID); + } + + /** + * Retrieve gallery entry alternative text + * + * @return string + */ + public function getLabel() + { + return $this->getData(self::LABEL); + } + + /** + * Retrieve gallery entry position (sort order) + * + * @return int + */ + public function getPosition() + { + return $this->getData(self::POSITION); + } + + /** + * Check if gallery entry is hidden from product page + * + * @return bool + */ + public function getIsDisabled() + { + return $this->getData(self::DISABLED); + } + + /** + * Retrieve gallery entry image types (thumbnail, image, small_image etc) + * + * @return string[] + */ + public function getTypes() + { + return $this->getData(self::TYPES); + } + + /** + * Get file path + * + * @return string + */ + public function getFile() + { + return $this->getData(self::FILE); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/EntryResolver.php b/app/code/Magento/Catalog/Model/Product/Gallery/EntryResolver.php new file mode 100644 index 0000000000000..df78aacd812e4 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Gallery/EntryResolver.php @@ -0,0 +1,75 @@ +getData('media_gallery'); + if (!isset($mediaGalleryData['images']) || !is_array($mediaGalleryData['images'])) { + return null; + } + + foreach ($mediaGalleryData['images'] as $image) { + if (isset($image['value_id']) && $image['value_id'] == $entryId) { + return isset($image['file']) ? $image['file'] : null; + } + } + return null; + } + + /** + * Retrieve gallery entry ID that corresponds to the given file path + * + * @param Product $product + * @param string $filePath + * @return int|null + */ + public function getEntryIdByFilePath(Product $product, $filePath) + { + $mediaGalleryData = $product->getData('media_gallery'); + if (!isset($mediaGalleryData['images']) || !is_array($mediaGalleryData['images'])) { + return null; + } + + foreach ($mediaGalleryData['images'] as $image) { + if (isset($image['file']) && $image['file'] == $filePath) { + return isset($image['value_id']) ? $image['value_id'] : null; + } + } + return null; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php b/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php new file mode 100644 index 0000000000000..81db877435ba8 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php @@ -0,0 +1,326 @@ + 'jpg', + 'image/jpeg' => 'jpg', + 'image/gif' => 'gif', + 'image/png' => 'png', + ); + + /** + * @var \Magento\Framework\StoreManagerInterface + */ + protected $storeManager; + + /** + * @var \Magento\Catalog\Api\ProductRepositoryInterface + */ + protected $productRepository; + + /** + * @var MediaConfig + */ + protected $mediaConfig; + + /** + * @var \Magento\Catalog\Model\Product\Gallery\ContentValidator + */ + protected $contentValidator; + + /** + * @var \Magento\Framework\Filesystem + */ + protected $filesystem; + + /** + * @var \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryDataBuilder + */ + protected $entryBuilder; + + /** + * @var \Magento\Catalog\Model\Resource\Product\Attribute\Backend\Media + */ + protected $mediaGallery; + + /** + * @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface + */ + protected $attributeRepository; + + /** + * @param \Magento\Framework\StoreManagerInterface $storeManager + * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository + * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository + * @param MediaConfig $mediaConfig + * @param ContentValidator $contentValidator + * @param \Magento\Framework\Filesystem $filesystem + * @param EntryResolver $entryResolver + * @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryDataBuilder $entryBuilder + * @param \Magento\Catalog\Model\Resource\Product\Attribute\Backend\Media $mediaGallery + */ + public function __construct( + \Magento\Framework\StoreManagerInterface $storeManager, + \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, + \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository, + MediaConfig $mediaConfig, + \Magento\Catalog\Model\Product\Gallery\ContentValidator $contentValidator, + \Magento\Framework\Filesystem $filesystem, + EntryResolver $entryResolver, + \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryDataBuilder $entryBuilder, + \Magento\Catalog\Model\Resource\Product\Attribute\Backend\Media $mediaGallery + ) { + $this->productRepository = $productRepository; + $this->storeManager = $storeManager; + $this->attributeRepository = $attributeRepository; + $this->mediaConfig = $mediaConfig; + $this->contentValidator = $contentValidator; + $this->filesystem = $filesystem; + $this->entryResolver = $entryResolver; + $this->entryBuilder = $entryBuilder; + $this->mediaGallery = $mediaGallery; + } + + /** + * Retrieve backend model of product media gallery attribute + * + * @param Product $product + * @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend + * @throws StateException + */ + protected function getGalleryAttributeBackend(Product $product) + { + $attributes = $product->getTypeInstance()->getSetAttributes($product); + if (!isset($attributes['media_gallery']) + || !($attributes['media_gallery'] instanceof \Magento\Eav\Model\Entity\Attribute\AbstractAttribute) + ) { + throw new StateException('Requested product does not support images.'); + } + /** @var $galleryAttribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */ + $galleryAttribute = $attributes['media_gallery']; + return $galleryAttribute->getBackend(); + } + + /** + * Retrieve assoc array that contains media attribute values of the given product + * + * @param Product $product + * @return array + */ + protected function getMediaAttributeValues(Product $product) + { + $mediaAttributeCodes = array_keys($product->getMediaAttributes()); + $mediaAttributeValues = array(); + foreach ($mediaAttributeCodes as $attributeCode) { + $mediaAttributeValues[$attributeCode] = $product->getData($attributeCode); + } + return $mediaAttributeValues; + } + + /** + * {@inheritdoc} + */ + public function create( + $productSku, + ProductAttributeMediaGalleryEntryInterface $entry, + ContentInterface $entryContent, + $storeId = 0 + ) { + try { + $this->storeManager->getStore($storeId); + } catch (\Exception $exception) { + throw new NoSuchEntityException('There is no store with provided ID.'); + } + if (!$this->contentValidator->isValid($entryContent)) { + throw new InputException('The image content is not valid.'); + } + $product = $this->productRepository->get($productSku); + + $fileContent = @base64_decode($entryContent->getEntryData(), true); + $mediaTmpPath = $this->mediaConfig->getBaseTmpMediaPath(); + $mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); + $mediaDirectory->create($mediaTmpPath); + $fileName = $entryContent->getName() . '.' . $this->mimeTypeExtensionMap[$entryContent->getMimeType()]; + $relativeFilePath = $mediaTmpPath . DIRECTORY_SEPARATOR . $fileName; + $absoluteFilePath = $mediaDirectory->getAbsolutePath($relativeFilePath); + $mediaDirectory->writeFile($relativeFilePath, $fileContent); + + /** @var $productMediaGallery \Magento\Catalog\Model\Product\Attribute\Backend\Media */ + $productMediaGallery = $this->getGalleryAttributeBackend($product); + $imageFileUri = $productMediaGallery->addImage( + $product, + $absoluteFilePath, + $entry->getTypes(), + true, + $entry->getIsDisabled() + ); + // Update additional fields that are still empty after addImage call + $productMediaGallery->updateImage($product, $imageFileUri, array( + 'label' => $entry->getLabel(), + 'position' => $entry->getPosition(), + 'disabled' => $entry->getIsDisabled(), + )); + $product->setStoreId($storeId); + + try { + $this->productRepository->save($product); + } catch (\Exception $e) { + throw new StateException('Cannot save product.'); + } + // Remove all temporary files + $mediaDirectory->delete($relativeFilePath); + // File could change its name during the move from tmp dir + return $this->entryResolver->getEntryIdByFilePath( + $product, + $productMediaGallery->getRenamedImage($imageFileUri) + ); + } + + /** + * {@inheritdoc} + */ + public function update($productSku, ProductAttributeMediaGalleryEntryInterface $entry, $storeId = 0) + { + try { + $this->storeManager->getStore($storeId); + } catch (\Exception $exception) { + throw new NoSuchEntityException('There is no store with provided ID.'); + } + $product = $this->productRepository->get($productSku); + /** @var $productMediaGallery \Magento\Catalog\Model\Product\Attribute\Backend\Media */ + $productMediaGallery = $this->getGalleryAttributeBackend($product); + $filePath = $this->entryResolver->getEntryFilePathById($product, $entry->getId()); + if (is_null($filePath)) { + throw new NoSuchEntityException('There is no image with provided ID.'); + } + + $productMediaGallery->updateImage($product, $filePath, array( + 'label' => $entry->getLabel(), + 'position' => $entry->getPosition(), + 'disabled' => $entry->getIsDisabled(), + )); + $productMediaGallery->clearMediaAttribute($product, array_keys($product->getMediaAttributes())); + $productMediaGallery->setMediaAttribute($product, $entry->getTypes(), $filePath); + $product->setStoreId($storeId); + + try { + $this->productRepository->save($product); + } catch (\Exception $exception) { + throw new StateException('Cannot save product.'); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function remove($productSku, $entryId) + { + $product = $this->productRepository->get($productSku); + /** @var $productMediaGallery \Magento\Catalog\Model\Product\Attribute\Backend\Media */ + $productMediaGallery = $this->getGalleryAttributeBackend($product); + $filePath = $this->entryResolver->getEntryFilePathById($product, $entryId); + if (is_null($filePath)) { + throw new NoSuchEntityException('There is no image with provided ID.'); + } + + $productMediaGallery->removeImage($product, $filePath); + $this->productRepository->save($product); + return true; + } + + /** + * {@inheritdoc} + */ + public function get($productSku, $imageId) + { + try { + $product = $this->productRepository->get($productSku); + } catch (\Exception $exception) { + throw new NoSuchEntityException("Such product doesn't exist"); + } + + $output = null; + $productImages = $this->getMediaAttributeValues($product); + foreach ((array)$product->getMediaGallery('images') as $image) { + if (intval($image['value_id']) == intval($imageId)) { + $image['types'] = array_keys($productImages, $image['file']); + $output = $this->entryBuilder->populateWithArray($image)->create(); + break; + } + } + + if (is_null($output)) { + throw new NoSuchEntityException("Such image doesn't exist"); + } + return $output; + } + + /** + * {@inheritdoc} + */ + public function getList($productSku) + { + $result = array(); + /** @var \Magento\Catalog\Model\Product $product */ + $product = $this->productRepository->get($productSku); + + /** @var \Magento\Catalog\Api\Data\ProductAttributeInterface $galleryAttribute */ + $galleryAttribute = $this->attributeRepository->get('media_gallery'); + + $container = new \Magento\Framework\Object(array('attribute' => $galleryAttribute)); + $gallery = $this->mediaGallery->loadGallery($product, $container); + + $productImages = $this->getMediaAttributeValues($product); + + foreach ($gallery as $image) { + $this->entryBuilder->setId($image['value_id']); + $this->entryBuilder->setLabel($image['label_default']); + $this->entryBuilder->setTypes(array_keys($productImages, $image['file'])); + $this->entryBuilder->setIsDisabled($image['disabled_default']); + $this->entryBuilder->setPosition($image['position_default']); + $this->entryBuilder->setFile($image['file']); + $result[] = $this->entryBuilder->create(); + } + return $result; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/GroupPrice.php b/app/code/Magento/Catalog/Model/Product/GroupPrice.php new file mode 100644 index 0000000000000..44e4c6960da34 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/GroupPrice.php @@ -0,0 +1,50 @@ +getData('customer_group_id'); + } + + /** + * Retrieve price value + * + * @return float + */ + public function getValue() + { + return $this->getData('value'); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/GroupPriceManagement.php b/app/code/Magento/Catalog/Model/Product/GroupPriceManagement.php new file mode 100644 index 0000000000000..d80915c5e8dcc --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/GroupPriceManagement.php @@ -0,0 +1,174 @@ +productRepository = $productRepository; + $this->groupPriceBuilder = $groupPriceBuilder; + $this->groupRepository = $groupRepository; + $this->priceModifier = $priceModifier; + $this->config = $config; + $this->storeManager = $storeManager; + } + + /** + * {@inheritdoc} + */ + public function add($productSku, $customerGroupId, $price) + { + if (!\Zend_Validate::is($price, 'Float') || $price <= 0 || !\Zend_Validate::is($price, 'Float')) { + throw new InputException('Please provide valid data'); + } + $customerGroup = $this->groupRepository->getById($customerGroupId); + $product = $this->productRepository->get($productSku, true); + $groupPrices = $product->getData('group_price'); + $websiteIdentifier = 0; + if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) != 0) { + $websiteIdentifier = $this->storeManager->getWebsite()->getId(); + } + $found = false; + foreach ($groupPrices as &$currentPrice) { + if (intval($currentPrice['cust_group']) === $customerGroupId + && intval($currentPrice['website_id']) === intval($websiteIdentifier) + ) { + $currentPrice['price'] = $price; + $found = true; + break; + } + } + if (!$found) { + $groupPrices[] = array( + 'cust_group' => $customerGroup->getId(), + 'website_id' => $websiteIdentifier, + 'price' => $price, + ); + } + + $product->setData('group_price', $groupPrices); + $errors = $product->validate(); + if (is_array($errors) && count($errors)) { + $errorAttributeCodes = implode(', ', array_keys($errors)); + throw new InputException( + sprintf('Values of following attributes are invalid: %s', $errorAttributeCodes) + ); + } + try { + $this->productRepository->save($product); + } catch (\Exception $e) { + throw new CouldNotSaveException('Could not save group price'); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function remove($productSku, $customerGroupId) + { + $product = $this->productRepository->get($productSku, true); + $websiteIdentifier = 0; + if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) != 0) { + $websiteIdentifier = $this->storeManager->getWebsite()->getId(); + } + $this->priceModifier->removeGroupPrice($product, $customerGroupId, $websiteIdentifier); + return true; + } + + /** + * {@inheritdoc} + */ + public function getList($productSku, $websiteId = null) + { + $product = $this->productRepository->get($productSku, true); + $priceKey = 'website_price'; + if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { + $priceKey = 'price'; + } + + $prices = array(); + foreach ($product->getData('group_price') as $price) { + $this->groupPriceBuilder->populateWithArray( + array( + 'customer_group_id' => $price['all_groups'] ? 'all' : $price['cust_group'], + 'value' => $price[$priceKey], + ) + ); + $prices[] = $this->groupPriceBuilder->create(); + } + return $prices; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/LinkTypeProvider.php b/app/code/Magento/Catalog/Model/Product/LinkTypeProvider.php index 82343d5dbac71..ef1797431b7cb 100644 --- a/app/code/Magento/Catalog/Model/Product/LinkTypeProvider.php +++ b/app/code/Magento/Catalog/Model/Product/LinkTypeProvider.php @@ -25,7 +25,7 @@ */ namespace Magento\Catalog\Model\Product; -class LinkTypeProvider +class LinkTypeProvider implements \Magento\Catalog\Api\ProductLinkTypeListInterface { /** * Available product link types @@ -34,14 +34,39 @@ class LinkTypeProvider * * @var array */ - protected $_linkTypes; + protected $linkTypes; /** + * @var \Magento\Catalog\Api\Data\ProductLinkTypeDataBuilder + */ + protected $linkTypeBuilder; + + /** + * @var \Magento\Catalog\Api\Data\ProductLinkAttributeDataBuilder + */ + protected $linkAttributeBuilder; + + /** + * @var \Magento\Catalog\Model\Product\LinkFactory + */ + protected $linkFactory; + + /** + * @param \Magento\Catalog\Api\Data\ProductLinkTypeDataBuilder $linkTypeBuilder + * @param \Magento\Catalog\Api\Data\ProductLinkAttributeDataBuilder $linkAttributeBuilder + * @param LinkFactory $linkFactory * @param array $linkTypes */ - public function __construct(array $linkTypes = array()) - { - $this->_linkTypes = $linkTypes; + public function __construct( + \Magento\Catalog\Api\Data\ProductLinkTypeDataBuilder $linkTypeBuilder, + \Magento\Catalog\Api\Data\ProductLinkAttributeDataBuilder $linkAttributeBuilder, + \Magento\Catalog\Model\Product\LinkFactory $linkFactory, + array $linkTypes = array() + ) { + $this->linkTypes = $linkTypes; + $this->linkTypeBuilder = $linkTypeBuilder; + $this->linkAttributeBuilder = $linkAttributeBuilder; + $this->linkFactory = $linkFactory; } /** @@ -51,6 +76,39 @@ public function __construct(array $linkTypes = array()) */ public function getLinkTypes() { - return $this->_linkTypes; + return $this->linkTypes; + } + + /** + * {@inheritdoc} + */ + public function getItems() + { + $output = []; + foreach ($this->getLinkTypes() as $type => $typeCode) { + $output[] = $this->linkTypeBuilder + ->populateWithArray(['name' => $type, 'code' => $typeCode]) + ->create(); + } + return $output; + } + + /** + * {@inheritdoc} + */ + public function getItemAttributes($type) + { + $output = []; + $types = $this->getLinkTypes(); + $typeId = isset($types[$type]) ? $types[$type] : null; + + /** @var \Magento\Catalog\Model\Product\Link $link */ + $link = $this->linkFactory->create(['data' => ['link_type_id' => $typeId]]); + $attributes = $link->getAttributes(); + foreach ($attributes as $item) { + $data = ['code' => $item['code'], 'type' => $item['type']]; + $output[] = $this->linkAttributeBuilder->populateWithArray($data)->create(); + } + return $output; } } diff --git a/app/code/Magento/Catalog/Model/Product/Media/AttributeManagement.php b/app/code/Magento/Catalog/Model/Product/Media/AttributeManagement.php new file mode 100644 index 0000000000000..dc431da5e19c6 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Media/AttributeManagement.php @@ -0,0 +1,67 @@ +collectionFactory = $collectionFactory; + $this->storeManager = $storeManager; + } + + /** + * {@inheritdoc} + */ + public function getList($attributeSetName) + { + /** @var \Magento\Catalog\Model\Resource\Product\Attribute\Collection $collection */ + $collection = $this->collectionFactory->create(); + $collection->setAttributeSetFilterBySetName($attributeSetName, Product::ENTITY); + $collection->setFrontendInputTypeFilter('media_image'); + $collection->addStoreLabel($this->storeManager->getStore()->getId()); + + return $collection->getItems(); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Media/GalleryEntryContent.php b/app/code/Magento/Catalog/Model/Product/Media/GalleryEntryContent.php new file mode 100644 index 0000000000000..1aed3f160339d --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Media/GalleryEntryContent.php @@ -0,0 +1,53 @@ +getData(self::DATA); + } + + /** + * {@inheritdoc} + */ + public function getMimeType() + { + return $this->getData(self::MIME_TYPE); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return $this->getData(self::NAME); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Option.php b/app/code/Magento/Catalog/Model/Product/Option.php index dc3b95fb27cd7..51b419a5abb0c 100644 --- a/app/code/Magento/Catalog/Model/Product/Option.php +++ b/app/code/Magento/Catalog/Model/Product/Option.php @@ -28,6 +28,8 @@ use Magento\Catalog\Pricing\Price\BasePrice; use Magento\Framework\Model\Exception; use Magento\Framework\Model\AbstractModel; +use \Magento\Framework\Model\AbstractExtensibleModel; +use \Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface; /** * Catalog product option model @@ -35,28 +37,10 @@ * @method \Magento\Catalog\Model\Resource\Product\Option getResource() * @method int getProductId() * @method \Magento\Catalog\Model\Product\Option setProductId(int $value) - * @method string getType() - * @method \Magento\Catalog\Model\Product\Option setType(string $value) - * @method string getTitle() - * @method \Magento\Catalog\Model\Product\Option seTitle(string $value) - * @method int getIsRequire() - * @method \Magento\Catalog\Model\Product\Option setIsRequire(int $value) - * @method string getSku() - * @method \Magento\Catalog\Model\Product\Option setSku(string $value) - * @method int getMaxCharacters() - * @method \Magento\Catalog\Model\Product\Option setMaxCharacters(int $value) - * @method string getFileExtension() - * @method \Magento\Catalog\Model\Product\Option setFileExtension(string $value) - * @method int getImageSizeX() - * @method \Magento\Catalog\Model\Product\Option setImageSizeX(int $value) - * @method int getImageSizeY() - * @method \Magento\Catalog\Model\Product\Option setImageSizeY(int $value) - * @method int getSortOrder() - * @method \Magento\Catalog\Model\Product\Option setSortOrder(int $value) * * @author Magento Core Team */ -class Option extends AbstractModel +class Option extends AbstractExtensibleModel implements \Magento\Catalog\Api\Data\ProductCustomOptionInterface { const OPTION_GROUP_TEXT = 'text'; @@ -128,6 +112,7 @@ class Option extends AbstractModel /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService * @param Option\Value $productOptionValue * @param Option\Type\Factory $optionFactory * @param \Magento\Framework\Stdlib\String $string @@ -139,6 +124,7 @@ class Option extends AbstractModel public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService, Option\Value $productOptionValue, \Magento\Catalog\Model\Product\Option\Type\Factory $optionFactory, \Magento\Framework\Stdlib\String $string, @@ -151,7 +137,7 @@ public function __construct( $this->_optionFactory = $optionFactory; $this->validatorPool = $validatorPool; $this->string = $string; - parent::__construct($context, $registry, $resource, $resourceCollection, $data); + parent::__construct($context, $registry, $metadataService, $resource, $resourceCollection, $data); } /** @@ -201,7 +187,7 @@ public function getValueById($valueId) } /** - * @return Option\Value[] + * @return ProductCustomOptionValuesInterface[]|null */ public function getValues() { @@ -414,7 +400,7 @@ public function saveOptions() * @return AbstractModel * @throws \Magento\Framework\Model\Exception */ - protected function _afterSave() + public function afterSave() { $this->getValueInstance()->unsetValues(); if (is_array($this->getData('values'))) { @@ -427,7 +413,7 @@ protected function _afterSave() throw new Exception(__('Select type options required values rows.')); } - return parent::_afterSave(); + return parent::afterSave(); } /** @@ -588,4 +574,121 @@ protected function _getValidationRulesBeforeSave() { return $this->validatorPool->get($this->getType()); } + + /** + * Get product SKU + * + * @return string + */ + public function getProductSku() + { + $productSku = $this->_getData('product_sku'); + if (!$productSku) { + $productSku = $this->getProduct()->getSku(); + } + return $productSku; + } + + /** + * Get option id + * + * @return int|null + */ + public function getOptionId() + { + return $this->_getData('option_id'); + } + + + /** + * Get option title + * + * @return string + */ + public function getTitle() + { + return $this->_getData('title'); + } + + /** + * Get option type + * + * @return string + */ + public function getType() + { + return $this->_getData('type'); + } + + /** + * Get sort order + * + * @return int + */ + public function getSortOrder() + { + return $this->_getData('sort_order'); + } + + /** + * Get is require + * + * @return bool + */ + public function getIsRequire() + { + return $this->_getData('is_require'); + } + + /** + * Get price type + * + * @return string|null + */ + public function getPriceType() + { + return $this->_getData('price_type'); + } + + /** + * Get Sku + * + * @return string|null + */ + public function getSku() + { + return $this->_getData('sku'); + } + + /** + * @return string|null + */ + public function getFileExtension() + { + return $this->getData('file_extension'); + } + + /** + * @return int|null + */ + public function getMaxCharacters() + { + return $this->getData('max_characters'); + } + + /** + * @return int|null + */ + public function getImageSizeX() + { + return $this->getData('image_size_x'); + } + + /** + * @return int|null + */ + public function getImageSizeY() + { + return $this->getData('image_size_y'); + } } diff --git a/app/code/Magento/Catalog/Model/Product/Option/Converter.php b/app/code/Magento/Catalog/Model/Product/Option/Converter.php new file mode 100644 index 0000000000000..6933e288548ab --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Option/Converter.php @@ -0,0 +1,63 @@ +productRepository = $productRepository; + } + + + /** + * Convert option data to array + * @param \Magento\Catalog\Api\Data\ProductCustomOptionInterface $option + * @return array + */ + public function toArray(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $option) + { + $optionData = $option->getData(); + $values = $option->getData('values'); + $valuesData = []; + if (!empty($values)) { + foreach ($values as $key => $value) { + $valuesData[$key] = $value->getData(); + } + } + $optionData['values'] = $valuesData; + return $optionData; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Option/Repository.php b/app/code/Magento/Catalog/Model/Product/Option/Repository.php new file mode 100644 index 0000000000000..ccdde906022a6 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Option/Repository.php @@ -0,0 +1,186 @@ +productRepository = $productRepository; + $this->optionResource = $optionResource; + $this->converter = $converter; + } + + /** + * {@inheritdoc} + */ + public function getList($productSku) + { + $product = $this->productRepository->get($productSku, true); + return $product->getOptions(); + } + + /** + * {@inheritdoc} + */ + public function get($productSku, $optionId) + { + $product = $this->productRepository->get($productSku); + $option = $product->getOptionById($optionId); + if (is_null($option)) { + throw NoSuchEntityException::singleField('optionId', $optionId); + } + return $option; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $entity) + { + $this->optionResource->delete($entity); + return true; + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $option) + { + $productSku = $option->getProductSku(); + $product = $this->productRepository->get($productSku, true); + $optionData = $this->converter->toArray($option); + if ($option->getOptionId()) { + if (!$product->getOptionById($option->getOptionId())) { + throw new NoSuchEntityException(); + } + $originalValues = $product->getOptionById($option->getOptionId())->getValues(); + if (!empty($optionData['values'])) { + $optionData['values'] = $this->markRemovedValues($optionData['values'], $originalValues); + } + } + + unset($optionData['product_sku']); + + $product->setProductOptions([$optionData]); + $existingOptions = $product->getOptions(); + try { + $this->productRepository->save($product, true); + } catch (\Exception $e) { + throw new CouldNotSaveException('Could not save product option'); + } + + $product = $this->productRepository->get($productSku, true); + if (!$option->getOptionId()) { + $currentOptions = $product->getOptions(); + + $newID = array_diff(array_keys($currentOptions), array_keys($existingOptions)); + if (empty($newID)) { + throw new CouldNotSaveException('Could not save product option'); + } + $newID = current($newID); + } else { + $newID = $option->getOptionId(); + } + $option = $this->get($productSku, $newID); + return $option; + } + + /** + * {@inheritdoc} + */ + public function deleteByIdentifier($productSku, $optionId) + { + $product = $this->productRepository->get($productSku, true); + $options = $product->getOptions(); + $option = $product->getOptionById($optionId); + if (is_null($option)) { + throw NoSuchEntityException::singleField('optionId', $optionId); + } + unset($options[$optionId]); + try { + $this->delete($option); + if (empty($options)) { + $this->productRepository->save($product); + } + } catch (\Exception $e) { + throw new CouldNotSaveException('Could not remove custom option'); + } + return true; + } + + /** + * Mark original values for removal if they are absent among new values + * + * @param $newValues array + * @param $originalValues \Magento\Catalog\Model\Product\Option\Value[] + * @return array + */ + protected function markRemovedValues($newValues, $originalValues) + { + $existingValuesIds = []; + + foreach ($newValues as $newValue) { + if (array_key_exists('option_type_id', $newValue)) { + $existingValuesIds[] = $newValue['option_type_id']; + } + } + /** @var $originalValue \Magento\Catalog\Model\Product\Option\Value */ + foreach ($originalValues as $originalValue) { + if (!in_array($originalValue->getData('option_type_id'), $existingValuesIds)) { + $originalValue->setData('is_delete', 1); + $newValues[] = $originalValue->getData(); + } + } + + return $newValues; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type.php b/app/code/Magento/Catalog/Model/Product/Option/Type.php new file mode 100644 index 0000000000000..d0552f8cf02bb --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Option/Type.php @@ -0,0 +1,59 @@ +getData('label'); + } + + /** + * Get option type code + * + * @return string + */ + public function getCode() + { + return $this->getData('code'); + } + + /** + * Get option type group + * + * @return string + */ + public function getGroup() + { + return $this->getData('group'); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index 092edb9b2936a..30359358e38b4 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -45,47 +45,11 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType */ protected $_formattedOptionValue = null; - /** - * @var \Magento\Framework\Filesystem - */ - protected $_filesystem; - /** * @var \Magento\Framework\Filesystem\Directory\ReadInterface */ protected $_rootDirectory; - /** - * @var \Magento\Framework\Filesystem\Directory\WriteInterface - */ - protected $_mediaDirectory; - - /** - * Relative path for main destination folder - * - * @var string - */ - protected $_path = '/custom_options'; - - /** - * Relative path for quote folder - * - * @var string - */ - protected $_quotePath = '/custom_options/quote'; - - /** - * Relative path for order folder - * - * @var string - */ - protected $_orderPath = '/custom_options/order'; - - /** - * @var \Magento\Framework\File\Size - */ - protected $_fileSize; - /** * Core file storage database * @@ -112,6 +76,16 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType */ protected $_itemOptionFactory; + /** + * @var File\ValidatorInfo + */ + protected $validatorInfo; + + /** + * @var File\ValidatorFile + */ + protected $validatorFile; + /** * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig @@ -119,30 +93,28 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder * @param \Magento\Framework\Escaper $escaper * @param \Magento\Core\Helper\File\Storage\Database $coreFileStorageDatabase - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\File\Size $fileSize + * @param File\ValidatorInfo $validatorInfo + * @param File\ValidatorFile $validatorFile * @param array $data + * @throws \Magento\Framework\Filesystem\FilesystemException */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Sales\Model\Quote\Item\OptionFactory $itemOptionFactory, + \Magento\Core\Helper\File\Storage\Database $coreFileStorageDatabase, + \Magento\Catalog\Model\Product\Option\Type\File\ValidatorInfo $validatorInfo, + \Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile $validatorFile, \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder, \Magento\Framework\Escaper $escaper, - \Magento\Core\Helper\File\Storage\Database $coreFileStorageDatabase, - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\File\Size $fileSize, array $data = array() ) { $this->_itemOptionFactory = $itemOptionFactory; $this->_urlBuilder = $urlBuilder; $this->_escaper = $escaper; $this->_coreFileStorageDatabase = $coreFileStorageDatabase; - $this->_filesystem = $filesystem; - $this->_rootDirectory = $this->_filesystem->getDirectoryRead(DirectoryList::ROOT); - $this->_mediaDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA); - $this->_fileSize = $fileSize; - $this->_data = $data; + $this->validatorInfo = $validatorInfo; + $this->validatorFile = $validatorFile; parent::__construct($checkoutSession, $scopeConfig, $data); } @@ -250,22 +222,42 @@ public function validateUserValue($values) $fileInfo = $this->_getCurrentConfigFileInfo(); } if ($fileInfo !== null) { - if (is_array($fileInfo) && $this->_validateFile($fileInfo)) { - $value = $fileInfo; - } else { - $value = null; + try { + $value = $this->validatorInfo->setUseQuotePath($this->getUseQuotePath()) + ->validate($fileInfo, $option) ? $fileInfo : null; + $this->setUserValue($value); + return $this; + } catch (Exception $exception) { + $this->setIsValid(false); + throw $exception; } - $this->setUserValue($value); - return $this; } // Process new uploaded file try { - $this->_validateUploadedFile(); + $value = $this->validatorFile->setProduct($this->getProduct()) + ->validate($this->_getProcessingParams(), $option); + $this->setUserValue($value); + } catch (File\LargeSizeException $largeSizeException) { + $this->setIsValid(false); + throw new Exception($largeSizeException->getMessage()); + } catch (File\OptionRequiredException $e) { + switch ($this->getProcessMode()) { + case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL: + throw new Exception(__('Please specify the product\'s required option(s).')); + break; + default: + $this->setUserValue(null); + break; + } + } catch (File\RunValidationException $e) { + $this->setUserValue(null); + } catch (File\Exception $e) { + $this->setIsValid(false); + throw new Exception($e->getMessage()); } catch (\Exception $e) { if ($this->getSkipCheckRequiredOption()) { $this->setUserValue(null); - return $this; } else { throw new Exception($e->getMessage()); } @@ -273,295 +265,6 @@ public function validateUserValue($values) return $this; } - /** - * Validate uploaded file - * - * @return $this - * @throws \Magento\Framework\Model\Exception - */ - protected function _validateUploadedFile() - { - $option = $this->getOption(); - $processingParams = $this->_getProcessingParams(); - - /** - * Upload init - */ - $upload = new \Zend_File_Transfer_Adapter_Http(); - $file = $processingParams->getFilesPrefix() . 'options_' . $option->getId() . '_file'; - $maxFileSize = $this->getFileSizeService()->getMaxFileSize(); - try { - $runValidation = $option->getIsRequire() || $upload->isUploaded($file); - if (!$runValidation) { - $this->setUserValue(null); - return $this; - } - - $fileInfo = $upload->getFileInfo($file); - $fileInfo = $fileInfo[$file]; - $fileInfo['title'] = $fileInfo['name']; - } catch (\Exception $e) { - // when file exceeds the upload_max_filesize, $_FILES is empty - if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $maxFileSize) { - $this->setIsValid(false); - $value = $this->getFileSizeService()->getMaxFileSizeInMb(); - throw new Exception(__("The file you uploaded is larger than %1 Megabytes allowed by server", $value)); - } else { - switch ($this->getProcessMode()) { - case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL: - throw new Exception(__('Please specify the product\'s required option(s).')); - break; - default: - $this->setUserValue(null); - break; - } - return $this; - } - } - - /** - * Option Validations - */ - - // Image dimensions - $_dimentions = array(); - if ($option->getImageSizeX() > 0) { - $_dimentions['maxwidth'] = $option->getImageSizeX(); - } - if ($option->getImageSizeY() > 0) { - $_dimentions['maxheight'] = $option->getImageSizeY(); - } - if (count($_dimentions) > 0) { - $upload->addValidator('ImageSize', false, $_dimentions); - } - - // File extension - $_allowed = $this->_parseExtensionsString($option->getFileExtension()); - if ($_allowed !== null) { - $upload->addValidator('Extension', false, $_allowed); - } else { - $_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions')); - if ($_forbidden !== null) { - $upload->addValidator('ExcludeExtension', false, $_forbidden); - } - } - - // Maximum filesize - $upload->addValidator('FilesSize', false, array('max' => $maxFileSize)); - - /** - * Upload process - */ - - $this->_initFilesystem(); - - if ($upload->isUploaded($file) && $upload->isValid($file)) { - - $extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION); - - $fileName = \Magento\Core\Model\File\Uploader::getCorrectFileName($fileInfo['name']); - $dispersion = \Magento\Core\Model\File\Uploader::getDispretionPath($fileName); - - $filePath = $dispersion; - - $tmpDirectory = $this->_filesystem->getDirectoryRead(DirectoryList::SYS_TMP); - $fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name']))); - $filePath .= '/' . $fileHash . '.' . $extension; - $fileFullPath = $this->_mediaDirectory->getAbsolutePath($this->_quotePath . $filePath); - - $upload->addFilter('Rename', array('target' => $fileFullPath, 'overwrite' => true)); - - $this->getProduct()->getTypeInstance()->addFileQueue( - array( - 'operation' => 'receive_uploaded_file', - 'src_name' => $file, - 'dst_name' => $fileFullPath, - 'uploader' => $upload, - 'option' => $this - ) - ); - - $_width = 0; - $_height = 0; - - if ($tmpDirectory->isReadable($tmpDirectory->getRelativePath($fileInfo['tmp_name']))) { - $_imageSize = getimagesize($fileInfo['tmp_name']); - if ($_imageSize) { - $_width = $_imageSize[0]; - $_height = $_imageSize[1]; - } - } - $uri = $this->_filesystem->getUri(DirectoryList::MEDIA); - $this->setUserValue( - array( - 'type' => $fileInfo['type'], - 'title' => $fileInfo['name'], - 'quote_path' => $uri . $this->_quotePath . $filePath, - 'order_path' => $uri . $this->_orderPath . $filePath, - 'fullpath' => $fileFullPath, - 'size' => $fileInfo['size'], - 'width' => $_width, - 'height' => $_height, - 'secret_key' => substr($fileHash, 0, 20) - ) - ); - } elseif ($upload->getErrors()) { - $errors = $this->_getValidatorErrors($upload->getErrors(), $fileInfo); - - if (count($errors) > 0) { - $this->setIsValid(false); - throw new Exception(implode("\n", $errors)); - } - } else { - $this->setIsValid(false); - throw new Exception(__('Please specify the product\'s required option(s).')); - } - return $this; - } - - /** - * Validate file - * - * @param array $optionValue - * @return bool|void - * @throws \Magento\Framework\Model\Exception - */ - protected function _validateFile($optionValue) - { - $option = $this->getOption(); - /** - * @see \Magento\Catalog\Model\Product\Option\Type\File::_validateUploadFile() - * There setUserValue() sets correct fileFullPath only for - * quote_path. So we must form both full paths manually and - * check them. - */ - $checkPaths = array(); - if (isset($optionValue['quote_path'])) { - $checkPaths[] = $optionValue['quote_path']; - } - if (isset($optionValue['order_path']) && !$this->getUseQuotePath()) { - $checkPaths[] = $optionValue['order_path']; - } - $fileFullPath = null; - $fileRelativePath = null; - foreach ($checkPaths as $path) { - if (!$this->_rootDirectory->isFile($path)) { - if (!$this->_coreFileStorageDatabase->saveFileToFilesystem($fileFullPath)) { - continue; - } - } - $fileFullPath = $this->_rootDirectory->getAbsolutePath($path); - $fileRelativePath = $path; - break; - } - - if ($fileFullPath === null) { - return false; - } - - $validatorChain = new \Zend_Validate(); - - $_dimentions = array(); - - if ($option->getImageSizeX() > 0) { - $_dimentions['maxwidth'] = $option->getImageSizeX(); - } - if ($option->getImageSizeY() > 0) { - $_dimentions['maxheight'] = $option->getImageSizeY(); - } - if (count($_dimentions) > 0 && !$this->_isImage($fileFullPath)) { - return false; - } - if (count($_dimentions) > 0) { - $validatorChain->addValidator(new \Zend_Validate_File_ImageSize($_dimentions)); - } - - // File extension - $_allowed = $this->_parseExtensionsString($option->getFileExtension()); - if ($_allowed !== null) { - $validatorChain->addValidator(new \Zend_Validate_File_Extension($_allowed)); - } else { - $_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions')); - if ($_forbidden !== null) { - $validatorChain->addValidator(new \Zend_Validate_File_ExcludeExtension($_forbidden)); - } - } - - // Maximum file size - $maxFileSize = $this->getFileSizeService()->getMaxFileSize(); - $validatorChain->addValidator(new \Zend_Validate_File_FilesSize(array('max' => $maxFileSize))); - - - if ($validatorChain->isValid($fileFullPath)) { - $ok = $this->_rootDirectory->isReadable( - $fileRelativePath - ) && isset( - $optionValue['secret_key'] - ) && substr( - md5($this->_rootDirectory->readFile($fileRelativePath)), - 0, - 20 - ) == $optionValue['secret_key']; - - return $ok; - } elseif ($validatorChain->getErrors()) { - $errors = $this->_getValidatorErrors($validatorChain->getErrors(), $optionValue); - - if (count($errors) > 0) { - $this->setIsValid(false); - throw new Exception(implode("\n", $errors)); - } - } else { - $this->setIsValid(false); - throw new Exception(__('Please specify the product\'s required option(s).')); - } - } - - /** - * Get Error messages for validator Errors - * - * @param string[] $errors Array of validation failure message codes @see \Zend_Validate::getErrors() - * @param array $fileInfo File info - * @return string[] Array of error messages - */ - protected function _getValidatorErrors($errors, $fileInfo) - { - $option = $this->getOption(); - $result = array(); - foreach ($errors as $errorCode) { - if ($errorCode == \Zend_Validate_File_ExcludeExtension::FALSE_EXTENSION) { - $result[] = __( - "The file '%1' for '%2' has an invalid extension.", - $fileInfo['title'], - $option->getTitle() - ); - } elseif ($errorCode == \Zend_Validate_File_Extension::FALSE_EXTENSION) { - $result[] = __( - "The file '%1' for '%2' has an invalid extension.", - $fileInfo['title'], - $option->getTitle() - ); - } elseif ($errorCode == \Zend_Validate_File_ImageSize::WIDTH_TOO_BIG || - $errorCode == \Zend_Validate_File_ImageSize::HEIGHT_TOO_BIG - ) { - $result[] = __( - "Maximum allowed image size for '%1' is %2x%3 px.", - $option->getTitle(), - $option->getImageSizeX(), - $option->getImageSizeY() - ); - } elseif ($errorCode == \Zend_Validate_File_FilesSize::TOO_BIG) { - $maxFileSize = $this->getFileSizeService()->getMaxFileSizeInMb(); - $result[] = __( - "The file '%1' you uploaded is larger than the %2 megabytes allowed by our server.", - $fileInfo['title'], - $maxFileSize - ); - } - } - return $result; - } - /** * Prepare option value for cart * @@ -641,18 +344,7 @@ protected function _getOptionHtml($optionValue) { $value = $this->_unserializeValue($optionValue); try { - if (isset( - $value - ) && isset( - $value['width'] - ) && isset( - $value['height'] - ) && $value['width'] > 0 && $value['height'] > 0 - ) { - $sizes = $value['width'] . ' x ' . $value['height'] . ' ' . __('px.'); - } else { - $sizes = ''; - } + $sizes = $this->prepareSize($value); $urlRoute = !empty($value['url']['route']) ? $value['url']['route'] : ''; $urlParams = !empty($value['url']['params']) ? $value['url']['params'] : ''; @@ -798,24 +490,6 @@ public function setCustomOptionDownloadUrl($url) return $this; } - /** - * Directory structure initializing - * - * @return void - */ - protected function _initFilesystem() - { - $this->_mediaDirectory->create($this->_path); - $this->_mediaDirectory->create($this->_quotePath); - $this->_mediaDirectory->create($this->_orderPath); - - // Directory listing and hotlink secure - $path = $this->_path . '/.htaccess'; - if (!$this->_mediaDirectory->isFile($path)) { - $this->_mediaDirectory->writeFile($path, "Order deny,allow\nDeny from all"); - } - } - /** * Return URL for option file download * @@ -829,51 +503,16 @@ protected function _getOptionDownloadUrl($route, $params) } /** - * Parse file extensions string with various separators - * - * @param string $extensions String to parse - * @return array|null - */ - protected function _parseExtensionsString($extensions) - { - preg_match_all('/[a-z0-9]+/si', strtolower($extensions), $matches); - if (isset($matches[0]) && is_array($matches[0]) && count($matches[0]) > 0) { - return $matches[0]; - } - return null; - } - - /** - * Simple check if file is image - * - * @param array|string $fileInfo - either file data from \Zend_File_Transfer or file path - * @return boolean + * @param array $value + * @return string */ - protected function _isImage($fileInfo) + protected function prepareSize($value) { - // Maybe array with file info came in - if (is_array($fileInfo)) { - return strstr($fileInfo['type'], 'image/'); - } - - // File path came in - check the physical file - if (!$this->_rootDirectory->isReadable($this->_rootDirectory->getRelativePath($fileInfo))) { - return false; + $sizes = ''; + if (!empty($value['width']) && !empty($value['height']) && $value['width'] > 0 && $value['height'] > 0) { + $sizes = $value['width'] . ' x ' . $value['height'] . ' ' . __('px.'); + return array($value, $sizes); } - $imageInfo = getimagesize($fileInfo); - if (!$imageInfo) { - return false; - } - return true; - } - - /** - * Get file storage helper - * - * @return \Magento\Framework\File\Size - */ - public function getFileSizeService() - { - return $this->_fileSize; + return $sizes; } } diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File/Exception.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File/Exception.php new file mode 100644 index 0000000000000..914b6f1e13f30 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File/Exception.php @@ -0,0 +1,29 @@ +scopeConfig = $scopeConfig; + $this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT); + $this->fileSize = $fileSize; + } + + /** + * Store Config value + * + * @param string $key Config value key + * @return string + */ + protected function getConfigData($key) + { + return $this->scopeConfig->getValue( + 'catalog/custom_options/' . $key, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + + /** + * Get Error messages for validator Errors + * + * @param string[] $errors Array of validation failure message codes @see \Zend_Validate::getErrors() + * @param array $fileInfo File info + * @param \Magento\Catalog\Model\Product\Option $option + * @return string[] Array of error messages + * @see \Magento\Catalog\Model\Product\Option\Type\File::_getValidatorErrors + */ + protected function getValidatorErrors($errors, $fileInfo, $option) + { + $result = array(); + foreach ($errors as $errorCode) { + switch($errorCode) { + case \Zend_Validate_File_ExcludeExtension::FALSE_EXTENSION: + $result[] = __( + "The file '%1' for '%2' has an invalid extension.", + $fileInfo['title'], + $option->getTitle() + ); + break; + case \Zend_Validate_File_Extension::FALSE_EXTENSION: + $result[] = __( + "The file '%1' for '%2' has an invalid extension.", + $fileInfo['title'], + $option->getTitle() + ); + break; + case \Zend_Validate_File_ImageSize::WIDTH_TOO_BIG: + case \Zend_Validate_File_ImageSize::HEIGHT_TOO_BIG: + $result[] = __( + "Maximum allowed image size for '%1' is %2x%3 px.", + $option->getTitle(), + $option->getImageSizeX(), + $option->getImageSizeY() + ); + break; + case \Zend_Validate_File_FilesSize::TOO_BIG: + $result[] = __( + "The file '%1' you uploaded is larger than the %2 megabytes allowed by our server.", + $fileInfo['title'], + $this->fileSize->getMaxFileSizeInMb() + ); + break; + } + } + return $result; + } + + /** + * Parse file extensions string with various separators + * + * @param string $extensions String to parse + * @return array|null + * @see \Magento\Catalog\Model\Product\Option\Type\File::_parseExtensionsString + */ + protected function parseExtensionsString($extensions) + { + if (preg_match_all('/(?[a-z0-9]+)/si', strtolower($extensions), $matches)) { + return $matches['extension'] ?: null; + } + return null; + } + + /** + * @param \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object + * @param \Magento\Catalog\Model\Product\Option $option + * @param array $fileFullPath + * @return \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object + * @throws NotImageException + */ + protected function buildImageValidator($object, $option, $fileFullPath = null) + { + $dimensions = array(); + + if ($option->getImageSizeX() > 0) { + $dimensions['maxwidth'] = $option->getImageSizeX(); + } + if ($option->getImageSizeY() > 0) { + $dimensions['maxheight'] = $option->getImageSizeY(); + } + if (count($dimensions) > 0) { + if (!is_null($fileFullPath) && !$this->isImage($fileFullPath)) { + throw new NotImageException(); + } + $object->addValidator(new \Zend_Validate_File_ImageSize($dimensions)); + } + + // File extension + $allowed = $this->parseExtensionsString($option->getFileExtension()); + if ($allowed !== null) { + $object->addValidator(new \Zend_Validate_File_Extension($allowed)); + } else { + $forbidden = $this->parseExtensionsString($this->getConfigData('forbidden_extensions')); + if ($forbidden !== null) { + $object->addValidator(new \Zend_Validate_File_ExcludeExtension($forbidden)); + } + } + + $object->addValidator( + new \Zend_Validate_File_FilesSize(array('max' => $this->fileSize->getMaxFileSize())) + ); + return $object; + } + + /** + * Simple check if file is image + * + * @param array|string $fileInfo - either file data from \Zend_File_Transfer or file path + * @return boolean + * @see \Magento\Catalog\Model\Product\Option\Type\File::_isImage + */ + protected function isImage($fileInfo) + { + // Maybe array with file info came in + if (is_array($fileInfo)) { + return strstr($fileInfo['type'], 'image/'); + } + + // File path came in - check the physical file + if (!$this->rootDirectory->isReadable($this->rootDirectory->getRelativePath($fileInfo))) { + return false; + } + $imageInfo = getimagesize($fileInfo); + if (!$imageInfo) { + return false; + } + return true; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php new file mode 100644 index 0000000000000..e8c5818d9ae16 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php @@ -0,0 +1,236 @@ +mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); + $this->filesystem = $filesystem; + $this->httpFactory = $httpFactory; + parent::__construct($scopeConfig, $filesystem, $fileSize); + } + + /** + * @param Product $product + * @return $this + */ + public function setProduct(Product $product) + { + $this->product = $product; + return $this; + } + + /** + * @param \Magento\Framework\Object $processingParams + * @param \Magento\Catalog\Model\Product\Option $option + * @return array + * @throws \Magento\Framework\Model\Exception + * @throws \Zend_File_Transfer_Exception + */ + public function validate($processingParams, $option) + { + $upload = $this->httpFactory->create(); + $file = $processingParams->getFilesPrefix() . 'options_' . $option->getId() . '_file'; + try { + $runValidation = $option->getIsRequire() || $upload->isUploaded($file); + if (!$runValidation) { + throw new RunValidationException(); + } + + $fileInfo = $upload->getFileInfo($file)[$file]; + $fileInfo['title'] = $fileInfo['name']; + } catch (RunValidationException $r) { + throw $r; + } catch (\Exception $e) { + // when file exceeds the upload_max_filesize, $_FILES is empty + if ($this->validateContentLength()) { + $value = $this->fileSize->getMaxFileSizeInMb(); + throw new LargeSizeException( + __("The file you uploaded is larger than %1 Megabytes allowed by server", $value) + ); + } else { + throw new OptionRequiredException(); + } + } + + /** + * Option Validations + */ + $upload = $this->buildImageValidator($upload, $option); + + /** + * Upload process + */ + $this->initFilesystem(); + $userValue = array(); + + if ($upload->isUploaded($file) && $upload->isValid($file)) { + + $extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION); + + $fileName = \Magento\Core\Model\File\Uploader::getCorrectFileName($fileInfo['name']); + $dispersion = \Magento\Core\Model\File\Uploader::getDispretionPath($fileName); + + $filePath = $dispersion; + + $tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP); + $fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name']))); + $filePath .= '/' . $fileHash . '.' . $extension; + $fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath); + + $upload->addFilter(new \Zend_Filter_File_Rename(array('target' => $fileFullPath, 'overwrite' => true))); + + // TODO: I don't know how change this + if (!is_null($this->product)) { + $this->product->getTypeInstance()->addFileQueue( + array( + 'operation' => 'receive_uploaded_file', + 'src_name' => $file, + 'dst_name' => $fileFullPath, + 'uploader' => $upload, + 'option' => $this + ) + ); + } + + $_width = 0; + $_height = 0; + + if ($tmpDirectory->isReadable($tmpDirectory->getRelativePath($fileInfo['tmp_name']))) { + $imageSize = getimagesize($fileInfo['tmp_name']); + if ($imageSize) { + $_width = $imageSize[0]; + $_height = $imageSize[1]; + } + } + $uri = $this->filesystem->getUri(DirectoryList::MEDIA); + $userValue = array( + 'type' => $fileInfo['type'], + 'title' => $fileInfo['name'], + 'quote_path' => $uri . $this->quotePath . $filePath, + 'order_path' => $uri . $this->orderPath . $filePath, + 'fullpath' => $fileFullPath, + 'size' => $fileInfo['size'], + 'width' => $_width, + 'height' => $_height, + 'secret_key' => substr($fileHash, 0, 20) + ); + } elseif ($upload->getErrors()) { + $errors = $this->getValidatorErrors($upload->getErrors(), $fileInfo, $option); + + if (count($errors) > 0) { + throw new Exception(implode("\n", $errors)); + } + } else { + throw new Exception(__('Please specify the product\'s required option(s).')); + } + return $userValue; + } + + /** + * Directory structure initializing + * + * @return void + * @see \Magento\Catalog\Model\Product\Option\Type\File::_initFilesystem + */ + protected function initFilesystem() + { + $this->mediaDirectory->create($this->path); + $this->mediaDirectory->create($this->quotePath); + $this->mediaDirectory->create($this->orderPath); + + // Directory listing and hotlink secure + $path = $this->path . '/.htaccess'; + if (!$this->mediaDirectory->isFile($path)) { + $this->mediaDirectory->writeFile($path, "Order deny,allow\nDeny from all"); + } + } + + /** + * @return bool + * @todo need correctly name + */ + protected function validateContentLength() + { + return isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $this->fileSize->getMaxFileSize(); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorInfo.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorInfo.php new file mode 100644 index 0000000000000..095fe67f4d459 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorInfo.php @@ -0,0 +1,168 @@ +coreFileStorageDatabase = $coreFileStorageDatabase; + $this->validateFactory = $validateFactory; + parent::__construct($scopeConfig, $filesystem, $fileSize); + } + + /** + * @param mixed $useQuotePath + * @return $this + */ + public function setUseQuotePath($useQuotePath) + { + $this->useQuotePath = $useQuotePath; + return $this; + } + + /** + * @param array $optionValue + * @param \Magento\Catalog\Model\Product\Option $option + * @return bool + * @throws \Magento\Framework\Model\Exception + */ + public function validate($optionValue, $option) + { + if (!is_array($optionValue)) { + return false; + } + + $this->fileFullPath = null; + $this->fileRelativePath = null; + $this->initFilePath($optionValue); + + if ($this->fileFullPath === null) { + return false; + } + + $validatorChain = $this->validateFactory->create(); + try { + $validatorChain = $this->buildImageValidator($validatorChain, $option, $this->fileFullPath); + } catch (NotImageException $notImage) { + return false; + } + + $result = false; + if ($validatorChain->isValid($this->fileFullPath)) { + $result = $this->rootDirectory->isReadable($this->fileRelativePath) + && isset($optionValue['secret_key']) + && $this->buildSecretKey($this->fileRelativePath) == $optionValue['secret_key']; + + } elseif ($validatorChain->getErrors()) { + $errors = $this->getValidatorErrors($validatorChain->getErrors(), $optionValue, $option); + + if (count($errors) > 0) { + throw new \Magento\Framework\Model\Exception(implode("\n", $errors)); + } + } else { + throw new \Magento\Framework\Model\Exception(__('Please specify the product\'s required option(s).')); + } + return $result; + } + + /** + * @param string $fileRelativePath + * @return string + */ + protected function buildSecretKey($fileRelativePath) + { + return substr(md5($this->rootDirectory->readFile($fileRelativePath)), 0, 20); + } + + /** + * @param array $optionValue + * @return void + */ + protected function initFilePath($optionValue) + { + /** + * @see \Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::validate + * There setUserValue() sets correct fileFullPath only for + * quote_path. So we must form both full paths manually and + * check them. + */ + $checkPaths = array(); + if (isset($optionValue['quote_path'])) { + $checkPaths[] = $optionValue['quote_path']; + } + if (isset($optionValue['order_path']) && !$this->useQuotePath) { + $checkPaths[] = $optionValue['order_path']; + } + + foreach ($checkPaths as $path) { + if (!$this->rootDirectory->isFile($path)) { + if (!$this->coreFileStorageDatabase->saveFileToFilesystem($path)) { + continue; + } + } + $this->fileFullPath = $this->rootDirectory->getAbsolutePath($path); + $this->fileRelativePath = $path; + break; + } + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Option/Value.php b/app/code/Magento/Catalog/Model/Product/Option/Value.php index dcc8d625a4ffa..50c32e3e93922 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Value.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Value.php @@ -25,6 +25,7 @@ use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Option; +use \Magento\Framework\Model\AbstractExtensibleModel; /** * Catalog product option select type model @@ -33,14 +34,10 @@ * @method \Magento\Catalog\Model\Resource\Product\Option\Value getResource() * @method int getOptionId() * @method \Magento\Catalog\Model\Product\Option\Value setOptionId(int $value) - * @method string getSku() - * @method \Magento\Catalog\Model\Product\Option\Value setSku(string $value) - * @method int getSortOrder() - * @method \Magento\Catalog\Model\Product\Option\Value setSortOrder(int $value) * * @SuppressWarnings(PHPMD.LongVariable) */ -class Value extends \Magento\Framework\Model\AbstractModel +class Value extends AbstractExtensibleModel implements \Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface { /** * Option type percent @@ -72,6 +69,7 @@ class Value extends \Magento\Framework\Model\AbstractModel /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService * @param \Magento\Catalog\Model\Resource\Product\Option\Value\CollectionFactory $valueCollectionFactory * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\Db $resourceCollection @@ -80,13 +78,14 @@ class Value extends \Magento\Framework\Model\AbstractModel public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Catalog\Api\CategoryAttributeRepositoryInterface $metadataService, \Magento\Catalog\Model\Resource\Product\Option\Value\CollectionFactory $valueCollectionFactory, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = array() ) { $this->_valueCollectionFactory = $valueCollectionFactory; - parent::__construct($context, $registry, $resource, $resourceCollection, $data); + parent::__construct($context, $registry, $metadataService, $resource, $resourceCollection, $data); } /** @@ -306,4 +305,54 @@ public function duplicate($oldOptionId, $newOptionId) $this->getResource()->duplicate($this, $oldOptionId, $newOptionId); return $this; } + + /** + * Get option title + * + * @return string + */ + public function getTitle() + { + return $this->_getData('title'); + } + + /** + * Get sort order + * + * @return int + */ + public function getSortOrder() + { + return $this->_getData('sort_order'); + } + + /** + * Get price type + * + * @return string + */ + public function getPriceType() + { + return $this->_getData('price_type'); + } + + /** + * Get Sku + * + * @return string|null + */ + public function getSku() + { + return $this->_getData('sku'); + } + + /** + * Get Sku + * + * @return string|null + */ + public function getOptionTypeId() + { + return $this->_getData('option_type_id'); + } } diff --git a/app/code/Magento/Catalog/Model/Product/PriceModifier.php b/app/code/Magento/Catalog/Model/Product/PriceModifier.php index 01373135fa103..8405447a88c73 100644 --- a/app/code/Magento/Catalog/Model/Product/PriceModifier.php +++ b/app/code/Magento/Catalog/Model/Product/PriceModifier.php @@ -29,6 +29,20 @@ class PriceModifier { + /** + * @var \Magento\Catalog\Model\ProductRepository + */ + protected $productRepository; + + /** + * @param \Magento\Catalog\Model\ProductRepository $productRepository + */ + public function __construct( + \Magento\Catalog\Model\ProductRepository $productRepository + ) { + $this->productRepository = $productRepository; + } + /** * @param \Magento\Catalog\Model\Product $product * @param int $customerGroupId @@ -47,7 +61,8 @@ public function removeGroupPrice(\Magento\Catalog\Model\Product $product, $custo foreach ($prices as $key => $groupPrice) { if ($groupPrice['cust_group'] == $customerGroupId - && intval($groupPrice['website_id']) === intval($websiteId)) { + && intval($groupPrice['website_id']) === intval($websiteId) + ) { unset ($prices[$key]); } } @@ -59,7 +74,7 @@ public function removeGroupPrice(\Magento\Catalog\Model\Product $product, $custo } $product->setData('group_price', $prices); try { - $product->save(); + $this->productRepository->save($product); } catch (\Exception $exception) { throw new CouldNotSaveException("Invalid data provided for group price"); } @@ -85,10 +100,12 @@ public function removeTierPrice(\Magento\Catalog\Model\Product $product, $custom foreach ($prices as $key => $tierPrice) { if ($customerGroupId == 'all' && $tierPrice['price_qty'] == $qty - && $tierPrice['all_groups'] == 1 && intval($tierPrice['website_id']) === intval($websiteId)) { + && $tierPrice['all_groups'] == 1 && intval($tierPrice['website_id']) === intval($websiteId) + ) { unset ($prices[$key]); } elseif ($tierPrice['price_qty'] == $qty && $tierPrice['cust_group'] == $customerGroupId - && intval($tierPrice['website_id']) === intval($websiteId)) { + && intval($tierPrice['website_id']) === intval($websiteId) + ) { unset ($prices[$key]); } } @@ -101,7 +118,7 @@ public function removeTierPrice(\Magento\Catalog\Model\Product $product, $custom } $product->setData('tier_price', $prices); try { - $product->save(); + $this->productRepository->save($product); } catch (\Exception $exception) { throw new CouldNotSaveException("Invalid data provided for tier_price"); } diff --git a/app/code/Magento/Catalog/Model/Product/TierPrice.php b/app/code/Magento/Catalog/Model/Product/TierPrice.php new file mode 100644 index 0000000000000..a1ef0f60e0e60 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/TierPrice.php @@ -0,0 +1,50 @@ +getData(self::QTY); + } + + /** + * Retrieve price value + * + * @return float + */ + public function getValue() + { + return $this->getData(self::VALUE); + } +} diff --git a/app/code/Magento/Catalog/Model/Product/TierPriceManagement.php b/app/code/Magento/Catalog/Model/Product/TierPriceManagement.php new file mode 100644 index 0000000000000..41ad04f748098 --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/TierPriceManagement.php @@ -0,0 +1,201 @@ +productRepository = $productRepository; + $this->priceBuilder = $priceBuilder; + $this->storeManager = $storeManager; + $this->priceModifier = $priceModifier; + $this->config = $config; + $this->groupManagement = $groupManagement; + $this->groupRepository = $groupRepository; + } + + /** + * {@inheritdoc} + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + public function add($productSku, $customerGroupId, $price, $qty) + { + if (!\Zend_Validate::is($price, 'Float') || $price <= 0 || !\Zend_Validate::is($qty, 'Float') || $qty <= 0) { + throw new InputException('Please provide valid data'); + } + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); + $tierPrices = $product->getData('tier_price'); + $websiteIdentifier = 0; + if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) != 0) { + $websiteIdentifier = $this->storeManager->getWebsite()->getId(); + } + $found = false; + + foreach ($tierPrices as &$item) { + if ('all' == $customerGroupId) { + $isGroupValid = ($item['all_groups'] == 1); + } else { + $isGroupValid = ($item['cust_group'] == $customerGroupId); + } + + if ($isGroupValid && $item['website_id'] == $websiteIdentifier && $item['price_qty'] == $qty) { + $item['price'] = $price; + $found = true; + break; + } + } + if (!$found) { + $mappedCustomerGroupId = 'all' == $customerGroupId + ? $this->groupManagement->getAllCustomersGroup()->getId() + : $this->groupRepository->getById($customerGroupId)->getId(); + + $tierPrices[] = array( + 'cust_group' => $mappedCustomerGroupId, + 'price' => $price, + 'website_price' => $price, + 'website_id' => $websiteIdentifier, + 'price_qty' => $qty + ); + } + + $product->setData('tier_price', $tierPrices); + $errors = $product->validate(); + if (is_array($errors) && count($errors)) { + $errorAttributeCodes = implode(', ', array_keys($errors)); + throw new InputException( + sprintf('Values of following attributes are invalid: %s', $errorAttributeCodes) + ); + } + try { + $this->productRepository->save($product); + } catch (\Exception $e) { + throw new CouldNotSaveException('Could not save group price'); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function remove($productSku, $customerGroupId, $qty) + { + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); + $websiteIdentifier = 0; + if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) != 0) { + $websiteIdentifier = $this->storeManager->getWebsite()->getId(); + } + $this->priceModifier->removeTierPrice($product, $customerGroupId, $qty, $websiteIdentifier); + return true; + } + + /** + * {@inheritdoc} + */ + public function getList($productSku, $customerGroupId) + { + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); + + $priceKey = 'website_price'; + if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { + $priceKey = 'price'; + } + + $prices = array(); + foreach ($product->getData('tier_price') as $price) { + if ((is_numeric($customerGroupId) && intval($price['cust_group']) === intval($customerGroupId)) + || ($customerGroupId === 'all' && $price['all_groups']) + ) { + $this->priceBuilder->populateWithArray( + array( + \Magento\Catalog\Api\Data\ProductTierPriceInterface::VALUE => $price[$priceKey], + \Magento\Catalog\Api\Data\ProductTierPriceInterface::QTY => $price['price_qty'] + ) + ); + $prices[] = $this->priceBuilder->create(); + } + } + return $prices; + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Type/Price.php b/app/code/Magento/Catalog/Model/Product/Type/Price.php index a56056a33f535..f56412702f942 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/Price.php +++ b/app/code/Magento/Catalog/Model/Product/Type/Price.php @@ -25,6 +25,7 @@ namespace Magento\Catalog\Model\Product\Type; use Magento\Catalog\Model\Product; +use Magento\Customer\Api\GroupManagementInterface; use Magento\Store\Model\Store; use Magento\Framework\Pricing\PriceCurrencyInterface; @@ -81,6 +82,11 @@ class Price */ protected $priceCurrency; + /** + * @var GroupManagementInterface + */ + protected $_groupManagement; + /** * @param \Magento\CatalogRule\Model\Resource\RuleFactory $ruleFactory * @param \Magento\Framework\StoreManagerInterface $storeManager @@ -88,6 +94,7 @@ class Price * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param PriceCurrencyInterface $priceCurrency + * @param GroupManagementInterface $groupManagement */ public function __construct( \Magento\CatalogRule\Model\Resource\RuleFactory $ruleFactory, @@ -95,7 +102,8 @@ public function __construct( \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Event\ManagerInterface $eventManager, - PriceCurrencyInterface $priceCurrency + PriceCurrencyInterface $priceCurrency, + GroupManagementInterface $groupManagement ) { $this->_ruleFactory = $ruleFactory; $this->_storeManager = $storeManager; @@ -103,6 +111,7 @@ public function __construct( $this->_customerSession = $customerSession; $this->_eventManager = $eventManager; $this->priceCurrency = $priceCurrency; + $this->_groupManagement = $groupManagement; } /** @@ -256,7 +265,7 @@ protected function _applyTierPrice($product, $qty, $finalPrice) */ public function getTierPrice($qty, $product) { - $allGroups = \Magento\Customer\Service\V1\CustomerGroupServiceInterface::CUST_GROUP_ALL; + $allGroups = $this->_groupManagement->getAllCustomersGroup()->getId(); $prices = $product->getData('tier_price'); if (is_null($prices)) { diff --git a/app/code/Magento/Catalog/Model/ProductAttributeGroupRepository.php b/app/code/Magento/Catalog/Model/ProductAttributeGroupRepository.php new file mode 100644 index 0000000000000..25864279fea14 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductAttributeGroupRepository.php @@ -0,0 +1,114 @@ +groupRepository = $groupRepository; + $this->groupResource = $groupResource; + $this->groupFactory = $groupFactory; + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Eav\Api\Data\AttributeGroupInterface $group) + { + return $this->groupRepository->save($group); + } + + /** + * {@inheritdoc} + */ + public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) + { + return $this->groupRepository->getList($searchCriteria); + } + + /** + * {@inheritdoc} + */ + public function get($groupId) + { + /** @var \Magento\Catalog\Model\Product\Attribute\Group $group */ + $group = $this->groupFactory->create(); + $this->groupResource->load($group, $groupId); + if (!$group->getId()) { + throw new NoSuchEntityException(sprintf('Group with id "%s" does not exist.', $groupId)); + } + return $group; + } + + /** + * {@inheritdoc} + */ + public function deleteById($groupId) + { + $this->delete( + $this->get($groupId) + ); + return true; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Eav\Api\Data\AttributeGroupInterface $group) + { + /** @var \Magento\Catalog\Model\Product\Attribute\Group $group */ + if ($group->hasSystemAttributes()) { + throw new StateException('Attribute group that contains system attributes can not be deleted'); + } + return $this->groupRepository->delete($group); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/Attribute.php b/app/code/Magento/Catalog/Model/ProductLink/Attribute.php new file mode 100644 index 0000000000000..8f7f4cc4f0747 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/Attribute.php @@ -0,0 +1,46 @@ +_get('code'); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return $this->_get('type'); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php new file mode 100644 index 0000000000000..023ed18378297 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php @@ -0,0 +1,74 @@ +converterPool = $converterPool; + $this->providers = $providers; + } + + /** + * Get product collection by link type + * + * @param \Magento\Catalog\Model\Product $product + * @param string $type + * @return array + * @throws NoSuchEntityException + */ + public function getCollection(\Magento\Catalog\Model\Product $product, $type) + { + if (!isset($this->providers[$type])) { + throw new NoSuchEntityException('Collection provider is not registered'); + } + + $products = $this->providers[$type]->getLinkedProducts($product); + $converter = $this->converterPool->getConverter($type); + $output = []; + foreach ($products as $item) { + $output[$item->getId()] = $converter->convert($item); + } + return $output; + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Crosssell.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Crosssell.php new file mode 100644 index 0000000000000..4f39bb467cf3c --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Crosssell.php @@ -0,0 +1,36 @@ +getCrossSellProducts(); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Related.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Related.php new file mode 100644 index 0000000000000..c07e8b3b79858 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Related.php @@ -0,0 +1,36 @@ +getRelatedProducts(); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Upsell.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Upsell.php new file mode 100644 index 0000000000000..4cf52a9920262 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/Upsell.php @@ -0,0 +1,36 @@ +getUpSellProducts(); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProviderInterface.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProviderInterface.php new file mode 100644 index 0000000000000..b2a6921662dfb --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProviderInterface.php @@ -0,0 +1,36 @@ +converters = $converters; + } + + /** + * Get converter by link type + * + * @param string $linkType + * @return ConverterInterface + */ + public function getConverter($linkType) + { + return isset($this->converters[$linkType]) + ? $this->converters[$linkType] + : $this->converters[$this->defaultConverterCode]; + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/Converter/DefaultConverter.php b/app/code/Magento/Catalog/Model/ProductLink/Converter/DefaultConverter.php new file mode 100644 index 0000000000000..a8020ec76c707 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/Converter/DefaultConverter.php @@ -0,0 +1,40 @@ + $product->getTypeId(), + 'sku' => $product->getSku(), + 'position' => $product->getPosition() + ]; + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/Link.php b/app/code/Magento/Catalog/Model/ProductLink/Link.php new file mode 100644 index 0000000000000..ed756e70e3295 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/Link.php @@ -0,0 +1,134 @@ +_data = $data; + } + + /** + * Retrieves a value from the data array if set, or null otherwise. + * + * @param string $key + * @return mixed|null + */ + protected function _get($key) + { + return isset($this->_data[$key]) ? $this->_data[$key] : null; + } + + /** + * Return Data Object data in array format. + * + * @return array + */ + public function __toArray() + { + $data = $this->_data; + $hasToArray = function ($model) { + return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']); + }; + foreach ($data as $key => $value) { + if ($hasToArray($value)) { + $data[$key] = $value->__toArray(); + } elseif (is_array($value)) { + foreach ($value as $nestedKey => $nestedValue) { + if ($hasToArray($nestedValue)) { + $value[$nestedKey] = $nestedValue->__toArray(); + } + } + $data[$key] = $value; + } + } + return $data; + } + + /** + * Get product SKU + * + * @identifier + * @return string + */ + public function getProductSku() + { + return $this->_get('product_sku'); + } + + /** + * Get link type + * + * @identifier + * @return string + */ + public function getLinkType() + { + return $this->_get('link_type'); + } + + /** + * Get linked product sku + * + * @identifier + * @return string + */ + public function getLinkedProductSku() + { + return $this->_get('linked_product_sku'); + } + + /** + * Get linked product type (simple, virtual, etc) + * + * @return string + */ + public function getLinkedProductType() + { + return $this->_get('linked_product_type'); + } + + /** + * Get product position + * + * @return int + */ + public function getPosition() + { + return $this->_get('position'); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/Management.php b/app/code/Magento/Catalog/Model/ProductLink/Management.php new file mode 100644 index 0000000000000..7ad96d096b547 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/Management.php @@ -0,0 +1,172 @@ +productRepository = $productRepository; + $this->entityCollectionProvider = $collectionProvider; + $this->productLinkBuilder = $productLinkBuilder; + $this->productResource = $productResource; + $this->linkInitializer = $linkInitializer; + $this->valueBuilder = $valueBuilder; + $this->linkTypeProvider = $linkTypeProvider; + } + + /** + * {@inheritdoc} + */ + public function getLinkedItemsByType($productSku, $type) + { + $output = []; + $product = $this->productRepository->get($productSku); + try { + $collection = $this->entityCollectionProvider->getCollection($product, $type); + } catch (NoSuchEntityException $e) { + throw new NoSuchEntityException('Unknown link type: ' . (string)$type); + } + foreach ($collection as $item) { + $data = [ + 'product_sku' => $product->getSku(), + 'link_type' => $type, + 'linked_product_sku' => $item['sku'], + 'linked_product_type' => $item['type'], + 'position' => $item['position'], + ]; + $this->productLinkBuilder->populateWithArray($data); + if (isset($item['custom_attributes'])) { + foreach ($item['custom_attributes'] as $option) { + $this->productLinkBuilder->setCustomAttribute( + $option['attribute_code'], + $option['value'] + ); + } + } + $output[] = $this->productLinkBuilder->create(); + } + return $output; + } + + /** + * {@inheritdoc} + */ + public function setProductLinks($productSku, $type, array $items) + { + $linkTypes = $this->linkTypeProvider->getLinkTypes(); + + if (!isset($linkTypes[$type])) { + throw new NoSuchEntityException( + sprintf("Provided link type \"%s\" does not exist", $type) + ); + } + + $product = $this->productRepository->get($productSku); + $assignedSkuList = []; + /** @var \Magento\Catalog\Api\Data\ProductLinkInterface $link */ + foreach ($items as $link) { + $assignedSkuList[] = $link->getLinkedProductSku(); + } + $linkedProductIds = $this->productResource->getProductsIdsBySkus($assignedSkuList); + + $links = []; + /** @var \Magento\Catalog\Api\Data\ProductLinkInterface[] $items*/ + foreach ($items as $link) { + $data = $link->__toArray(); + $linkedSku = $link->getLinkedProductSku(); + if (!isset($linkedProductIds[$linkedSku])) { + throw new NoSuchEntityException( + sprintf("Product with SKU \"%s\" does not exist", $linkedSku) + ); + } + $data['product_id'] = $linkedProductIds[$linkedSku]; + $links[$linkedProductIds[$linkedSku]] = $data; + } + $this->linkInitializer->initializeLinks($product, [$type => $links]); + try { + $product->save(); + } catch (\Exception $exception) { + throw new CouldNotSaveException('Invalid data provided for linked products'); + } + return true; + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/Repository.php b/app/code/Magento/Catalog/Model/ProductLink/Repository.php new file mode 100644 index 0000000000000..90b13c122a1f9 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/Repository.php @@ -0,0 +1,147 @@ +productRepository = $productRepository; + $this->entityCollectionProvider = $entityCollectionProvider; + $this->linkInitializer = $linkInitializer; + $this->linkManagement = $linkManagement; + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Catalog\Api\Data\ProductLinkInterface $entity) + { + $linkedProduct = $this->productRepository->get($entity->getLinkedProductSku()); + $product = $this->productRepository->get($entity->getProductSku()); + $links = $this->entityCollectionProvider->getCollection($product, $entity->getLinkType()); + + $data = $entity->__toArray(); + foreach ($entity->getCustomAttributes() as $attribute) { + $data[$attribute->getAttributeCode()] = $attribute->getValue(); + } + $data['product_id'] = $linkedProduct->getId(); + $links[$linkedProduct->getId()] = $data; + $this->linkInitializer->initializeLinks($product, [$entity->getLinkType() => $links]); + try { + $product->save(); + } catch (\Exception $exception) { + throw new CouldNotSaveException('Invalid data provided for linked products'); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Catalog\Api\Data\ProductLinkInterface $entity) + { + $linkedProduct = $this->productRepository->get($entity->getLinkedProductSku()); + $product = $this->productRepository->get($entity->getProductSku()); + $links = $this->entityCollectionProvider->getCollection($product, $entity->getLinkType()); + + if (!isset($links[$linkedProduct->getId()])) { + throw new NoSuchEntityException( + sprintf( + 'Product with SKU %s is not linked to product with SKU %s', + $entity->getLinkedProductSku(), + $entity->getProductSku() + ) + ); + } + //Remove product from the linked product list + unset($links[$linkedProduct->getId()]); + + $this->linkInitializer->initializeLinks($product, [$entity->getLinkType() => $links]); + try { + $product->save(); + } catch (\Exception $exception) { + throw new CouldNotSaveException('Invalid data provided for linked products'); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function deleteById($productSku, $type, $linkedProductSku) + { + $linkItems = $this->linkManagement->getLinkedItemsByType($productSku, $type); + /** @var \Magento\Catalog\Api\Data\ProductLinkInterface $linkItem */ + foreach ($linkItems as $linkItem) { + if ($linkItem->getLinkedProductSku() == $linkedProductSku) { + return $this->delete($linkItem); + } + } + throw new NoSuchEntityException( + 'Product %s doesn\'t have linked %s as %s', + [ + $productSku, + $linkedProductSku, + $type + ] + ); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductLink/Type.php b/app/code/Magento/Catalog/Model/ProductLink/Type.php new file mode 100644 index 0000000000000..b58bce138223c --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductLink/Type.php @@ -0,0 +1,46 @@ +_get('code'); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return $this->_get('name'); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductOptions/Config.php b/app/code/Magento/Catalog/Model/ProductOptions/Config.php index 8f024ef4e8a3d..5672a9cc0f3d2 100644 --- a/app/code/Magento/Catalog/Model/ProductOptions/Config.php +++ b/app/code/Magento/Catalog/Model/ProductOptions/Config.php @@ -23,7 +23,8 @@ */ namespace Magento\Catalog\Model\ProductOptions; -class Config extends \Magento\Framework\Config\Data implements \Magento\Catalog\Model\ProductOptions\ConfigInterface +class Config extends \Magento\Framework\Config\Data implements + \Magento\Catalog\Model\ProductOptions\ConfigInterface { /** * @param \Magento\Catalog\Model\ProductOptions\Config\Reader $reader diff --git a/app/code/Magento/Catalog/Model/ProductOptions/TypeList.php b/app/code/Magento/Catalog/Model/ProductOptions/TypeList.php new file mode 100644 index 0000000000000..4592218c02920 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductOptions/TypeList.php @@ -0,0 +1,72 @@ +config = $config; + $this->builder = $builder; + } + + /** + * {@inheritdoc} + */ + public function getItems() + { + $output = []; + foreach ($this->config->getAll() as $option) { + foreach ($option['types'] as $type) { + if ($type['disabled']) { + continue; + } + $itemData = [ + 'label' => __($type['label']), + 'code' => $type['name'], + 'group' => __($option['label']) + ]; + $output[] = $this->builder->populateWithArray($itemData)->create(); + } + } + return $output; + } +} diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index 8dc31bb44c1bf..9cec26266df6f 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -24,9 +24,12 @@ */ namespace Magento\Catalog\Model; -use Magento\Framework\Exception\NoSuchEntityException; +use \Magento\Framework\Exception\NoSuchEntityException; +use \Magento\Catalog\Model\Resource\Product\Collection; +use \Magento\Framework\Api\SearchCriteriaInterface; +use \Magento\Framework\Api\SortOrder; -class ProductRepository +class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterface { /** * @var ProductFactory @@ -38,27 +41,88 @@ class ProductRepository */ protected $instances = array(); + /** + * @var \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper + */ + protected $initializationHelper; + + /** + * @var \Magento\Catalog\Api\Data\ProductSearchResultsDataBuilder + */ + protected $searchResultsBuilder; + + /** + * @var \Magento\Framework\Api\SearchCriteriaDataBuilder + */ + protected $searchCriteriaBuilder; + + /** + * @var \Magento\Framework\Api\FilterBuilder + */ + protected $filterBuilder; + + /** + * @var \Magento\Catalog\Model\Resource\Product\CollectionFactory + */ + protected $collectionFactory; + + /** + * @var \Magento\Catalog\Model\Resource\Product + */ + protected $resourceModel; + + /** + * @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface + */ + protected $attributeRepository; + + /** + * @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface + */ + protected $metadataService; + /** * @param ProductFactory $productFactory + * @param \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $initializationHelper + * @param \Magento\Catalog\Api\Data\ProductSearchResultsDataBuilder $searchResultsBuilder + * @param Resource\Product\CollectionFactory $collectionFactory + * @param \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder + * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository + * @param Resource\Product $resourceModel + * @param \Magento\Framework\Api\FilterBuilder $filterBuilder + * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataServiceInterface */ - public function __construct(ProductFactory $productFactory) - { + public function __construct( + ProductFactory $productFactory, + \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $initializationHelper, + \Magento\Catalog\Api\Data\ProductSearchResultsDataBuilder $searchResultsBuilder, + \Magento\Catalog\Model\Resource\Product\CollectionFactory $collectionFactory, + \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder, + \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository, + \Magento\Catalog\Model\Resource\Product $resourceModel, + \Magento\Framework\Api\FilterBuilder $filterBuilder, + \Magento\Catalog\Api\ProductAttributeRepositoryInterface $metadataServiceInterface + ) { $this->productFactory = $productFactory; + $this->collectionFactory = $collectionFactory; + $this->initializationHelper = $initializationHelper; + $this->searchResultsBuilder = $searchResultsBuilder; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->resourceModel = $resourceModel; + $this->attributeRepository = $attributeRepository; + $this->filterBuilder = $filterBuilder; + $this->metadataService = $metadataServiceInterface; } /** - * Retrieve product instance by sku - * - * @param string $sku - * @param boolean $editMode - * @return Product - * @throws NoSuchEntityException + * {@inheritdoc} */ public function get($sku, $editMode = false) { if (!isset($this->instances[$sku])) { $product = $this->productFactory->create(); - $productId = $product->getIdBySku($sku); + + $productId = $this->resourceModel->getIdBySku($sku); if (!$productId) { throw new NoSuchEntityException('Requested product doesn\'t exist'); } @@ -70,4 +134,153 @@ public function get($sku, $editMode = false) } return $this->instances[$sku]; } + + /** + * Merge data from DB and updates from request + * + * @param array $productData + * @param bool $createNew + * @return \Magento\Catalog\Api\Data\ProductInterface|Product + * @throws NoSuchEntityException + */ + protected function initializeProductData(array $productData, $createNew) + { + if ($createNew) { + $product = $this->productFactory->create(); + } else { + $product = $this->get($productData['sku']); + $this->initializationHelper->initialize($product); + } + foreach ($productData as $key => $value) { + $product->setData($key, $value); + } + + return $product; + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false) + { + $productId = $this->resourceModel->getIdBySku($product->getSku()); + $product = $this->initializeProductData($product->toFlatArray(), empty($productId)); + $validationResult = $this->resourceModel->validate($product); + if (true !== $validationResult) { + throw new \Magento\Framework\Exception\CouldNotSaveException( + sprintf('Invalid product data: %s', implode(',', $validationResult)) + ); + } + try { + if ($saveOptions) { + $product->setCanSaveCustomOptions(true); + } + $this->resourceModel->save($product); + } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) { + throw \Magento\Framework\Exception\InputException::invalidFieldValue( + $exception->getAttributeCode(), + $product->getData($exception->getAttributeCode()), + $exception + ); + } catch (\Exception $e) { + throw new \Magento\Framework\Exception\CouldNotSaveException('Unable to save product'); + } + if (array_key_exists($product->getSku(), $this->instances)) { + unset($this->instances[$product->getSku()]); + } + + return $product; + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Catalog\Api\Data\ProductInterface $product) + { + $productSku = $product->getSku(); + try { + $this->resourceModel->delete($product); + } catch (\Exception $e) { + throw new \Magento\Framework\Exception\StateException('Unable to remove product ' . $productSku); + } + if (array_key_exists($productSku, $this->instances)) { + unset($this->instances[$productSku]); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function deleteById($productSku) + { + $product = $this->get($productSku); + return $this->delete($product); + } + + /** + * {@inheritdoc} + */ + public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) + { + /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */ + $collection = $this->collectionFactory->create(); + + $extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter( + [ + $this->filterBuilder + ->setField('attribute_set_id') + ->setValue(\Magento\Catalog\Api\Data\ProductAttributeInterface::DEFAULT_ATTRIBUTE_SET_ID) + ->create() + ] + ); + + foreach ($this->metadataService->getList($extendedSearchCriteria->create())->getItems() as $metadata) { + $collection->addAttributeToSelect($metadata->getAttributeCode()); + } + $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner'); + $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner'); + + //Add filters from root filter group to the collection + foreach ($searchCriteria->getFilterGroups() as $group) { + $this->addFilterGroupToCollection($group, $collection); + } + /** @var SortOrder $sortOrder */ + foreach ((array)$searchCriteria->getSortOrders() as $sortOrder) { + $field = $sortOrder->getField(); + $collection->addOrder( + $field, + ($sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC) ? 'ASC' : 'DESC' + ); + } + $collection->setCurPage($searchCriteria->getCurrentPage()); + $collection->setPageSize($searchCriteria->getPageSize()); + $collection->load(); + + $this->searchResultsBuilder->setSearchCriteria($searchCriteria); + $this->searchResultsBuilder->setItems($collection->getItems()); + $this->searchResultsBuilder->setTotalCount($collection->getSize()); + return $this->searchResultsBuilder->create(); + } + + /** + * Helper function that adds a FilterGroup to the collection. + * + * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup + * @param Collection $collection + * @return void + */ + protected function addFilterGroupToCollection( + \Magento\Framework\Api\Search\FilterGroup $filterGroup, + Collection $collection + ) { + $fields = []; + foreach ($filterGroup->getFilters() as $filter) { + $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; + $fields[] = array('attribute' => $filter->getField(), $condition => $filter->getValue()); + } + if ($fields) { + $collection->addFieldToFilter($fields); + } + } } diff --git a/app/code/Magento/Catalog/Model/ProductType.php b/app/code/Magento/Catalog/Model/ProductType.php new file mode 100644 index 0000000000000..c4529b74bc800 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductType.php @@ -0,0 +1,47 @@ +_get('name'); + } + + /** + * {@inheritdoc} + */ + public function getLabel() + { + return $this->_get('label'); + } +} diff --git a/app/code/Magento/Catalog/Model/ProductTypeList.php b/app/code/Magento/Catalog/Model/ProductTypeList.php new file mode 100644 index 0000000000000..064bf3f6b0893 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ProductTypeList.php @@ -0,0 +1,85 @@ +productTypeConfig = $productTypeConfig; + $this->productTypeBuilder = $productTypeBuilder; + } + + /** + * {@inheritdoc} + */ + public function getProductTypes() + { + if (is_null($this->productTypes)) { + $productTypes = array(); + foreach ($this->productTypeConfig->getAll() as $productTypeData) { + $productTypes[] = $this->productTypeBuilder->populateWithArray( + [ + 'name' => $productTypeData['name'], + 'label' => $productTypeData['label'] + ] + )->create(); + } + $this->productTypes = $productTypes; + } + return $this->productTypes; + } +} diff --git a/app/code/Magento/Catalog/Model/Resource/Category/Attribute/Collection.php b/app/code/Magento/Catalog/Model/Resource/Category/Attribute/Collection.php index 622bd3a3c89ca..9004697019238 100644 --- a/app/code/Magento/Catalog/Model/Resource/Category/Attribute/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Category/Attribute/Collection.php @@ -43,6 +43,7 @@ class Collection extends \Magento\Eav\Model\Resource\Entity\Attribute\Collection * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory + * @param \Magento\Eav\Model\Config $eavConfig * @param \Zend_Db_Adapter_Abstract $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ @@ -51,12 +52,13 @@ public function __construct( \Magento\Framework\Logger $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\EntityFactory $eavEntityFactory, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { $this->_eavEntityFactory = $eavEntityFactory; - parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); + parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $connection, $resource); } /** diff --git a/app/code/Magento/Catalog/Model/Resource/Eav/Attribute.php b/app/code/Magento/Catalog/Model/Resource/Eav/Attribute.php index 2058d82898f25..67d6d04ff1d27 100644 --- a/app/code/Magento/Catalog/Model/Resource/Eav/Attribute.php +++ b/app/code/Magento/Catalog/Model/Resource/Eav/Attribute.php @@ -33,41 +33,29 @@ * @method \Magento\Catalog\Model\Resource\Eav\Attribute getFrontendInputRenderer() * @method string setFrontendInputRenderer(string $value) * @method int setIsGlobal(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsVisible() * @method int setIsVisible(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsSearchable() * @method int setIsSearchable(int $value) * @method \Magento\Catalog\Model\Resource\Eav\Attribute getSearchWeight() * @method int setSearchWeight(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsFilterable() * @method int setIsFilterable(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsComparable() * @method int setIsComparable(int $value) * @method int setIsVisibleOnFront(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsHtmlAllowedOnFront() * @method int setIsHtmlAllowedOnFront(int $value) * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsUsedForPriceRules() * @method int setIsUsedForPriceRules(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsFilterableInSearch() * @method int setIsFilterableInSearch(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getUsedInProductListing() * @method int setUsedInProductListing(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getUsedForSortBy() * @method int setUsedForSortBy(int $value) * @method string setApplyTo(string $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsVisibleInAdvancedSearch() * @method int setIsVisibleInAdvancedSearch(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getPosition() * @method int setPosition(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsWysiwygEnabled() * @method int setIsWysiwygEnabled(int $value) - * @method \Magento\Catalog\Model\Resource\Eav\Attribute getIsUsedForPromoRules() * @method int setIsUsedForPromoRules(int $value) - * @method string getFrontendLabel() * * @author Magento Core Team */ -class Attribute extends \Magento\Eav\Model\Entity\Attribute +class Attribute extends \Magento\Eav\Model\Entity\Attribute implements + \Magento\Catalog\Api\Data\ProductAttributeInterface { const SCOPE_STORE = 0; @@ -123,12 +111,14 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Api\MetadataServiceInterface $metadataService * @param \Magento\Core\Helper\Data $coreData * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Eav\Model\Resource\Helper $resourceHelper * @param \Magento\Framework\Validator\UniversalFactory $universalFactory + * @param \Magento\Eav\Api\Data\AttributeOptionDataBuilder $optionDataBuilder * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList * @param \Magento\Framework\Locale\ResolverInterface $localeResolver @@ -143,12 +133,14 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, + \Magento\Framework\Api\MetadataServiceInterface $metadataService, \Magento\Core\Helper\Data $coreData, \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Eav\Model\Resource\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, + \Magento\Eav\Api\Data\AttributeOptionDataBuilder $optionDataBuilder, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList, \Magento\Framework\Locale\ResolverInterface $localeResolver, @@ -167,12 +159,14 @@ public function __construct( parent::__construct( $context, $registry, + $metadataService, $coreData, $eavConfig, $eavTypeFactory, $storeManager, $resourceHelper, $universalFactory, + $optionDataBuilder, $localeDate, $reservedAttributeList, $localeResolver, @@ -196,7 +190,7 @@ protected function _construct() * @return \Magento\Framework\Model\AbstractModel * @throws \Magento\Framework\Model\Exception */ - protected function _beforeSave() + public function beforeSave() { $this->setData('modulePrefix', self::MODULE_NAME); if (isset($this->_origData['is_global'])) { @@ -221,7 +215,10 @@ protected function _beforeSave() $this->setIsHtmlAllowedOnFront(1); } } - return parent::_beforeSave(); + if (!$this->getIsSearchable()) { + $this->setIsVisibleInAdvancedSearch(false); + } + return parent::beforeSave(); } /** @@ -229,7 +226,7 @@ protected function _beforeSave() * * @return \Magento\Framework\Model\AbstractModel */ - protected function _afterSave() + public function afterSave() { /** * Fix saving attribute in admin @@ -245,7 +242,7 @@ protected function _afterSave() $this->_indexerEavProcessor->markIndexerAsInvalid(); } - return parent::_afterSave(); + return parent::afterSave(); } /** @@ -282,10 +279,10 @@ protected function _isOriginalEnabledInFlat() * @return $this * @throws \Magento\Framework\Model\Exception */ - protected function _beforeDelete() + public function beforeDelete() { $this->attrLockValidator->validate($this); - return parent::_beforeDelete(); + return parent::beforeDelete(); } /** @@ -293,9 +290,9 @@ protected function _beforeDelete() * * @return $this */ - protected function _afterDeleteCommit() + public function afterDeleteCommit() { - parent::_afterDeleteCommit(); + parent::afterDeleteCommit(); if ($this->_isOriginalEnabledInFlat()) { $this->_productFlatIndexerProcessor->markIndexerAsInvalid(); @@ -503,4 +500,124 @@ public function getIndexType() return 'source'; } + + /** + * {@inheritdoc} + */ + public function getIsWysiwygEnabled() + { + return $this->getData(self::IS_WYSIWYG_ENABLED); + } + + /** + * {@inheritdoc} + */ + public function getIsHtmlAllowedOnFront() + { + return $this->getData(self::IS_HTML_ALLOWED_ON_FRONT); + } + + /** + * {@inheritdoc} + */ + public function getUsedForSortBy() + { + return $this->getData(self::USED_FOR_SORT_BY); + } + + /** + * {@inheritdoc} + */ + public function getIsFilterable() + { + return $this->getData(self::IS_FILTERABLE); + } + + /** + * {@inheritdoc} + */ + public function getIsFilterableInSearch() + { + return $this->getData(self::IS_FILTERABLE_IN_SEARCH); + } + + /** + * {@inheritdoc} + */ + public function getPosition() + { + return $this->getData(self::POSITION); + } + + /** + * {@inheritdoc} + */ + public function getIsConfigurable() + { + return $this->getData(self::IS_CONFIGURABLE); + } + + /** + * {@inheritdoc} + */ + public function getIsSearchable() + { + return $this->getData(self::IS_SEARCHABLE); + } + + /** + * {@inheritdoc} + */ + public function getIsVisibleInAdvancedSearch() + { + return $this->getData(self::IS_VISIBLE_IN_ADVANCED_SEARCH); + } + + /** + * {@inheritdoc} + */ + public function getIsComparable() + { + return $this->getData(self::IS_COMPARABLE); + } + + /** + * {@inheritdoc} + */ + public function getIsUsedForPromoRules() + { + return $this->getData(self::IS_USED_FOR_PROMO_RULES); + } + + /** + * {@inheritdoc} + */ + public function getIsVisibleOnFront() + { + return $this->getData(self::IS_VISIBLE_ON_FRONT); + } + + /** + * {@inheritdoc} + */ + public function getUsedInProductListing() + { + return $this->getData(self::USED_IN_PRODUCT_LISTING); + } + + /** + * {@inheritdoc} + */ + public function getIsVisible() + { + return $this->getData(self::IS_VISIBLE); + } + + /** + * {@inheritdoc} + */ + public function getScope() + { + return $this->isScopeGlobal() ? 'global' : ($this->isScopeWebsite() ? 'website' : 'store'); + } } diff --git a/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Attribute.php b/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Attribute.php index be984995b84f1..b7fd22b243cfe 100644 --- a/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Attribute.php +++ b/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Attribute.php @@ -43,11 +43,12 @@ protected function _construct() /** * Apply attribute filter to product collection * - * @param \Magento\Catalog\Model\Layer\Filter\Attribute $filter + * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @param int $value + * @throws \Magento\Framework\Model\Exception * @return $this */ - public function applyFilterToCollection($filter, $value) + public function applyFilterToCollection(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter, $value) { $collection = $filter->getLayer()->getProductCollection(); $attribute = $filter->getAttributeModel(); @@ -72,10 +73,11 @@ public function applyFilterToCollection($filter, $value) /** * Retrieve array with products counts per attribute option * - * @param \Magento\Catalog\Model\Layer\Filter\Attribute $filter + * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter + * @throws \Magento\Framework\Model\Exception * @return array */ - public function getCount($filter) + public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter) { // clone select from collection with filters $select = clone $filter->getLayer()->getProductCollection()->getSelect(); diff --git a/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Decimal.php b/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Decimal.php index df7b61673dcb7..47b74ab9f9d65 100644 --- a/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Decimal.php +++ b/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Decimal.php @@ -43,12 +43,13 @@ protected function _construct() /** * Apply attribute filter to product collection * - * @param \Magento\Catalog\Model\Layer\Filter\Decimal $filter + * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @param float $range * @param int $index + * @throws \Magento\Framework\Model\Exception * @return $this */ - public function applyFilterToCollection($filter, $range, $index) + public function applyFilterToCollection(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter, $range, $index) { $collection = $filter->getLayer()->getProductCollection(); $attribute = $filter->getAttributeModel(); @@ -80,10 +81,10 @@ public function applyFilterToCollection($filter, $range, $index) /** * Retrieve array of minimal and maximal values * - * @param \Magento\Catalog\Model\Layer\Filter\Decimal $filter + * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @return array */ - public function getMinMax($filter) + public function getMinMax(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter) { $select = $this->_getSelect($filter); $adapter = $this->_getReadAdapter(); @@ -104,7 +105,8 @@ public function getMinMax($filter) * Retrieve clean select with joined index table * Joined table has index * - * @param \Magento\Catalog\Model\Layer\Filter\Decimal $filter + * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter + * @throws \Magento\Framework\Model\Exception * @return \Magento\Framework\DB\Select */ protected function _getSelect($filter) @@ -140,11 +142,11 @@ protected function _getSelect($filter) /** * Retrieve array with products counts per range * - * @param \Magento\Catalog\Model\Layer\Filter\Decimal $filter + * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @param int $range * @return array */ - public function getCount($filter, $range) + public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter, $range) { $select = $this->_getSelect($filter); $adapter = $this->_getReadAdapter(); diff --git a/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Price.php b/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Price.php index 594f0d7f5524d..f9d2134d754cb 100644 --- a/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Price.php +++ b/app/code/Magento/Catalog/Model/Resource/Layer/Filter/Price.php @@ -58,18 +58,18 @@ class Price extends \Magento\Framework\Model\Resource\Db\AbstractDb /** * @param \Magento\Framework\App\Resource $resource * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Catalog\Model\Layer\Category $layer + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param \Magento\Customer\Model\Session $session * @param \Magento\Framework\StoreManagerInterface $storeManager */ public function __construct( \Magento\Framework\App\Resource $resource, \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Catalog\Model\Layer\Category $layer, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Customer\Model\Session $session, \Magento\Framework\StoreManagerInterface $storeManager ) { - $this->layer = $layer; + $this->layer = $layerResolver->get(); $this->session = $session; $this->storeManager = $storeManager; $this->_eventManager = $eventManager; @@ -339,12 +339,12 @@ public function loadNextPrices($price, $rightIndex, $upperPrice = null) /** * Apply price range filter to product collection * - * @param \Magento\Catalog\Model\Layer\Filter\Price $filter + * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter + * @param mixed $interval * @return $this */ - public function applyPriceRange($filter) + public function applyPriceRange(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter, $interval) { - $interval = $filter->getInterval(); if (!$interval) { return $this; } diff --git a/app/code/Magento/Catalog/Model/Resource/Product.php b/app/code/Magento/Catalog/Model/Resource/Product.php index 9b7e0d30cc006..632fcc5e53bab 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product.php +++ b/app/code/Magento/Catalog/Model/Resource/Product.php @@ -59,8 +59,21 @@ class Product extends AbstractResource protected $_categoryCollectionFactory; /** - * Construct - * + * @var \Magento\Framework\Event\ManagerInterface + */ + protected $eventManager; + + /** + * @var \Magento\Eav\Model\Entity\Attribute\SetFactory + */ + protected $setFactory; + + /** + * @var \Magento\Eav\Model\Entity\TypeFactory + */ + protected $typeFactory; + + /** * @param \Magento\Framework\App\Resource $resource * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Eav\Model\Entity\Attribute\Set $attrSetEntity @@ -69,8 +82,11 @@ class Product extends AbstractResource * @param \Magento\Framework\Validator\UniversalFactory $universalFactory * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Factory $modelFactory - * @param \Magento\Catalog\Model\Resource\Category\CollectionFactory $categoryCollectionFactory + * @param Category\CollectionFactory $categoryCollectionFactory * @param Category $catalogCategory + * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param \Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory + * @param \Magento\Eav\Model\Entity\TypeFactory $typeFactory * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -86,10 +102,16 @@ public function __construct( \Magento\Catalog\Model\Factory $modelFactory, \Magento\Catalog\Model\Resource\Category\CollectionFactory $categoryCollectionFactory, Category $catalogCategory, + \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory, + \Magento\Eav\Model\Entity\TypeFactory $typeFactory, $data = array() ) { $this->_categoryCollectionFactory = $categoryCollectionFactory; $this->_catalogCategory = $catalogCategory; + $this->eventManager = $eventManager; + $this->setFactory = $setFactory; + $this->typeFactory = $typeFactory; parent::__construct( $resource, $eavConfig, @@ -246,6 +268,19 @@ protected function _afterSave(\Magento\Framework\Object $product) return parent::_afterSave($product); } + /** + * {@inheritdoc} + */ + public function delete($object) + { + $result = parent::delete($object); + $this->eventManager->dispatch( + 'catalog_product_delete_after_done', + array('product' => $object) + ); + return $result; + } + /** * Save product website relations * @@ -599,4 +634,19 @@ public function countAll() $result = (int)$adapter->fetchOne($select); return $result; } + + /** + * {@inheritdoc} + */ + public function validate($object) + { + //validate attribute set entity type + $entityType = $this->typeFactory->create()->loadByCode(\Magento\Catalog\Model\Product::ENTITY); + $attributeSet = $this->setFactory->create()->load($object->getAttributeSetId()); + if ($attributeSet->getEntityTypeId() != $entityType->getId()) { + return ['attribute_set' => 'Invalid attribute set entity type']; + } + + return parent::validate($object); + } } diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Backend/Media.php b/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Backend/Media.php index 6a35f9315be35..f7b0bfc32ce81 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Backend/Media.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Backend/Media.php @@ -63,26 +63,33 @@ public function loadGallery($product, $object) // Select gallery images for product $select = $adapter->select()->from( - array('main' => $this->getMainTable()), - array('value_id', 'value AS file') + ['main' => $this->getMainTable()], + [ + 'value_id', + 'file' => 'value' + ] )->joinLeft( - array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), + ['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') + [ + 'label', + 'position', + 'disabled' + ] )->joinLeft( // Joining default values - array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), + ['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') + ['label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled'] )->where( 'main.attribute_id = ?', $object->getAttribute()->getId() )->where( 'main.entity_id = ?', $product->getId() - )->order( - $positionCheckSql . ' ' . \Magento\Framework\DB\Select::SQL_ASC - ); + ) + ->where($positionCheckSql . ' IS NOT NULL') + ->order($positionCheckSql . ' ' . \Magento\Framework\DB\Select::SQL_ASC); $result = $adapter->fetchAll($select); $this->_removeDuplicates($result); diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Collection.php b/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Collection.php index bad88547c508b..7b10431ddd666 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Attribute/Collection.php @@ -41,6 +41,7 @@ class Collection extends \Magento\Eav\Model\Resource\Entity\Attribute\Collection * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory + * @param \Magento\Eav\Model\Config $eavConfig * @param \Zend_Db_Adapter_Abstract $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ @@ -49,12 +50,13 @@ public function __construct( \Magento\Framework\Logger $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\EntityFactory $eavEntityFactory, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { $this->_eavEntityFactory = $eavEntityFactory; - parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); + parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $connection, $resource); } /** diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php index 1c7709593681e..fa3b910bc3353 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php @@ -25,9 +25,9 @@ use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus; use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; +use Magento\Customer\Api\GroupManagementInterface; use Magento\Framework\DB\Select; use Magento\Store\Model\Store; -use Magento\Customer\Service\V1\CustomerGroupServiceInterface; /** * Product collection @@ -260,6 +260,11 @@ class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractColl */ protected $dateTime; + /** + * @var GroupManagementInterface + */ + protected $_groupManagement; + /** * @param \Magento\Core\Model\EntityFactory $entityFactory * @param \Magento\Framework\Logger $logger @@ -279,6 +284,7 @@ class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractColl * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Framework\Stdlib\DateTime $dateTime + * @param GroupManagementInterface $groupManagement * @param \Zend_Db_Adapter_Abstract $connection * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -302,6 +308,7 @@ public function __construct( \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Stdlib\DateTime $dateTime, + GroupManagementInterface $groupManagement, $connection = null ) { $this->moduleManager = $moduleManager; @@ -313,6 +320,7 @@ public function __construct( $this->_customerSession = $customerSession; $this->_resourceHelper = $resourceHelper; $this->dateTime = $dateTime; + $this->_groupManagement = $groupManagement; parent::__construct( $entityFactory, $logger, @@ -382,9 +390,8 @@ protected function _preparePriceExpressionParameters($select) */ public function getPriceExpression($select) { - if (null === $this->_priceExpression) { - $this->_preparePriceExpressionParameters($select); - } + //@todo: Add caching of price expresion + $this->_preparePriceExpressionParameters($select); return $this->_priceExpression; } @@ -2044,7 +2051,7 @@ public function addTierPriceData() foreach ($adapter->fetchAll($select) as $row) { $tierPrices[$row['product_id']][] = array( 'website_id' => $row['website_id'], - 'cust_group' => $row['all_groups'] ? CustomerGroupServiceInterface::CUST_GROUP_ALL : $row['cust_group'], + 'cust_group' => $row['all_groups'] ? $this->_groupManagement->getAllCustomersGroup()->getId() : $row['cust_group'], 'price_qty' => $row['price_qty'], 'price' => $row['price'], 'website_price' => $row['price'] diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Compare/Item/Collection.php b/app/code/Magento/Catalog/Model/Resource/Product/Compare/Item/Collection.php index fbdee28a69e73..3df10d62496d9 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Compare/Item/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Compare/Item/Collection.php @@ -85,6 +85,7 @@ class Collection extends \Magento\Catalog\Model\Resource\Product\Collection * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Framework\Stdlib\DateTime $dateTime + * @param \Magento\Customer\Api\GroupManagementInterface $groupManagement * @param \Magento\Catalog\Model\Resource\Product\Compare\Item $catalogProductCompareItem * @param \Magento\Catalog\Helper\Product\Compare $catalogProductCompare * @param \Zend_Db_Adapter_Abstract $connection @@ -110,6 +111,7 @@ public function __construct( \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Stdlib\DateTime $dateTime, + \Magento\Customer\Api\GroupManagementInterface $groupManagement, \Magento\Catalog\Model\Resource\Product\Compare\Item $catalogProductCompareItem, \Magento\Catalog\Helper\Product\Compare $catalogProductCompare, $connection = null @@ -135,6 +137,7 @@ public function __construct( $localeDate, $customerSession, $dateTime, + $groupManagement, $connection ); } diff --git a/app/code/Magento/Catalog/Model/Resource/Setup.php b/app/code/Magento/Catalog/Model/Resource/Setup.php index 3dd73ed183ea9..0e6e8d6c3ebd1 100644 --- a/app/code/Magento/Catalog/Model/Resource/Setup.php +++ b/app/code/Magento/Catalog/Model/Resource/Setup.php @@ -383,6 +383,7 @@ public function getDefaultEntities() 'type' => 'varchar', 'label' => 'Name', 'input' => 'text', + 'frontend_class' => 'validate-length maximum-length-255', 'sort_order' => 1, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE, 'searchable' => true, @@ -394,6 +395,7 @@ public function getDefaultEntities() 'type' => 'static', 'label' => 'SKU', 'input' => 'text', + 'frontend_class' => 'validate-length maximum-length-64', 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Sku', 'unique' => true, 'sort_order' => 2, @@ -447,7 +449,7 @@ public function getDefaultEntities() 'input' => 'price', 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Price', 'required' => false, - 'sort_order' => 2, + 'sort_order' => 3, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, 'used_in_product_listing' => true, 'apply_to' => 'simple,virtual', @@ -459,7 +461,7 @@ public function getDefaultEntities() 'input' => 'date', 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Startdate', 'required' => false, - 'sort_order' => 3, + 'sort_order' => 4, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, 'used_in_product_listing' => true, 'apply_to' => 'simple,virtual', @@ -471,7 +473,7 @@ public function getDefaultEntities() 'input' => 'date', 'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\Datetime', 'required' => false, - 'sort_order' => 4, + 'sort_order' => 5, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, 'used_in_product_listing' => true, 'apply_to' => 'simple,virtual', @@ -484,7 +486,7 @@ public function getDefaultEntities() 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Price', 'required' => false, 'user_defined' => true, - 'sort_order' => 5, + 'sort_order' => 6, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, 'apply_to' => 'simple,virtual', 'group' => 'Prices' @@ -493,8 +495,10 @@ public function getDefaultEntities() 'type' => 'decimal', 'label' => 'Weight', 'input' => 'weight', + 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Weight', + 'input_renderer' => 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight', 'sort_order' => 5, - 'apply_to' => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE + 'apply_to' => 'simple,virtual' ), 'manufacturer' => array( 'type' => 'int', @@ -542,10 +546,12 @@ public function getDefaultEntities() 'label' => 'Base Image', 'input' => 'media_image', 'frontend' => 'Magento\Catalog\Model\Product\Attribute\Frontend\Image', + 'input_renderer' => 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\BaseImage', 'required' => false, - 'sort_order' => 1, + 'sort_order' => 0, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE, - 'group' => 'Images' + 'used_in_product_listing' => true, + 'group' => 'General' ), 'small_image' => array( 'type' => 'varchar', @@ -585,7 +591,7 @@ public function getDefaultEntities() 'input' => 'text', 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Groupprice', 'required' => false, - 'sort_order' => 6, + 'sort_order' => 2, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, 'apply_to' => 'simple,virtual', 'group' => 'Prices' @@ -596,7 +602,7 @@ public function getDefaultEntities() 'input' => 'text', 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Tierprice', 'required' => false, - 'sort_order' => 6, + 'sort_order' => 7, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, 'apply_to' => 'simple,virtual', 'group' => 'Prices' @@ -617,7 +623,7 @@ public function getDefaultEntities() 'type' => 'datetime', 'label' => 'Set Product as New from Date', 'input' => 'date', - 'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\Datetime', + 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Startdate', 'required' => false, 'sort_order' => 7, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, @@ -656,7 +662,7 @@ public function getDefaultEntities() 'label' => 'Minimal Price', 'input' => 'price', 'required' => false, - 'sort_order' => 7, + 'sort_order' => 8, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE, 'visible' => false, 'apply_to' => 'simple,virtual', @@ -685,7 +691,7 @@ public function getDefaultEntities() 'type' => 'datetime', 'label' => 'Active From', 'input' => 'date', - 'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\Datetime', + 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Startdate', 'required' => false, 'sort_order' => 2, 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE, @@ -723,10 +729,14 @@ public function getDefaultEntities() ), 'category_ids' => array( 'type' => 'static', + 'label' => 'Categories', 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL, + 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Category', + 'input_renderer' => 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category', 'required' => false, - 'sort_order' => 13, - 'visible' => false + 'sort_order' => 9, + 'visible' => true, + 'group' => 'General' ), 'options_container' => array( 'type' => 'varchar', @@ -797,6 +807,41 @@ public function getDefaultEntities() 'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\Time\Updated', 'sort_order' => 20, 'visible' => false + ), + 'country_of_manufacture' => array( + 'type' => 'varchar', + 'label' => 'Country of Manufacture', + 'input' => 'select', + 'source' => 'Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture', + 'required' => false, + 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, + 'visible' => true, + 'user_defined' => false, + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'apply_to' => 'simple,bundle', + 'group' => 'General', + ), + 'quantity_and_stock_status' => array( + 'group' => 'General', + 'type' => 'int', + 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Stock', + 'label' => 'Quantity', + 'input' => 'select', + 'input_renderer' => 'Magento\CatalogInventory\Block\Adminhtml\Form\Field\Stock', + 'source' => 'Magento\\CatalogInventory\\Model\\Source\\Stock', + 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL, + 'default' => \Magento\CatalogInventory\Model\Stock::STOCK_IN_STOCK, + 'user_defined' => false, + 'visible' => true, + 'required' => false, + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'unique' => false ) ) ) diff --git a/app/code/Magento/Catalog/Model/Rss/Category.php b/app/code/Magento/Catalog/Model/Rss/Category.php index 9a7f34bbadfdd..47736d9b8bf25 100644 --- a/app/code/Magento/Catalog/Model/Rss/Category.php +++ b/app/code/Magento/Catalog/Model/Rss/Category.php @@ -45,16 +45,16 @@ class Category protected $visibility; /** - * @param \Magento\Catalog\Model\Layer\Category $catalogLayer + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param \Magento\Catalog\Model\Resource\Product\CollectionFactory $collectionFactory * @param \Magento\Catalog\Model\Product\Visibility $visibility */ public function __construct( - \Magento\Catalog\Model\Layer\Category $catalogLayer, + \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Catalog\Model\Resource\Product\CollectionFactory $collectionFactory, \Magento\Catalog\Model\Product\Visibility $visibility ) { - $this->catalogLayer = $catalogLayer; + $this->catalogLayer = $layerResolver->get(); $this->collectionFactory = $collectionFactory; $this->visibility = $visibility; } diff --git a/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php b/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php index a86383cc8cffc..05d69cce83f4d 100644 --- a/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php +++ b/app/code/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php @@ -86,7 +86,7 @@ public function __construct( * * @return $this */ - protected function _beforeSave() + public function beforeSave() { $this->urlRewriteHelper->validateSuffix($this->getValue()); return $this; @@ -95,12 +95,12 @@ protected function _beforeSave() /** * @return $this */ - protected function _afterSave() + public function afterSave() { if ($this->isValueChanged()) { $this->updateSuffixForUrlRewrites(); } - return parent::_afterSave(); + return parent::afterSave(); } /** diff --git a/app/code/Magento/Catalog/Pricing/Price/ConfiguredPrice.php b/app/code/Magento/Catalog/Pricing/Price/ConfiguredPrice.php index 1498d9f2ebc19..5104472262605 100644 --- a/app/code/Magento/Catalog/Pricing/Price/ConfiguredPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/ConfiguredPrice.php @@ -47,16 +47,18 @@ class ConfiguredPrice extends FinalPrice implements ConfiguredPriceInterface * @param Product $saleableItem * @param float $quantity * @param CalculatorInterface $calculator + * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param ItemInterface $item */ public function __construct( Product $saleableItem, $quantity, CalculatorInterface $calculator, + \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, ItemInterface $item = null ) { $this->item = $item; - parent::__construct($saleableItem, $quantity, $calculator); + parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); } /** diff --git a/app/code/Magento/Catalog/Pricing/Price/FinalPrice.php b/app/code/Magento/Catalog/Pricing/Price/FinalPrice.php index 10c5472f8a170..b86518acf69de 100644 --- a/app/code/Magento/Catalog/Pricing/Price/FinalPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/FinalPrice.php @@ -43,6 +43,16 @@ class FinalPrice extends AbstractPrice implements FinalPriceInterface */ private $basePrice; + /** + * @var \Magento\Framework\Pricing\Amount\AmountInterface + */ + protected $minimalPrice; + + /** + * @var \Magento\Framework\Pricing\Amount\AmountInterface + */ + protected $maximalPrice; + /** * Get Value * @@ -60,11 +70,16 @@ public function getValue() */ public function getMinimalPrice() { - $minimalPrice = $this->product->getMinimalPrice(); - if ($minimalPrice === null) { - $minimalPrice = $this->getValue(); + if (!$this->minimalPrice) { + $minimalPrice = $this->product->getMinimalPrice(); + if ($minimalPrice === null) { + $minimalPrice = $this->getValue(); + } else { + $minimalPrice = $this->priceCurrency->convertAndRound($minimalPrice); + } + $this->minimalPrice = $this->calculator->getAmount($minimalPrice, $this->product); } - return $this->calculator->getAmount($minimalPrice, $this->product); + return $this->minimalPrice; } /** @@ -74,7 +89,10 @@ public function getMinimalPrice() */ public function getMaximalPrice() { - return $this->calculator->getAmount($this->getValue(), $this->product); + if (!$this->maximalPrice) { + $this->maximalPrice = $this->calculator->getAmount($this->getValue(), $this->product); + } + return $this->maximalPrice; } /** diff --git a/app/code/Magento/Catalog/Pricing/Price/GroupPrice.php b/app/code/Magento/Catalog/Pricing/Price/GroupPrice.php index 626f76151d28e..ba2d4db3d7d46 100644 --- a/app/code/Magento/Catalog/Pricing/Price/GroupPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/GroupPrice.php @@ -33,7 +33,7 @@ /** * Group price model */ -class GroupPrice extends AbstractPrice implements GroupPriceInterface, BasePriceProviderInterface +class GroupPrice extends AbstractPrice implements BasePriceProviderInterface { /** * Price type group @@ -54,15 +54,17 @@ class GroupPrice extends AbstractPrice implements GroupPriceInterface, BasePrice * @param Product $saleableItem * @param float $quantity * @param CalculatorInterface $calculator + * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param Session $customerSession */ public function __construct( Product $saleableItem, $quantity, CalculatorInterface $calculator, + \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, Session $customerSession ) { - parent::__construct($saleableItem, $quantity, $calculator); + parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); $this->customerSession = $customerSession; } @@ -77,6 +79,9 @@ public function getValue() foreach ($this->getStoredGroupPrice() as $groupPrice) { if ($groupPrice['cust_group'] == $customerGroup) { $this->value = (float) $groupPrice['website_price']; + if (!$this->isPercentageDiscount()) { + $this->value = $this->priceCurrency->convertAndRound($this->value); + } break; } } @@ -98,7 +103,7 @@ protected function getCustomerGroupId() /** * @return array */ - public function getStoredGroupPrice() + protected function getStoredGroupPrice() { if (null === $this->storedGroupPrice) { $resource = $this->product->getResource(); @@ -113,4 +118,12 @@ public function getStoredGroupPrice() } return $this->storedGroupPrice; } + + /** + * @return bool + */ + public function isPercentageDiscount() + { + return false; + } } diff --git a/app/code/Magento/Catalog/Pricing/Price/GroupPriceInterface.php b/app/code/Magento/Catalog/Pricing/Price/GroupPriceInterface.php deleted file mode 100644 index 7a91ed8774aee..0000000000000 --- a/app/code/Magento/Catalog/Pricing/Price/GroupPriceInterface.php +++ /dev/null @@ -1,36 +0,0 @@ -value === null) { $price = $this->product->getPrice(); - $this->value = $price ? floatval($price) : false; + $priceInCurrentCurrency = $this->priceCurrency->convertAndRound($price); + $this->value = $priceInCurrentCurrency ? floatval($priceInCurrentCurrency) : false; } return $this->value; } diff --git a/app/code/Magento/Catalog/Pricing/Price/SpecialPrice.php b/app/code/Magento/Catalog/Pricing/Price/SpecialPrice.php index bab2c64e8132d..4def55e30818c 100644 --- a/app/code/Magento/Catalog/Pricing/Price/SpecialPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/SpecialPrice.php @@ -49,15 +49,17 @@ class SpecialPrice extends AbstractPrice implements SpecialPriceInterface, BaseP * @param Product $saleableItem * @param float $quantity * @param CalculatorInterface $calculator + * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param TimezoneInterface $localeDate */ public function __construct( Product $saleableItem, $quantity, CalculatorInterface $calculator, + \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, TimezoneInterface $localeDate ) { - parent::__construct($saleableItem, $quantity, $calculator); + parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); $this->localeDate = $localeDate; } @@ -84,7 +86,11 @@ public function getValue() */ public function getSpecialPrice() { - return $this->product->getSpecialPrice(); + $specialPrice = $this->product->getSpecialPrice(); + if (!is_null($specialPrice) && $specialPrice !== false && !$this->isPercentageDiscount()) { + $specialPrice = $this->priceCurrency->convertAndRound($specialPrice); + } + return $specialPrice; } /** @@ -118,4 +124,12 @@ public function isScopeDateInInterval() $this->getSpecialToDate() ); } + + /** + * @return bool + */ + public function isPercentageDiscount() + { + return false; + } } diff --git a/app/code/Magento/Catalog/Pricing/Price/SpecialPriceInterface.php b/app/code/Magento/Catalog/Pricing/Price/SpecialPriceInterface.php index b319b7f66fe1f..3b0bfe633f6e7 100644 --- a/app/code/Magento/Catalog/Pricing/Price/SpecialPriceInterface.php +++ b/app/code/Magento/Catalog/Pricing/Price/SpecialPriceInterface.php @@ -54,4 +54,9 @@ public function getSpecialToDate(); * @return bool */ public function isScopeDateInInterval(); + + /** + * @return bool + */ + public function isPercentageDiscount(); } diff --git a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php index d12080b57a94f..2bae3efb0e145 100644 --- a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php @@ -26,7 +26,7 @@ use Magento\Framework\Pricing\Adjustment\CalculatorInterface; use Magento\Catalog\Model\Product; -use Magento\Customer\Model\Group; +use Magento\Customer\Api\GroupManagementInterface; use Magento\Customer\Model\Session; use Magento\Framework\Pricing\Price\AbstractPrice; use Magento\Framework\Pricing\PriceInfoInterface; @@ -71,17 +71,22 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr * @param Product $saleableItem * @param float $quantity * @param CalculatorInterface $calculator + * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param Session $customerSession + * @param GroupManagementInterface $groupManagement */ public function __construct( Product $saleableItem, $quantity, CalculatorInterface $calculator, - Session $customerSession + \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, + Session $customerSession, + GroupManagementInterface $groupManagement ) { $quantity = $quantity ?: 1; - parent::__construct($saleableItem, $quantity, $calculator); + parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); $this->customerSession = $customerSession; + $this->groupManagement = $groupManagement; if ($saleableItem->hasCustomerGroupId()) { $this->customerGroup = (int) $saleableItem->getCustomerGroupId(); } else { @@ -100,7 +105,7 @@ public function getValue() $prices = $this->getStoredTierPrices(); $prevQty = PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT; $this->value = $prevPrice = $tierPrice = false; - $priceGroup = Group::CUST_GROUP_ALL; + $priceGroup = $this->groupManagement->getAllCustomersGroup()->getId(); foreach ($prices as $price) { if (!$this->canApplyTierPrice($price, $priceGroup, $prevQty)) { @@ -168,7 +173,7 @@ protected function filterTierPrices(array $priceList) $qtyCache = []; foreach ($priceList as $priceKey => $price) { /* filter price by customer group */ - if ($price['cust_group'] !== $this->customerGroup && $price['cust_group'] !== Group::CUST_GROUP_ALL) { + if ($price['cust_group'] !== $this->customerGroup && $price['cust_group'] !== $this->groupManagement->getAllCustomersGroup()->getId()) { unset($priceList[$priceKey]); continue; } @@ -228,10 +233,11 @@ protected function applyAdjustment($price) */ protected function canApplyTierPrice(array $currentTierPrice, $prevPriceGroup, $prevQty) { + $custGroupAllId = $this->groupManagement->getAllCustomersGroup()->getId(); // Tier price can be applied, if: // tier price is for current customer group or is for all groups if ($currentTierPrice['cust_group'] !== $this->customerGroup - && $currentTierPrice['cust_group'] !== Group::CUST_GROUP_ALL + && $currentTierPrice['cust_group'] !== $custGroupAllId ) { return false; } @@ -245,8 +251,8 @@ protected function canApplyTierPrice(array $currentTierPrice, $prevPriceGroup, $ } // and found tier qty is same as previous tier qty, but current tier group isn't ALL_GROUPS if ($currentTierPrice['price_qty'] == $prevQty - && $prevPriceGroup !== Group::CUST_GROUP_ALL - && $currentTierPrice['cust_group'] === Group::CUST_GROUP_ALL + && $prevPriceGroup !== $custGroupAllId + && $currentTierPrice['cust_group'] === $custGroupAllId ) { return false; } @@ -273,7 +279,27 @@ protected function getStoredTierPrices() if (null === $this->rawPriceList || !is_array($this->rawPriceList)) { $this->rawPriceList = array(); } + if (!$this->isPercentageDiscount()) { + foreach ($this->rawPriceList as $index => $rawPrice) { + if (isset($rawPrice['price'])) { + $this->rawPriceList[$index]['price'] = + $this->priceCurrency->convertAndRound($rawPrice['price']); + } + if (isset($rawPrice['website_price'])) { + $this->rawPriceList[$index]['website_price'] = + $this->priceCurrency->convertAndRound($rawPrice['website_price']); + } + } + } } return $this->rawPriceList; } + + /** + * @return bool + */ + public function isPercentageDiscount() + { + return false; + } } diff --git a/app/code/Magento/Catalog/Pricing/Price/TierPriceInterface.php b/app/code/Magento/Catalog/Pricing/Price/TierPriceInterface.php index 184628b9c6b6e..075cc90f1e024 100644 --- a/app/code/Magento/Catalog/Pricing/Price/TierPriceInterface.php +++ b/app/code/Magento/Catalog/Pricing/Price/TierPriceInterface.php @@ -38,4 +38,9 @@ public function getTierPriceList(); * @return int */ public function getTierPriceCount(); + + /** + * @return bool + */ + public function isPercentageDiscount(); } diff --git a/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php b/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php index 2085b806b0136..379f2b56df5e5 100644 --- a/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php +++ b/app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php @@ -64,7 +64,8 @@ protected function _toHtml() MsrpPrice::PRICE_CODE, $this->getSaleableItem(), [ - 'real_price_html' => $result + 'real_price_html' => $result, + 'zone' => $this->getZone(), ] ); $result = $msrpBlock->toHtml(); diff --git a/app/code/Magento/Catalog/Service/V1/Category/Attribute/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Category/Attribute/ReadServiceInterface.php index 946958e59b185..2ed210b2d81ed 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/Attribute/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Category/Attribute/ReadServiceInterface.php @@ -35,6 +35,7 @@ interface ReadServiceInterface * @return \Magento\Catalog\Service\V1\Data\Eav\Option[] * * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated */ public function options($id); @@ -45,6 +46,7 @@ public function options($id); * @return \Magento\Catalog\Service\V1\Data\Eav\AttributeMetadata * * @throws \Magento\Framework\Exception\NoSuchEntityException + * @see \Magento\Catalog\Api\CategoryAttributeRepositoryInterface::get */ public function info($id); @@ -53,6 +55,7 @@ public function info($id); * * @param \Magento\Framework\Api\SearchCriteria $searchCriteria * @return \Magento\Catalog\Service\V1\Data\Product\Attribute\SearchResults containing Data\Eav\Attribute objects + * @see \Magento\Catalog\Api\CategoryAttributeRepositoryInterface::getList */ public function search(\Magento\Framework\Api\SearchCriteria $searchCriteria); } diff --git a/app/code/Magento/Catalog/Service/V1/Category/MetadataServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Category/MetadataServiceInterface.php index e51478b84fb20..48e94bae95c89 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/MetadataServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Category/MetadataServiceInterface.php @@ -27,6 +27,8 @@ /** * Class Category MetadataServiceInterface + * @deprecated + * @see \Magento\Catalog\Api\CategoryAttributeMetadataRepositoryInterface */ interface MetadataServiceInterface extends \Magento\Framework\Api\MetadataServiceInterface { @@ -37,7 +39,7 @@ interface MetadataServiceInterface extends \Magento\Framework\Api\MetadataServic const DEFAULT_ATTRIBUTE_SET_ID = 3; - const DATA_OBJECT_CLASS_NAME = 'Magento\Catalog\Service\V1\Data\Category'; + const DATA_OBJECT_CLASS_NAME = 'Magento\Catalog\Api\Data\CategoryInterface'; /**#@-*/ /** diff --git a/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/ReadServiceInterface.php index 2d9601c55df9c..819a7375e5e76 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/ReadServiceInterface.php @@ -23,12 +23,19 @@ */ namespace Magento\Catalog\Service\V1\Category\ProductLinks; +/** + * @deprecated + * @todo remove this interface + */ interface ReadServiceInterface { /** * @param int $categoryId * @return \Magento\Catalog\Service\V1\Data\Category\ProductLink[] * @throws \Magento\Framework\Exception\NoSuchEntityException + * + * @deprecated + * @see \Magento\Catalog\Api\CategoryLinkManagementInterface::getList */ public function assignedProducts($categoryId); } diff --git a/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/WriteServiceInterface.php index bcf6f75250404..4f634e7c9a401 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Category/ProductLinks/WriteServiceInterface.php @@ -25,6 +25,10 @@ use Magento\Catalog\Service\V1\Data\Category\ProductLink; +/** + * @deprecated + * @todo remove this interface + */ interface WriteServiceInterface { /** @@ -36,6 +40,9 @@ interface WriteServiceInterface * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException + * + * @deprecated + * @see \Magento\Catalog\Api\CategoryLinkManagementInterface::save */ public function assignProduct($categoryId, ProductLink $productLink); @@ -46,6 +53,9 @@ public function assignProduct($categoryId, ProductLink $productLink); * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException + * + * @deprecated + * @see \Magento\Catalog\Api\CategoryLinkManagementInterface::save */ public function updateProduct($categoryId, ProductLink $productLink); @@ -57,6 +67,9 @@ public function updateProduct($categoryId, ProductLink $productLink); * @return bool Will returned True if products sucessfully deleted * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\StateException + * + * @deprecated + * @see \Magento\Catalog\Api\CategoryLinkManagementInterface::delete */ public function removeProduct($categoryId, $productSku); } diff --git a/app/code/Magento/Catalog/Service/V1/Category/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Category/ReadServiceInterface.php index 2cf1d9146b8a7..a592b09fa334a 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Category/ReadServiceInterface.php @@ -23,6 +23,9 @@ */ namespace Magento\Catalog\Service\V1\Category; +/** + * @todo remove this interface + */ interface ReadServiceInterface { /** @@ -31,6 +34,8 @@ interface ReadServiceInterface * @param int $categoryId * @return \Magento\Catalog\Service\V1\Data\Eav\Category\Info\Metadata * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Catalog\Api\CategoryRepositoryInterface::get */ public function info($categoryId); } diff --git a/app/code/Magento/Catalog/Service/V1/Category/Tree/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Category/Tree/ReadServiceInterface.php index 95b7f24a128e9..c3858bcd54dff 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/Tree/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Category/Tree/ReadServiceInterface.php @@ -28,6 +28,8 @@ /** * Class ReadServiceInterface * @package Magento\Catalog\Service\V1\Category + * + * @todo remove this interface */ interface ReadServiceInterface { @@ -38,6 +40,8 @@ interface ReadServiceInterface * @param int $rootCategoryId * @param int $depth * @return \Magento\Catalog\Service\V1\Data\Eav\Category\Tree containing Tree objects + * @deprecated + * @see \Magento\Catalog\Api\CategoryManagementInterface::getTree */ public function tree($rootCategoryId = null, $depth = null); } diff --git a/app/code/Magento/Catalog/Service/V1/Category/WriteService.php b/app/code/Magento/Catalog/Service/V1/Category/WriteService.php index 307d05be3416c..ab7cc5960d5c7 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/WriteService.php +++ b/app/code/Magento/Catalog/Service/V1/Category/WriteService.php @@ -107,7 +107,6 @@ public function delete($categoryId) } catch (\Exception $e) { throw new StateException('Cannot delete category with id %category_id', ['category_id' => $categoryId], $e); } - return true; } @@ -124,7 +123,6 @@ public function update($categoryId, CategoryDataObject $category) } catch (\Exception $e) { throw new CouldNotSaveException('Could not save category', [], $e); } - return true; } diff --git a/app/code/Magento/Catalog/Service/V1/Category/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Category/WriteServiceInterface.php index 46d46f8729957..318bc56c3f0eb 100644 --- a/app/code/Magento/Catalog/Service/V1/Category/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Category/WriteServiceInterface.php @@ -23,6 +23,9 @@ */ namespace Magento\Catalog\Service\V1\Category; +/** + * @todo remove this interface + */ interface WriteServiceInterface { /** @@ -31,6 +34,8 @@ interface WriteServiceInterface * @param \Magento\Catalog\Service\V1\Data\Category $category * @return int * @throws \Magento\Framework\Exception\CouldNotSaveException + * @deprecated + * @see \Magento\Catalog\Api\CategoryRepositoryInterface::save */ public function create(\Magento\Catalog\Service\V1\Data\Category $category); @@ -42,6 +47,8 @@ public function create(\Magento\Catalog\Service\V1\Data\Category $category); * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\StateException * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Catalog\Api\CategoryRepositoryInterface::delete */ public function delete($categoryId); @@ -53,6 +60,8 @@ public function delete($categoryId); * @return bool * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\InputException + * @deprecated + * @see \Magento\Catalog\Api\CategoryManagementInterface::update */ public function update($categoryId, \Magento\Catalog\Service\V1\Data\Category $category); @@ -65,6 +74,8 @@ public function update($categoryId, \Magento\Catalog\Service\V1\Data\Category $c * @return bool * @throws \Magento\Framework\Model\Exception * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Catalog\Api\CategoryManagementInterface::move */ public function move($categoryId, $parentId, $afterId = null); } diff --git a/app/code/Magento/Catalog/Service/V1/Data/Category.php b/app/code/Magento/Catalog/Service/V1/Data/Category.php index 4c9dc79048db6..e5bd98f81ad3e 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Category.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Category.php @@ -27,6 +27,8 @@ /** * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\CategoryInterface */ class Category extends AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Category/Mapper.php b/app/code/Magento/Catalog/Service/V1/Data/Category/Mapper.php index a384ade3e0e90..1a43f1e40569f 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Category/Mapper.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Category/Mapper.php @@ -32,13 +32,21 @@ class Mapper /** @var CategoryFactory */ protected $categoryFactory; + /** + * @var \Magento\Framework\Api\ExtensibleDataObjectConverter + */ + protected $extensibleDataObjectConverter; + /** * @param CategoryFactory $categoryFactory + * @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter */ public function __construct( - CategoryFactory $categoryFactory + CategoryFactory $categoryFactory, + \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter ) { $this->categoryFactory = $categoryFactory; + $this->extensibleDataObjectConverter = $extensibleDataObjectConverter; } /** @@ -52,7 +60,7 @@ public function toModel( \Magento\Catalog\Model\Category $categoryModel = null ) { $categoryModel = $categoryModel ?: $this->categoryFactory->create(); - $data = ExtensibleDataObjectConverter::toFlatArray($category); + $data = $this->extensibleDataObjectConverter->toFlatArray($category); /** @see /app/code/Magento/Catalog/Controller/Adminhtml/Category.php method "_filterCategoryPostData" */ if (isset($data['image']) && is_array($data['image'])) { $data['image_additional_data'] = $data['image']; diff --git a/app/code/Magento/Catalog/Service/V1/Data/Category/ProductLink.php b/app/code/Magento/Catalog/Service/V1/Data/Category/ProductLink.php index 91ddadbbf7618..d50cce8ffad38 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Category/ProductLink.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Category/ProductLink.php @@ -24,7 +24,10 @@ namespace Magento\Catalog\Service\V1\Data\Category; /** - * @codeCoverageIgnore + * @deprecated + * @todo remove this interface + * + * Replaced with @see \Magento\Catalog\Api\Data\CategoryProductLinkInterface */ class ProductLink extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeMetadata.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeMetadata.php index 42af9f3191773..87856a6b63b3a 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeMetadata.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeMetadata.php @@ -30,6 +30,8 @@ * Class AttributeMetadata * * @codeCoverageIgnore + * @deprecated + * @see \Magento\Eav\Api\Data\Entity\Attribute\MetadataInterface */ class AttributeMetadata extends AbstractExtensibleObject implements MetadataObjectInterface { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php index 2ab5a6171fe15..aac4a6f14982b 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php @@ -27,6 +27,8 @@ * Contains basic attribute set data * * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\AttributeSetInterface */ class AttributeSet extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/AttributeMetadata.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/AttributeMetadata.php index ec86ba2ccc5a5..839a4c2282ec1 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/AttributeMetadata.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/AttributeMetadata.php @@ -28,6 +28,7 @@ /** * @codeCoverageIgnore + * @todo this interface is never used. Recheck and remove it. */ class AttributeMetadata extends AbstractExtensibleObject implements MetadataObjectInterface { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/Tree.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/Tree.php index a0c36bb855001..61493e7d5366e 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/Tree.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/Category/Tree.php @@ -25,6 +25,8 @@ /** * @codeCoverageIgnore + * @see \Magento\Catalog\Api\Data\CategoryTreeInterface + * @deprecated */ class Tree extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/Option.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/Option.php index c5453b69c048d..dc934eabe3331 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Eav/Option.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/Option.php @@ -28,6 +28,8 @@ /** * Class Option * + * @deprecated + * @see \Magento\Eav\Api\Data\AttributeOptionInterface * @codeCoverageIgnore */ class Option extends \Magento\Framework\Api\AbstractExtensibleObject diff --git a/app/code/Magento/Catalog/Service/V1/Data/Product.php b/app/code/Magento/Catalog/Service/V1/Data/Product.php index cd22db48b77e5..a41eafda4728c 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Product.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Product.php @@ -25,6 +25,8 @@ /** * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Service\V1\Data\Product */ class Product extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Product/GroupPrice.php b/app/code/Magento/Catalog/Service/V1/Data/Product/GroupPrice.php index da2036c621d2b..e9ac5893ca556 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Product/GroupPrice.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Product/GroupPrice.php @@ -28,6 +28,8 @@ /** * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\ProductGroupPriceInterface */ class GroupPrice extends AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Product/TierPrice.php b/app/code/Magento/Catalog/Service/V1/Data/Product/TierPrice.php index 948b8af2128be..cd589f9e18d4b 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/Product/TierPrice.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Product/TierPrice.php @@ -28,6 +28,8 @@ /** * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\ProductTierPriceInterface */ class TierPrice extends AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Data/ProductMapper.php b/app/code/Magento/Catalog/Service/V1/Data/ProductMapper.php index 034f6db876c0e..3cc08ae91033f 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/ProductMapper.php +++ b/app/code/Magento/Catalog/Service/V1/Data/ProductMapper.php @@ -23,8 +23,9 @@ */ namespace Magento\Catalog\Service\V1\Data; -use \Magento\Framework\Api\ExtensibleDataObjectConverter; - +/** + * @deprecated + */ class ProductMapper { /** @var \Magento\Catalog\Model\ProductFactory */ @@ -33,16 +34,24 @@ class ProductMapper /** @var \Magento\Catalog\Model\Product\Type */ protected $productTypes; + /** + * @var \Magento\Framework\Api\ExtensibleDataObjectConverter + */ + protected $extensibleDataObjectConverter; + /** * @param \Magento\Catalog\Model\ProductFactory $productFactory * @param \Magento\Catalog\Model\Product\Type $productTypes + * @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter */ public function __construct( \Magento\Catalog\Model\ProductFactory $productFactory, - \Magento\Catalog\Model\Product\Type $productTypes + \Magento\Catalog\Model\Product\Type $productTypes, + \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter ) { $this->productFactory = $productFactory; $this->productTypes = $productTypes; + $this->extensibleDataObjectConverter = $extensibleDataObjectConverter; } /** @@ -58,8 +67,8 @@ public function toModel( $customAttributesToSkip = array() ) { /** @var \Magento\Catalog\Model\Product $productModel */ - $productModel = $productModel ? : $this->productFactory->create(); - $productModel->addData(ExtensibleDataObjectConverter::toFlatArray($product, $customAttributesToSkip)); + $productModel = $productModel ?: $this->productFactory->create(); + $productModel->addData($this->extensibleDataObjectConverter->toFlatArray($product, $customAttributesToSkip)); if (!is_numeric($productModel->getAttributeSetId())) { $productModel->setAttributeSetId($productModel->getDefaultAttributeSetId()); } diff --git a/app/code/Magento/Catalog/Service/V1/Data/ProductType.php b/app/code/Magento/Catalog/Service/V1/Data/ProductType.php index 47f458447df85..96351662eed9f 100644 --- a/app/code/Magento/Catalog/Service/V1/Data/ProductType.php +++ b/app/code/Magento/Catalog/Service/V1/Data/ProductType.php @@ -29,6 +29,8 @@ /** * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\ProductTypeInterface */ class ProductType extends AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/MetadataService.php b/app/code/Magento/Catalog/Service/V1/MetadataService.php index f9ee4c10ada4e..a930f292cb66a 100644 --- a/app/code/Magento/Catalog/Service/V1/MetadataService.php +++ b/app/code/Magento/Catalog/Service/V1/MetadataService.php @@ -37,6 +37,8 @@ * * @package Magento\Catalog\Service\V1 * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @deprecated + * @see \Magento\Eav\Api\Entity\Attribute\MetadataRepositoryInterface */ class MetadataService implements MetadataServiceInterface { diff --git a/app/code/Magento/Catalog/Service/V1/MetadataServiceInterface.php b/app/code/Magento/Catalog/Service/V1/MetadataServiceInterface.php index 4137f899c6971..b9b6b6f238356 100644 --- a/app/code/Magento/Catalog/Service/V1/MetadataServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/MetadataServiceInterface.php @@ -39,6 +39,7 @@ interface MetadataServiceInterface * @param string $attributeCode * @return AttributeMetadata * @throws \Magento\Framework\Exception\NoSuchEntityException + * @see \Magento\Eav\Api\AttributeRepositoryInterface::get */ public function getAttributeMetadata($entityType, $attributeCode); @@ -48,6 +49,7 @@ public function getAttributeMetadata($entityType, $attributeCode); * @param string $entityType * @param SearchCriteria $searchCriteria * @return SearchResults + * @see \Magento\Eav\Api\AttributeRepositoryInterface::getList */ public function getAllAttributeMetadata($entityType, SearchCriteria $searchCriteria); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/ReadServiceInterface.php index 020e95b2e2a48..91d894b5b9279 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/ReadServiceInterface.php @@ -24,6 +24,9 @@ */ namespace Magento\Catalog\Service\V1\Product\Attribute\Media; +/** + * @deprecated + */ interface ReadServiceInterface { /** @@ -33,12 +36,14 @@ interface ReadServiceInterface * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\InputException * @return \Magento\Catalog\Service\V1\Product\Attribute\Media\Data\MediaImage[] + * @see \Magento\Catalog\Api\ProductMediaAttributeManagementInterface::getList */ public function types($attributeSetId); /** * @param string $productSku * @return \Magento\Catalog\Service\V1\Product\Attribute\Media\Data\GalleryEntry[] + * @see \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface::getList */ public function getList($productSku); @@ -49,6 +54,7 @@ public function getList($productSku); * @param int $imageId * @throws \Magento\Framework\Exception\NoSuchEntityException * @return \Magento\Catalog\Service\V1\Product\Attribute\Media\Data\GalleryEntry + * @see \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface::get */ public function info($productSku, $imageId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/WriteServiceInterface.php index c5672db0f6384..384032833835c 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Media/WriteServiceInterface.php @@ -28,6 +28,9 @@ use \Magento\Catalog\Service\V1\Product\Attribute\Media\Data\GalleryEntry; use \Magento\Catalog\Service\V1\Product\Attribute\Media\Data\GalleryEntryContent; +/** + * @deprecated + */ interface WriteServiceInterface { /** @@ -41,6 +44,7 @@ interface WriteServiceInterface * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException + * @see \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface::create */ public function create($productSku, GalleryEntry $entry, GalleryEntryContent $entryContent, $storeId = 0); @@ -53,6 +57,7 @@ public function create($productSku, GalleryEntry $entry, GalleryEntryContent $en * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException + * @see \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface::update */ public function update($productSku, GalleryEntry $entry, $storeId = 0); @@ -64,6 +69,7 @@ public function update($productSku, GalleryEntry $entry, $storeId = 0); * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException + * @see \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface::remove */ public function delete($productSku, $entryId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/ReadServiceInterface.php index 3f84807fe7ddb..ee3c3a4e54a01 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/ReadServiceInterface.php @@ -25,12 +25,17 @@ /** * Interface ReadServiceInterface + * @deprecated + * @see \Magento\Eav\Api\OptionManagementInterface */ interface ReadServiceInterface { /** * Retrieve list of attribute options * + * @deprecated + * @see \Magento\Eav\Api\AttributeOptionManagementInterface::getItems + * * @param string $id * @return \Magento\Catalog\Service\V1\Data\Eav\Option[] */ diff --git a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/WriteServiceInterface.php index 8a2237e83ee84..433465f000c8f 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Attribute/Option/WriteServiceInterface.php @@ -25,12 +25,17 @@ /** * Interface WriteServiceInterface + * @deprecated + * @see \Magento\Eav\Api\AttributeOptionManagementInterface */ interface WriteServiceInterface { /** * Add option to attribute * + * @deprecated + * @see \Magento\Eav\Api\AttributeOptionManagementInterface::addOption + * * @param string $id * @param \Magento\Catalog\Service\V1\Data\Eav\Option $option * @throws \Magento\Framework\Exception\StateException @@ -41,6 +46,9 @@ public function addOption($id, \Magento\Catalog\Service\V1\Data\Eav\Option $opti /** * Delete option from attribute * + * @deprecated + * @see \Magento\Eav\Api\AttributeOptionManagementInterface::removeOption + * * @param string $id * @param int $optionId * @throws \Magento\Framework\Exception\StateException diff --git a/app/code/Magento/Catalog/Service/V1/Product/Attribute/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Attribute/ReadServiceInterface.php index 7af415f863a52..a853b4c4e301a 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Attribute/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Attribute/ReadServiceInterface.php @@ -33,6 +33,8 @@ interface ReadServiceInterface * Retrieve list of product attribute types * * @return \Magento\Catalog\Service\V1\Data\Eav\Product\Attribute\Type[] + * @deprecated + * @see \Magento\Catalog\Api\AttributeTypesListInterface::getItems */ public function types(); @@ -43,6 +45,8 @@ public function types(); * @return \Magento\Catalog\Service\V1\Data\Eav\AttributeMetadata * * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Catalog\Api\ProductAttributeRepositoryInterface::get */ public function info($id); @@ -51,6 +55,8 @@ public function info($id); * * @param \Magento\Framework\Api\SearchCriteria $searchCriteria * @return \Magento\Catalog\Service\V1\Data\Product\Attribute\SearchResults containing Data\Eav\Attribute objects + * @deprecated + * @see \Magento\Catalog\Api\ProductAttributeRepositoryInterface::getList */ public function search(\Magento\Framework\Api\SearchCriteria $searchCriteria); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteService.php b/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteService.php index 67148773e41bc..1428ab4da2954 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteService.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteService.php @@ -132,7 +132,7 @@ public function create(\Magento\Catalog\Service\V1\Data\Eav\AttributeMetadata $a */ public function update($id, AttributeMetadata $attribute) { - /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attributeModel */ + /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $model */ $model = $this->attributeFactory->create(); $model->loadByCode(\Magento\Catalog\Model\Product::ENTITY, $id); if (!$model->getId()) { diff --git a/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteServiceInterface.php index 1458c40ca538f..a0a34ed2f82af 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Attribute/WriteServiceInterface.php @@ -36,6 +36,8 @@ interface WriteServiceInterface * @return string * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Eav\Exception from validate() + * @deprecated + * @see \Magento\Catalog\Api\CategoryAttributeRepositoryInterface::save */ public function create(\Magento\Catalog\Service\V1\Data\Eav\AttributeMetadata $attributeMetadata); @@ -47,6 +49,8 @@ public function create(\Magento\Catalog\Service\V1\Data\Eav\AttributeMetadata $a * @return string * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Catalog\Api\CategoryAttributeRepositoryInterface::save */ public function update($id, \Magento\Catalog\Service\V1\Data\Eav\AttributeMetadata $attribute); @@ -57,6 +61,8 @@ public function update($id, \Magento\Catalog\Service\V1\Data\Eav\AttributeMetada * @throws \Magento\Framework\Exception\NoSuchEntityException If ID is not found * @throws \Exception If something goes wrong during delete * @return bool True if the entity was deleted (always true) + * @deprecated + * @see \Magento\Catalog\Api\CategoryAttributeRepositoryInterface::delete */ public function remove($attributeId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php index 74dc98351c95e..6aae2efc8119f 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php @@ -32,6 +32,8 @@ interface ReadServiceInterface * @param string $attributeSetId * @return \Magento\Catalog\Service\V1\Data\Eav\AttributeGroup[] * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Eav\Api\AttributeGroupRepositoryInterface::getList */ public function getList($attributeSetId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php index 9a2515a06e367..0fc910b776664 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php @@ -34,6 +34,8 @@ interface WriteServiceInterface * @return \Magento\Catalog\Service\V1\Data\Eav\AttributeGroup * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Eav\Api\AttributeGroupRepositoryInterface::save */ public function create($attributeSetId, \Magento\Catalog\Service\V1\Data\Eav\AttributeGroup $groupData); @@ -47,6 +49,8 @@ public function create($attributeSetId, \Magento\Catalog\Service\V1\Data\Eav\Att * @throws \Magento\Framework\Exception\StateException * @throws \Magento\Framework\Exception\CouldNotSaveException * @return bool + * @deprecated + * @see \Magento\Eav\Api\AttributeGroupRepositoryInterface::save */ public function update($attributeSetId, $groupId, \Magento\Catalog\Service\V1\Data\Eav\AttributeGroup $groupData); @@ -58,6 +62,8 @@ public function update($attributeSetId, $groupId, \Magento\Catalog\Service\V1\Da * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException * @return bool + * @deprecated + * @see \Magento\Eav\Api\AttributeGroupRepositoryInterface::delete */ public function delete($attributeSetId, $groupId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php index 0e6d39281ba0e..b434114cc24b4 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php @@ -29,6 +29,8 @@ interface AttributeServiceInterface * @param int $attributeSetId * @param \Magento\Catalog\Service\V1\Data\Eav\AttributeSet\Attribute $data * @return int + * @deprecated + * @see \Magento\Eav\Api\AttributeManagementInterface::assign */ public function addAttribute($attributeSetId, \Magento\Catalog\Service\V1\Data\Eav\AttributeSet\Attribute $data); @@ -41,6 +43,8 @@ public function addAttribute($attributeSetId, \Magento\Catalog\Service\V1\Data\E * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException * @return bool + * @deprecated + * @see \Magento\Eav\Api\AttributeManagementInterface::unassign */ public function deleteAttribute($attributeSetId, $attributeId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php index dc9e766fbab2d..ef4e19dbd6f04 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php @@ -27,6 +27,8 @@ interface ReadServiceInterface { /** * @return \Magento\Catalog\Service\V1\Data\Eav\AttributeSet[] + * @deprecated + * @see \Magento\Eav\Api\AttributeSetRepositoryInterface::getList */ public function getList(); @@ -36,6 +38,8 @@ public function getList(); * @param int $attributeSetId * @throws \Magento\Framework\Exception\NoSuchEntityException If $attributeSetId is not found * @return \Magento\Catalog\Service\V1\Data\Eav\AttributeSet + * @deprecated + * @see \Magento\Eav\Api\AttributeSetRepositoryInterface::get */ public function getInfo($attributeSetId); @@ -45,6 +49,8 @@ public function getInfo($attributeSetId); * @param int $attributeSetId * @throws \Magento\Framework\Exception\NoSuchEntityException If $attributeSetId is not found * @return \Magento\Catalog\Service\V1\Data\Eav\Attribute[] + * @deprecated + * @see \Magento\Eav\Api\AttributeManagementInterface::getAttributes */ public function getAttributeList($attributeSetId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php index 700c71892921a..15a02de37a210 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php @@ -39,6 +39,8 @@ interface WriteServiceInterface * @return int * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Eav\Api\AttributeSetManagementInterface::create */ public function create(AttributeSet $attributeSet, $skeletonId); @@ -48,6 +50,8 @@ public function create(AttributeSet $attributeSet, $skeletonId); * @param \Magento\Catalog\Service\V1\Data\Eav\AttributeSet $attributeSetData * @return int attribute set ID * @throws \Magento\Framework\Model\Exception If attribute set is not found + * @deprecated + * @see \Magento\Eav\Api\AttributeSetRepositoryInterface::save */ public function update(AttributeSet $attributeSetData); @@ -58,6 +62,8 @@ public function update(AttributeSet $attributeSetData); * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\InputException * @return bool + * @deprecated + * @see \Magento\Eav\Api\AttributeSetRepositoryInterface::delete */ public function remove($attributeSetId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option.php b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option.php index cbd06da93bee7..e96aaddc6cbcb 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option.php +++ b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option.php @@ -25,7 +25,9 @@ namespace Magento\Catalog\Service\V1\Product\CustomOptions\Data; /** - * @codeCoverageIgnore + * @deprecate + * @todo remove this interface + * @see \Magento\Catalog\Api\Data\ProductCustomOptionsOptionInterface */ class Option extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option/Metadata.php b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option/Metadata.php index 8cf6d86e2bb19..ccac7129cab1e 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option/Metadata.php +++ b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/Option/Metadata.php @@ -25,7 +25,8 @@ namespace Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option; /** - * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\ProductCustomOptionAttributeInterface */ class Metadata extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/OptionType.php b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/OptionType.php index 46b542b96cad0..2eab270d5d6b5 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/OptionType.php +++ b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/Data/OptionType.php @@ -25,7 +25,9 @@ namespace Magento\Catalog\Service\V1\Product\CustomOptions\Data; /** - * @codeCoverageIgnore + * @deprecate + * @todo remove this interface + * @see \Magento\Catalog\Api\Data\ProductCustomOptionTypeInterface */ class OptionType extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/ReadServiceInterface.php index f5381e836aefe..9382a7dd605b1 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/ReadServiceInterface.php @@ -24,12 +24,20 @@ namespace Magento\Catalog\Service\V1\Product\CustomOptions; +/** + * @deprecated + * @todo remove this interface + * @see \Magento\Catalog\Api\Product\CustomOptionManagementInterface + */ interface ReadServiceInterface { /** * Get custom option types * * @return \Magento\Catalog\Service\V1\Product\CustomOptions\Data\OptionType[] + * + * @deprecated + * @see \Magento\Catalog\Api\ProductCustomOptionTypeListInterface::getItems */ public function getTypes(); @@ -39,6 +47,9 @@ public function getTypes(); * @param string $productSku * @return \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option[] * @throws \Magento\Framework\Exception\NoSuchEntityException + * + * @deprecated + * @see \Magento\Catalog\Api\ProductCustomOptionManagementInterface::getList */ public function getList($productSku); @@ -49,6 +60,9 @@ public function getList($productSku); * @param string $optionId * @return \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option * @throws \Magento\Framework\Exception\NoSuchEntityException + * + * @deprecated + * @see \Magento\Catalog\Api\ProductCustomOptionManagementInterface::get */ public function get($productSku, $optionId); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/WriteServiceInterface.php index 000cb68e728b4..d7735560a21b9 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/CustomOptions/WriteServiceInterface.php @@ -24,6 +24,11 @@ namespace Magento\Catalog\Service\V1\Product\CustomOptions; +/** + * @deprecated + * @todo remove this interface + * @see \Magento\Catalog\Api\Product\CustomOptionManagementInterface + */ interface WriteServiceInterface { /** @@ -33,6 +38,9 @@ interface WriteServiceInterface * @param int $optionId * @throws \Magento\Framework\Exception\NoSuchEntityException|\Magento\Framework\Exception\CouldNotSaveException * @return bool + * + * @deprecated + * @see \Magento\Catalog\Api\ProductCustomOptionManagementInterface::remove */ public function remove($productSku, $optionId); @@ -44,6 +52,9 @@ public function remove($productSku, $optionId); * @return \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\CouldNotSaveException + * + * @deprecated + * @see \Magento\Catalog\Api\ProductCustomOptionManagementInterface::add */ public function add($productSku, \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option $option); @@ -55,6 +66,9 @@ public function add($productSku, \Magento\Catalog\Service\V1\Product\CustomOptio * @param \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option $option * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException + * + * @deprecated + * @see \Magento\Catalog\Api\ProductCustomOptionManagementInterface::update */ public function update( $productSku, diff --git a/app/code/Magento/Catalog/Service/V1/Product/GroupPriceService.php b/app/code/Magento/Catalog/Service/V1/Product/GroupPriceService.php index e8bb6563cfa8c..c657220dec0c5 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/GroupPriceService.php +++ b/app/code/Magento/Catalog/Service/V1/Product/GroupPriceService.php @@ -48,9 +48,9 @@ class GroupPriceService implements GroupPriceServiceInterface protected $storeManager; /** - * @var \Magento\Customer\Service\V1\CustomerGroupServiceInterface + * @var \Magento\Customer\Api\GroupRepositoryInterface */ - protected $customerGroupService; + protected $groupRepository; /** * @var \Magento\Catalog\Model\Product\PriceModifier @@ -66,7 +66,7 @@ class GroupPriceService implements GroupPriceServiceInterface * @param ProductRepository $productRepository * @param Product\GroupPriceBuilder $groupPriceBuilder * @param \Magento\Framework\StoreManagerInterface $storeManager - * @param \Magento\Customer\Service\V1\CustomerGroupServiceInterface $customerGroupService + * @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository * @param \Magento\Catalog\Model\Product\PriceModifier $priceModifier * @param \Magento\Framework\App\Config\ScopeConfigInterface $config */ @@ -74,14 +74,14 @@ public function __construct( ProductRepository $productRepository, Product\GroupPriceBuilder $groupPriceBuilder, \Magento\Framework\StoreManagerInterface $storeManager, - \Magento\Customer\Service\V1\CustomerGroupServiceInterface $customerGroupService, + \Magento\Customer\Api\GroupRepositoryInterface $groupRepository, \Magento\Catalog\Model\Product\PriceModifier $priceModifier, \Magento\Framework\App\Config\ScopeConfigInterface $config ) { $this->productRepository = $productRepository; $this->groupPriceBuilder = $groupPriceBuilder; $this->storeManager = $storeManager; - $this->customerGroupService = $customerGroupService; + $this->groupRepository = $groupRepository; $this->priceModifier = $priceModifier; $this->config = $config; } @@ -94,8 +94,8 @@ public function __construct( */ public function set($productSku, \Magento\Catalog\Service\V1\Data\Product\GroupPrice $price) { - $customerGroup = $this->customerGroupService->getGroup($price->getCustomerGroupId()); - $product = $this->productRepository->get($productSku, true); + $customerGroup = $this->groupRepository->getById($price->getCustomerGroupId()); + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); $groupPrices = $product->getData('group_price'); $websiteId = 0; @@ -141,7 +141,7 @@ public function set($productSku, \Magento\Catalog\Service\V1\Data\Product\GroupP */ public function delete($productSku, $customerGroupId) { - $product = $this->productRepository->get($productSku, true); + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { $websiteId = 0; } else { @@ -156,7 +156,7 @@ public function delete($productSku, $customerGroupId) */ public function getList($productSku) { - $product = $this->productRepository->get($productSku, true); + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); $priceKey = 'website_price'; if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { $priceKey = 'price'; diff --git a/app/code/Magento/Catalog/Service/V1/Product/GroupPriceServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/GroupPriceServiceInterface.php index fa8a40f81122c..139a090d2b53d 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/GroupPriceServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/GroupPriceServiceInterface.php @@ -24,6 +24,10 @@ */ namespace Magento\Catalog\Service\V1\Product; +/** + * @todo remove this interface + * @see \Magento\Catalog\Api\ProductGroupPriceManagementInterface + */ interface GroupPriceServiceInterface { /** @@ -34,6 +38,8 @@ interface GroupPriceServiceInterface * @return boolean * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException + * @deprecated + * @see \Magento\Catalog\Api\ProductGroupPriceManagementInterface::add */ public function set($productSku, \Magento\Catalog\Service\V1\Data\Product\GroupPrice $price); @@ -45,6 +51,8 @@ public function set($productSku, \Magento\Catalog\Service\V1\Data\Product\GroupP * @return boolean * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException + * @deprecated + * @see \Magento\Catalog\Api\ProductGroupPriceManagementInterface::remove */ public function delete($productSku, $customerGroupId); @@ -54,6 +62,8 @@ public function delete($productSku, $customerGroupId); * @param string $productSku * @return \Magento\Catalog\Service\V1\Data\Product\GroupPrice[] * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Catalog\Api\ProductGroupPriceManagementInterface::getList */ public function getList($productSku); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttribute.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttribute.php index 33809b9a546c3..d312358ca99b2 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttribute.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttribute.php @@ -28,6 +28,8 @@ * LinkAttribute Service Data Object * * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\ProductLinkAttributeInterface */ class LinkAttribute extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php index 89d9d939f7d0b..50db1b46b5009 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php @@ -28,6 +28,8 @@ * LinkType Service Data Object * * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\ProductLinkTypeInterface */ class LinkType extends \Magento\Framework\Api\AbstractExtensibleObject { diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php index 8af1173061128..9a567825d7677 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php @@ -28,6 +28,8 @@ * ProductLink Service Data Object * * @codeCoverageIgnore + * @deprecated + * @see \Magento\Catalog\Api\Data\ProductLinkInterface */ class ProductLink extends \Magento\Framework\Api\AbstractExtensibleObject { @@ -35,7 +37,6 @@ class ProductLink extends \Magento\Framework\Api\AbstractExtensibleObject * Constants for Data Object keys */ const TYPE = 'type'; - const ATTRIBUTE_SET_ID = 'attribute_set_id'; const SKU = 'sku'; const POSITION = 'position'; diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php index b4b2837552159..1fc840df2ea39 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php @@ -57,12 +57,12 @@ class ReadService implements ReadServiceInterface protected $linkTypeResolver; /** - * @var Data\ProductLinkBuilder + * @var \Magento\Catalog\Model\Product\Link\ProductLinkBuilder */ protected $productEntityBuilder; /** - * @var Data\ProductLink\CollectionProvider + * @var \Magento\Catalog\Model\ProductLink\CollectionProvider */ protected $entityCollectionProvider; @@ -79,9 +79,9 @@ class ReadService implements ReadServiceInterface /** * @param LinkTypeProvider $linkTypeProvider * @param Data\LinkTypeBuilder $builder - * @param Data\ProductLinkBuilder $productEntityBuilder + * @param \Magento\Catalog\Service\V1\Product\Link\Data\ProductLinkBuilder $productEntityBuilder * @param ProductLoader $productLoader - * @param ProductLink\CollectionProvider $entityCollectionProvider + * @param \Magento\Catalog\Model\ProductLink\CollectionProvider $entityCollectionProvider * @param Data\LinkAttributeBuilder $linkAttributeBuilder * @param \Magento\Catalog\Model\Product\LinkFactory $linkFactory * @param LinkTypeResolver $linkTypeResolver @@ -89,9 +89,9 @@ class ReadService implements ReadServiceInterface public function __construct( LinkTypeProvider $linkTypeProvider, Data\LinkTypeBuilder $builder, - Data\ProductLinkBuilder $productEntityBuilder, + \Magento\Catalog\Service\V1\Product\Link\Data\ProductLinkBuilder $productEntityBuilder, ProductLoader $productLoader, - Data\ProductLink\CollectionProvider $entityCollectionProvider, + \Magento\Catalog\Model\ProductLink\CollectionProvider $entityCollectionProvider, Data\LinkAttributeBuilder $linkAttributeBuilder, \Magento\Catalog\Model\Product\LinkFactory $linkFactory, LinkTypeResolver $linkTypeResolver diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php index 9a063cc52100d..1bc605044b000 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php @@ -24,12 +24,18 @@ namespace Magento\Catalog\Service\V1\Product\Link; +/** + * @todo remove this interface + * @deprecated + */ interface ReadServiceInterface { /** * Provide the list of product link types * * @return \Magento\Catalog\Service\V1\Product\Link\Data\LinkType[] + * @deprecated + * @see \Magento\Catalog\Api\Product\Link\ProductLinkTypeListInterface::getItems */ public function getProductLinkTypes(); @@ -40,6 +46,9 @@ public function getProductLinkTypes(); * @param string $type * @throws \Magento\Framework\Exception\NoSuchEntityException * @return \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink[] + * + * @deprecated + * @see \Magento\Catalog\Api\ProductLinkManagementInterface::getList */ public function getLinkedProducts($productSku, $type); @@ -49,6 +58,9 @@ public function getLinkedProducts($productSku, $type); * @param string $type * @throws \Magento\Framework\Exception\NoSuchEntityException * @return \Magento\Catalog\Service\V1\Product\Link\Data\LinkAttribute[] + * + * @deprecated + * @see \Magento\Catalog\Api\Product\Link\ProductLinkTypeListInterface::getItemAttributes */ public function getLinkAttributes($type); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/WriteService.php b/app/code/Magento/Catalog/Service/V1/Product/Link/WriteService.php index 686e986983f2e..db10e74ffc0d9 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Link/WriteService.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/WriteService.php @@ -55,23 +55,23 @@ class WriteService implements WriteServiceInterface protected $productResource; /** - * @var Data\ProductLink\DataMapperInterface + * @var \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\DataMapperInterface */ protected $dataMapper; /** * @param LinksInitializer $linkInitializer - * @param ProductLink\CollectionProvider $entityCollectionProvider + * @param \Magento\Catalog\Model\ProductLink\CollectionProvider $entityCollectionProvider * @param ProductLoader $productLoader * @param ProductResource $productResource - * @param ProductLink\DataMapperInterface $dataMapper + * @param \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\DataMapperInterface $dataMapper */ public function __construct( LinksInitializer $linkInitializer, - ProductLink\CollectionProvider $entityCollectionProvider, + \Magento\Catalog\Model\ProductLink\CollectionProvider $entityCollectionProvider, ProductLoader $productLoader, ProductResource $productResource, - Data\ProductLink\DataMapperInterface $dataMapper + \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\DataMapperInterface $dataMapper ) { $this->linkInitializer = $linkInitializer; $this->entityCollectionProvider = $entityCollectionProvider; @@ -175,8 +175,12 @@ public function remove($productSku, $linkedProductSku, $type) //Remove product from the linked product list unset($links[$linkedProduct->getId()]); - $this->saveLinks($product, [$type => $links]); - + $this->linkInitializer->initializeLinks($product, $links); + try { + $product->save(); + } catch (\Exception $exception) { + throw new CouldNotSaveException('Invalid data provided for linked products'); + } return true; } } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php index f4a4569616120..2420003a4ecac 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php @@ -24,6 +24,10 @@ namespace Magento\Catalog\Service\V1\Product\Link; +/** + * @todo remove this interface + * @deprecated + */ interface WriteServiceInterface { /** @@ -35,6 +39,9 @@ interface WriteServiceInterface * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException * @return bool + * + * @deprecated + * @see \Magento\Catalog\Api\ProductLinkManagementInterface::assign */ public function assign($productSku, array $assignedProducts, $type); @@ -47,6 +54,9 @@ public function assign($productSku, array $assignedProducts, $type); * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException * @return bool + * + * @deprecated + * @see \Magento\Catalog\Api\ProductLinkManagementInterface::update */ public function update($productSku, Data\ProductLink $linkedProduct, $type); @@ -59,6 +69,9 @@ public function update($productSku, Data\ProductLink $linkedProduct, $type); * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException * @return bool + * + * @deprecated + * @see \Magento\Catalog\Api\ProductLinkManagementInterface::remove */ public function remove($productSku, $linkedProductSku, $type); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/MetadataServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/MetadataServiceInterface.php index ad2ecd32ed96d..f1b69ebb5bac7 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/MetadataServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/MetadataServiceInterface.php @@ -25,6 +25,8 @@ /** * Class Product MetadataServiceInterface + * @deprecated + * @see \Magento\Catalog\Api\Product\Attribute\MetadataRepositoryInterface */ interface MetadataServiceInterface extends \Magento\Framework\Api\MetadataServiceInterface { diff --git a/app/code/Magento/Catalog/Service/V1/Product/TierPriceService.php b/app/code/Magento/Catalog/Service/V1/Product/TierPriceService.php index 51f3a20764c6c..efacfc13c7fb4 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/TierPriceService.php +++ b/app/code/Magento/Catalog/Service/V1/Product/TierPriceService.php @@ -26,9 +26,13 @@ use Magento\Catalog\Model\ProductFactory; use Magento\Catalog\Model\ProductRepository; use Magento\Catalog\Service\V1\Data\Product; +use Magento\Customer\Api\GroupManagementInterface; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\InputException; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class TierPriceService implements TierPriceServiceInterface { /** @@ -57,9 +61,14 @@ class TierPriceService implements TierPriceServiceInterface protected $config; /** - * @var \Magento\Customer\Service\V1\CustomerGroupServiceInterface + * @var \Magento\Customer\Api\GroupRepositoryInterface + */ + protected $groupRepository; + + /** + * @var GroupManagementInterface */ - protected $customerGroupService; + protected $groupManagement; /** * @param ProductRepository $productRepository @@ -67,7 +76,8 @@ class TierPriceService implements TierPriceServiceInterface * @param \Magento\Framework\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Product\PriceModifier $priceModifier * @param \Magento\Framework\App\Config\ScopeConfigInterface $config - * @param \Magento\Customer\Service\V1\CustomerGroupServiceInterface $customerGroupService + * @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository + * @param GroupManagementInterface $groupManagement */ public function __construct( ProductRepository $productRepository, @@ -75,14 +85,16 @@ public function __construct( \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Product\PriceModifier $priceModifier, \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Customer\Service\V1\CustomerGroupServiceInterface $customerGroupService + \Magento\Customer\Api\GroupRepositoryInterface $groupRepository, + GroupManagementInterface $groupManagement ) { $this->productRepository = $productRepository; $this->priceBuilder = $priceBuilder; $this->storeManager = $storeManager; $this->priceModifier = $priceModifier; $this->config = $config; - $this->customerGroupService = $customerGroupService; + $this->groupRepository = $groupRepository; + $this->groupManagement = $groupManagement; } /** @@ -92,7 +104,7 @@ public function __construct( */ public function set($productSku, $customerGroupId, \Magento\Catalog\Service\V1\Data\Product\TierPrice $price) { - $product = $this->productRepository->get($productSku, true); + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); $tierPrices = $product->getData('tier_price'); $websiteId = 0; @@ -117,8 +129,8 @@ public function set($productSku, $customerGroupId, \Magento\Catalog\Service\V1\D } if (!$found) { $mappedCustomerGroupId = 'all' == $customerGroupId - ? \Magento\Customer\Service\V1\CustomerGroupServiceInterface::CUST_GROUP_ALL - : $this->customerGroupService->getGroup($customerGroupId)->getId(); + ? $this->groupManagement->getAllCustomersGroup()->getId() + : $this->groupRepository->getById($customerGroupId)->getId(); $tierPrices[] = array( 'cust_group' => $mappedCustomerGroupId, @@ -150,7 +162,7 @@ public function set($productSku, $customerGroupId, \Magento\Catalog\Service\V1\D */ public function delete($productSku, $customerGroupId, $qty) { - $product = $this->productRepository->get($productSku, true); + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { $websiteId = 0; } else { @@ -165,7 +177,7 @@ public function delete($productSku, $customerGroupId, $qty) */ public function getList($productSku, $customerGroupId) { - $product = $this->productRepository->get($productSku, true); + $product = $this->productRepository->get($productSku, ['edit_mode' => true]); $priceKey = 'website_price'; if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) == 0) { diff --git a/app/code/Magento/Catalog/Service/V1/Product/TierPriceServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/TierPriceServiceInterface.php index 83a941fdd5cdc..ad1bc1cfa8cd4 100644 --- a/app/code/Magento/Catalog/Service/V1/Product/TierPriceServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/Product/TierPriceServiceInterface.php @@ -24,6 +24,10 @@ */ namespace Magento\Catalog\Service\V1\Product; +/** + * @todo remove this interface + * @see \Magento\Catalog\Api\Product\TierPriceManagementInterface + */ interface TierPriceServiceInterface { /** @@ -35,6 +39,8 @@ interface TierPriceServiceInterface * @return boolean * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException + * @deprecated + * @see \Magento\Catalog\Api\ProductTierPriceManagementInterface::add */ public function set($productSku, $customerGroupId, \Magento\Catalog\Service\V1\Data\Product\TierPrice $price); @@ -47,6 +53,8 @@ public function set($productSku, $customerGroupId, \Magento\Catalog\Service\V1\D * @return boolean * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException + * @deprecated + * @see \Magento\Catalog\Api\ProductTierPriceManagementInterface::remove */ public function delete($productSku, $customerGroupId, $qty); @@ -57,6 +65,8 @@ public function delete($productSku, $customerGroupId, $qty); * @param string $customerGroupId * @return \Magento\Catalog\Service\V1\Data\Product\TierPrice[] * @throws \Magento\Framework\Exception\NoSuchEntityException + * @deprecated + * @see \Magento\Catalog\Api\ProductTierPriceManagementInterface::getList */ public function getList($productSku, $customerGroupId); } diff --git a/app/code/Magento/Catalog/Service/V1/ProductService.php b/app/code/Magento/Catalog/Service/V1/ProductService.php index 6f253cd2fe685..1a202172cc625 100644 --- a/app/code/Magento/Catalog/Service/V1/ProductService.php +++ b/app/code/Magento/Catalog/Service/V1/ProductService.php @@ -34,6 +34,7 @@ /** * Class ProductService + * @deprecated * @package Magento\Catalog\Service\V1 * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ diff --git a/app/code/Magento/Catalog/Service/V1/ProductServiceInterface.php b/app/code/Magento/Catalog/Service/V1/ProductServiceInterface.php index b5336b43e6c0d..5eea05795a697 100644 --- a/app/code/Magento/Catalog/Service/V1/ProductServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/ProductServiceInterface.php @@ -26,6 +26,8 @@ /** * Class ProductServiceInterface * @package Magento\Catalog\Service\V1 + * @deprecated + * @todo remove this interface */ interface ProductServiceInterface { @@ -35,6 +37,8 @@ interface ProductServiceInterface * @param string $id * @throws \Magento\Framework\Exception\NoSuchEntityException If ID is not found * @return \Magento\Catalog\Service\V1\Data\Product $product + * @deprecated + * @see \Magento\Catalog\Api\ProductRepositoryInterface::get */ public function get($id); @@ -45,6 +49,8 @@ public function get($id); * @throws \Magento\Framework\Exception\NoSuchEntityException If ID is not found * @throws \Exception If something goes wrong during delete * @return bool True if the entity was deleted (always true) + * @deprecated + * @see \Magento\Catalog\Api\ProductRepositoryInterface::delete */ public function delete($id); @@ -56,6 +62,8 @@ public function delete($id); * @throws \Magento\Framework\Exception\NoSuchEntityException If a ID is sent but the entity does not exist * @throws \Magento\Framework\Model\Exception If something goes wrong during save * @return string id + * @deprecated + * @see \Magento\Catalog\Api\ProductRepositoryInterface::save */ public function create(\Magento\Catalog\Service\V1\Data\Product $product); @@ -68,6 +76,8 @@ public function create(\Magento\Catalog\Service\V1\Data\Product $product); * @throws \Magento\Framework\Exception\NoSuchEntityException If a ID is sent but the entity does not exist * @throws \Magento\Framework\Model\Exception If something goes wrong during save * @return string id + * @deprecated + * @see \Magento\Catalog\Api\ProductManagementInterface::update */ public function update($id, \Magento\Catalog\Service\V1\Data\Product $product); @@ -76,6 +86,8 @@ public function update($id, \Magento\Catalog\Service\V1\Data\Product $product); * * @param \Magento\Framework\Api\SearchCriteria $searchCriteria * @return \Magento\Catalog\Service\V1\Data\Product\SearchResults containing Data\Product objects + * @deprecated + * @see \Magento\Catalog\Api\ProductRepositoryInterface::getList */ public function search(\Magento\Framework\Api\SearchCriteria $searchCriteria); } diff --git a/app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php b/app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php index 9ad7a4011b5ea..95ca2bffd0c10 100644 --- a/app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php +++ b/app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php @@ -25,12 +25,17 @@ */ namespace Magento\Catalog\Service\V1; +/** + * @deprecated + */ interface ProductTypeServiceInterface { /** * Retrieve the list of product types * * @return \Magento\Catalog\Service\V1\Data\ProductType[] + * @deprecated + * @see \Magento\Catalog\Api\ProductTypeListInterface::getProductTypes */ public function getProductTypes(); } diff --git a/app/code/Magento/Catalog/composer.json b/app/code/Magento/Catalog/composer.json index 72024bf3461e2..6e4e4ae54c50d 100644 --- a/app/code/Magento/Catalog/composer.json +++ b/app/code/Magento/Catalog/composer.json @@ -3,33 +3,33 @@ "description": "N/A", "require": { "php": "~5.4.11|~5.5.0", - "magento/module-store": "0.1.0-alpha105", - "magento/module-eav": "0.1.0-alpha105", - "magento/module-cms": "0.1.0-alpha105", - "magento/module-indexer": "0.1.0-alpha105", - "magento/module-customer": "0.1.0-alpha105", - "magento/module-core": "0.1.0-alpha105", - "magento/module-theme": "0.1.0-alpha105", - "magento/module-checkout": "0.1.0-alpha105", - "magento/module-log": "0.1.0-alpha105", - "magento/module-backend": "0.1.0-alpha105", - "magento/module-widget": "0.1.0-alpha105", - "magento/module-wishlist": "0.1.0-alpha105", - "magento/module-tax": "0.1.0-alpha105", - "magento/module-msrp": "0.1.0-alpha105", - "magento/module-catalog-inventory": "0.1.0-alpha105", - "magento/module-directory": "0.1.0-alpha105", - "magento/module-catalog-rule": "0.1.0-alpha105", - "magento/module-sales": "0.1.0-alpha105", - "magento/module-product-alert": "0.1.0-alpha105", - "magento/module-url-rewrite": "0.1.0-alpha105", - "magento/module-catalog-url-rewrite": "0.1.0-alpha105", - "magento/module-page-cache": "0.1.0-alpha105", - "magento/framework": "0.1.0-alpha105", + "magento/module-store": "0.1.0-alpha106", + "magento/module-eav": "0.1.0-alpha106", + "magento/module-cms": "0.1.0-alpha106", + "magento/module-indexer": "0.1.0-alpha106", + "magento/module-customer": "0.1.0-alpha106", + "magento/module-core": "0.1.0-alpha106", + "magento/module-theme": "0.1.0-alpha106", + "magento/module-checkout": "0.1.0-alpha106", + "magento/module-log": "0.1.0-alpha106", + "magento/module-backend": "0.1.0-alpha106", + "magento/module-widget": "0.1.0-alpha106", + "magento/module-wishlist": "0.1.0-alpha106", + "magento/module-tax": "0.1.0-alpha106", + "magento/module-msrp": "0.1.0-alpha106", + "magento/module-catalog-inventory": "0.1.0-alpha106", + "magento/module-directory": "0.1.0-alpha106", + "magento/module-catalog-rule": "0.1.0-alpha106", + "magento/module-sales": "0.1.0-alpha106", + "magento/module-product-alert": "0.1.0-alpha106", + "magento/module-url-rewrite": "0.1.0-alpha106", + "magento/module-catalog-url-rewrite": "0.1.0-alpha106", + "magento/module-page-cache": "0.1.0-alpha106", + "magento/framework": "0.1.0-alpha106", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.1.0-alpha105", + "version": "0.1.0-alpha106", "extra": { "map": [ [ diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-install-1.6.0.0.php b/app/code/Magento/Catalog/data/catalog_setup/data-install-1.6.0.0.php deleted file mode 100644 index 451386d11d2d5..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-install-1.6.0.0.php +++ /dev/null @@ -1,166 +0,0 @@ -installEntities(); -// Create Root Catalog Node -$installer->createCategory()->load( - 1 -)->setId( - 1 -)->setStoreId( - 0 -)->setPath( - 1 -)->setLevel( - 0 -)->setPosition( - 0 -)->setChildrenCount( - 0 -)->setName( - 'Root Catalog' -)->setInitialSetupFlag( - true -)->save(); - -$category = $installer->createCategory(); - -$installer->createCategory()->setStoreId( - 0 -)->setName( - 'Default Category' -)->setDisplayMode( - 'PRODUCTS' -)->setAttributeSetId( - $category->getDefaultAttributeSetId() -)->setIsActive( - 1 -)->setPath( - '1' -)->setInitialSetupFlag( - true -)->save(); - -$data = array( - 'scope' => 'default', - 'scope_id' => 0, - 'path' => \Magento\Catalog\Helper\Category::XML_PATH_CATEGORY_ROOT_ID, - 'value' => $category->getId() -); -$installer->getConnection()->insertOnDuplicate($installer->getTable('core_config_data'), $data, array('value')); - -$installer->addAttributeGroup(\Magento\Catalog\Model\Product::ENTITY, 'Default', 'Design', 6); - -$entityTypeId = $installer->getEntityTypeId(\Magento\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' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED, 'code' => 'relation'), - array('link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL, 'code' => 'up_sell'), - array('link_type_id' => \Magento\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' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED, - 'product_link_attribute_code' => 'position', - 'data_type' => 'int' - ), - array( - 'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL, - 'product_link_attribute_code' => 'position', - 'data_type' => 'int' - ), - array( - 'link_type_id' => \Magento\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/Magento/Catalog/data/catalog_setup/data-install-2.0.0.php b/app/code/Magento/Catalog/data/catalog_setup/data-install-2.0.0.php new file mode 100644 index 0000000000000..a73fd8a6791ba --- /dev/null +++ b/app/code/Magento/Catalog/data/catalog_setup/data-install-2.0.0.php @@ -0,0 +1,267 @@ +installEntities(); +// Create Root Catalog Node +$installer->createCategory() + ->load(1) + ->setId(1) + ->setStoreId(0) + ->setPath(1) + ->setLevel(0) + ->setPosition(0) + ->setChildrenCount(0) + ->setName('Root Catalog') + ->setInitialSetupFlag(true) + ->save(); + +$category = $installer->createCategory(); + +$installer->createCategory() + ->setStoreId(0) + ->setName('Default Category') + ->setDisplayMode('PRODUCTS') + ->setAttributeSetId($category->getDefaultAttributeSetId()) + ->setIsActive(1) + ->setPath('1') + ->setInitialSetupFlag(true) + ->save(); + +$data = [ + 'scope' => 'default', + 'scope_id' => 0, + 'path' => \Magento\Catalog\Helper\Category::XML_PATH_CATEGORY_ROOT_ID, + 'value' => $category->getId() +]; +$installer->getConnection() + ->insertOnDuplicate($installer->getTable('core_config_data'), $data, ['value']); + +$installer->addAttributeGroup(\Magento\Catalog\Model\Product::ENTITY, 'Default', 'Design', 6); + +$entityTypeId = $installer->getEntityTypeId(\Magento\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 = [ + 'display' => ['name' => 'Display Settings', 'sort' => 20, 'id' => null], + 'design' => ['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 = [ + 'custom_design' => ['group' => 'design', 'sort' => 10], + // 'custom_design_apply' => array('group' => 'design', 'sort' => 20), + 'custom_design_from' => ['group' => 'design', 'sort' => 30], + 'custom_design_to' => ['group' => 'design', 'sort' => 40], + 'page_layout' => ['group' => 'design', 'sort' => 50], + 'custom_layout_update' => ['group' => 'design', 'sort' => 60], + 'display_mode' => ['group' => 'display', 'sort' => 10], + 'landing_page' => ['group' => 'display', 'sort' => 20], + 'is_anchor' => ['group' => 'display', 'sort' => 30], + 'available_sort_by' => ['group' => 'display', 'sort' => 40], + 'default_sort_by' => ['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 = [ + ['link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED, 'code' => 'relation'], + ['link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL, 'code' => 'up_sell'], + ['link_type_id' => \Magento\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 = [ + [ + 'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED, + 'product_link_attribute_code' => 'position', + 'data_type' => 'int' + ], + [ + 'link_type_id' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL, + 'product_link_attribute_code' => 'position', + 'data_type' => 'int' + ], + [ + 'link_type_id' => \Magento\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']); +} + +$newGeneralTabName = 'Product Details'; +$newPriceTabName = 'Advanced Pricing'; +$newImagesTabName = 'Image Management'; +$newMetaTabName = 'Search Engine Optimization'; +$autosettingsTabName = 'Autosettings'; +$tabNames = [ + 'General' => [ + 'attribute_group_name' => $newGeneralTabName, + 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newGeneralTabName)), + 'tab_group_code' => 'basic', + 'sort_order' => 10 + ], + 'Images' => [ + 'attribute_group_name' => $newImagesTabName, + 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newImagesTabName)), + 'tab_group_code' => 'basic', + 'sort_order' => 20 + ], + 'Meta Information' => [ + 'attribute_group_name' => $newMetaTabName, + 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newMetaTabName)), + 'tab_group_code' => 'basic', + 'sort_order' => 30 + ], + 'Prices' => [ + 'attribute_group_name' => $newPriceTabName, + 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newPriceTabName)), + 'tab_group_code' => 'advanced', + 'sort_order' => 40 + ], + 'Design' => ['attribute_group_code' => 'design', 'tab_group_code' => 'advanced', 'sort_order' => 50] +]; + +$entityTypeId = $installer->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY); +$attributeSetId = $installer->getAttributeSetId($entityTypeId, 'Default'); + +//Rename attribute tabs +foreach ($tabNames as $tabName => $tab) { + $groupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, $tabName); + if ($groupId) { + foreach ($tab as $propertyName => $propertyValue) { + $installer->updateAttributeGroup($entityTypeId, $attributeSetId, $groupId, $propertyName, $propertyValue); + } + } +} + +//Add new tab +$installer->addAttributeGroup($entityTypeId, $attributeSetId, $autosettingsTabName, 60); +$installer->updateAttributeGroup( + $entityTypeId, + $attributeSetId, + 'Autosettings', + 'attribute_group_code', + 'autosettings' +); +$installer->updateAttributeGroup($entityTypeId, $attributeSetId, 'Autosettings', 'tab_group_code', 'advanced'); + +//New attributes order and properties +$properties = ['is_required', 'default_value', 'frontend_input_renderer']; +$attributesOrder = [ + //Product Details tab + 'name' => [$newGeneralTabName => 10], + 'sku' => [$newGeneralTabName => 20], + 'price' => [$newGeneralTabName => 30], + 'image' => [$newGeneralTabName => 50], + 'weight' => [$newGeneralTabName => 70, 'is_required' => 0], + 'category_ids' => [$newGeneralTabName => 80], + 'description' => [$newGeneralTabName => 90, 'is_required' => 0], + 'status' => [ + $newGeneralTabName => 100, + 'is_required' => 0, + 'default_value' => 1, + 'frontend_input_renderer' => 'Magento\Framework\Data\Form\Element\Hidden' + ], + //Autosettings tab + 'short_description' => [$autosettingsTabName => 0, 'is_required' => 0], + 'visibility' => [$autosettingsTabName => 20, 'is_required' => 0], + 'news_from_date' => [$autosettingsTabName => 30], + 'news_to_date' => [$autosettingsTabName => 40], + 'country_of_manufacture' => [$autosettingsTabName => 50] +]; + +foreach ($attributesOrder as $key => $value) { + $attribute = $installer->getAttribute($entityTypeId, $key); + if ($attribute) { + foreach ($value as $propertyName => $propertyValue) { + if (in_array($propertyName, $properties)) { + $installer->updateAttribute($entityTypeId, $attribute['attribute_id'], $propertyName, $propertyValue); + } else { + $installer->addAttributeToGroup( + $entityTypeId, + $attributeSetId, + $propertyName, + $attribute['attribute_id'], + $propertyValue + ); + } + } + } +} + +foreach (['status', 'visibility'] as $attributeCode) { + $installer->updateAttribute( + \Magento\Catalog\Model\Product::ENTITY, + $attributeCode, + 'is_required_in_admin_store', + '1' + ); +} diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.1-1.6.0.0.2.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.1-1.6.0.0.2.php deleted file mode 100644 index ec040bd6b70bb..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.1-1.6.0.0.2.php +++ /dev/null @@ -1,50 +0,0 @@ -addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'country_of_manufacture', - array( - 'group' => 'General', - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Country of Manufacture', - 'input' => 'select', - 'class' => '', - 'source' => 'Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture', - 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'simple,bundle' - ) -); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.10-1.6.0.0.11.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.10-1.6.0.0.11.php deleted file mode 100644 index f190e2ae49f21..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.10-1.6.0.0.11.php +++ /dev/null @@ -1,29 +0,0 @@ -getAttribute('catalog_product', 'group_price', 'attribute_id'); -$installer->updateAttribute('catalog_product', $attributeId, array(), null, 5); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.12-1.6.0.0.13.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.12-1.6.0.0.13.php deleted file mode 100644 index 56a8bc5542575..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.12-1.6.0.0.13.php +++ /dev/null @@ -1,61 +0,0 @@ -getAttribute('catalog_product', 'group_price', 'attribute_id'); -$priceAttrId = $installer->getAttribute('catalog_product', 'price', 'attribute_id'); -$connection = $installer->getConnection(); - -// update sort_order of Group Price attribute to be after Price -$select = $connection->select()->join( - array('t2' => $installer->getTable('eav_entity_attribute')), - 't1.attribute_group_id = t2.attribute_group_id', - array('sort_order' => new \Zend_Db_Expr('t2.sort_order + 1')) -)->where( - 't1.attribute_id = ?', - $groupPriceAttrId -)->where( - 't2.attribute_id = ?', - $priceAttrId -); -$query = $select->crossUpdateFromSelect(array('t1' => $installer->getTable('eav_entity_attribute'))); -$connection->query($query); - -// update sort_order of all other attributes to be after Group Price -$select = $connection->select()->join( - array('t2' => $installer->getTable('eav_entity_attribute')), - 't1.attribute_group_id = t2.attribute_group_id', - array('sort_order' => new \Zend_Db_Expr('t1.sort_order + 1')) -)->where( - 't1.attribute_id != ?', - $groupPriceAttrId -)->where( - 't1.sort_order >= t2.sort_order' -)->where( - 't2.attribute_id = ?', - $groupPriceAttrId -); -$query = $select->crossUpdateFromSelect(array('t1' => $installer->getTable('eav_entity_attribute'))); -$connection->query($query); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.13-1.6.0.0.14.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.13-1.6.0.0.14.php deleted file mode 100644 index 74639c8a0a559..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.13-1.6.0.0.14.php +++ /dev/null @@ -1,74 +0,0 @@ -getConnection(); - -$installer->startSetup(); - -$entityTypeId = $installer->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY); -$attributeId = $installer->getAttributeId($entityTypeId, 'filter_price_range'); -$attributeTableOld = $installer->getAttributeTable($entityTypeId, $attributeId); - -$installer->updateAttribute($entityTypeId, $attributeId, 'backend_type', 'decimal'); - -$attributeTableNew = $installer->getAttributeTable($entityTypeId, $attributeId); - -if ($attributeTableOld != $attributeTableNew) { - $connection->disableTableKeys($attributeTableOld)->disableTableKeys($attributeTableNew); - - $select = $connection->select()->from( - $attributeTableOld, - array('entity_type_id', 'attribute_id', 'store_id', 'entity_id', 'value') - )->where( - 'entity_type_id = ?', - $entityTypeId - )->where( - 'attribute_id = ?', - $attributeId - ); - - $query = $select->insertFromSelect( - $attributeTableNew, - array('entity_type_id', 'attribute_id', 'store_id', 'entity_id', 'value') - ); - - $connection->query($query); - - $connection->delete( - $attributeTableOld, - $connection->quoteInto( - 'entity_type_id = ?', - $entityTypeId - ) . $connection->quoteInto( - ' AND attribute_id = ?', - $attributeId - ) - ); - - $connection->enableTableKeys($attributeTableOld)->enableTableKeys($attributeTableNew); -} - -$installer->endSetup(); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.14-1.6.0.0.15.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.14-1.6.0.0.15.php deleted file mode 100644 index 96c255fff1b81..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.14-1.6.0.0.15.php +++ /dev/null @@ -1,35 +0,0 @@ -updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - $attributeCode, - 'backend_model', - 'Magento\Catalog\Model\Product\Attribute\Backend\Startdate' - ); -} diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.16-1.6.0.0.17.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.16-1.6.0.0.17.php deleted file mode 100644 index 64e3753492211..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.16-1.6.0.0.17.php +++ /dev/null @@ -1,58 +0,0 @@ -createMigrationSetup(); -$installer->startSetup(); - -$attributeData = $this->getAttribute('catalog_category', 'custom_layout_update'); -$installer->appendClassAliasReplace( - 'catalog_category_entity_text', - 'value', - \Magento\Framework\Module\Setup\Migration::ENTITY_TYPE_BLOCK, - \Magento\Framework\Module\Setup\Migration::FIELD_CONTENT_TYPE_XML, - array('value_id'), - 'attribute_id = ' . (int)$attributeData['attribute_id'] -); - -$attributeData = $this->getAttribute('catalog_product', 'custom_layout_update'); -$installer->appendClassAliasReplace( - 'catalog_product_entity_text', - 'value', - \Magento\Framework\Module\Setup\Migration::ENTITY_TYPE_BLOCK, - \Magento\Framework\Module\Setup\Migration::FIELD_CONTENT_TYPE_XML, - array('value_id'), - 'attribute_id = ' . (int)$attributeData['attribute_id'] -); - -$installer->appendClassAliasReplace( - 'catalog_eav_attribute', - 'frontend_input_renderer', - \Magento\Framework\Module\Setup\Migration::ENTITY_TYPE_BLOCK, - \Magento\Framework\Module\Setup\Migration::FIELD_CONTENT_TYPE_PLAIN, - array('attribute_id') -); -$installer->doUpdateClassAliases(); - -$installer->endSetup(); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.17-1.6.0.0.18.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.17-1.6.0.0.18.php deleted file mode 100644 index 6474ef2f3cf10..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.17-1.6.0.0.18.php +++ /dev/null @@ -1,66 +0,0 @@ -getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'category_ids'); -if ($attribute) { - $properties = array( - 'sort_order' => 9, - 'is_visible' => true, - 'frontend_label' => 'Categories', - 'input' => 'categories', - 'group' => 'General Information', - 'backend_model' => 'Magento\Catalog\Model\Product\Attribute\Backend\Category', - 'frontend_input_renderer' => 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category' - ); - foreach ($properties as $key => $value) { - $this->updateAttribute($attribute['entity_type_id'], $attribute['attribute_id'], $key, $value); - } -} - -$this->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'quantity_and_stock_status', - array( - 'group' => 'General', - 'type' => 'int', - 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Stock', - 'frontend' => '', - 'label' => 'Quantity', - 'input' => 'select', - 'class' => '', - 'input_renderer' => 'Magento\CatalogInventory\Block\Adminhtml\Form\Field\Stock', - 'source' => 'Magento\CatalogInventory\Model\Source\Stock', - 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL, - 'default' => \Magento\CatalogInventory\Model\Stock::STOCK_IN_STOCK, - 'user_defined' => false, - 'visible' => true, - 'required' => false, - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'unique' => false - ) -); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.18-1.6.0.0.19.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.18-1.6.0.0.19.php deleted file mode 100644 index ace9f91db52cf..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.18-1.6.0.0.19.php +++ /dev/null @@ -1,51 +0,0 @@ -getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'image'); - -if ($attribute) { - $this->addAttributeToGroup( - $attribute['entity_type_id'], - $this->getAttributeSetId($attribute['entity_type_id'], 'Default'), - 'General', - $attribute['attribute_id'], - 0 - ); - - $this->updateAttribute( - $attribute['entity_type_id'], - $attribute['attribute_id'], - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\BaseImage' - ); - - $this->updateAttribute( - $attribute['entity_type_id'], - $attribute['attribute_id'], - 'used_in_product_listing', - '1' - ); -} diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.19-1.6.0.0.20.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.19-1.6.0.0.20.php deleted file mode 100644 index f2bad46b5b70e..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.19-1.6.0.0.20.php +++ /dev/null @@ -1,37 +0,0 @@ -getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'weight', 'apply_to')), - array(\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL) -); - -$this->updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'weight', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight\Renderer' -); -$this->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'weight', 'apply_to', implode(',', $applyTo)); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.20-1.6.0.0.21.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.20-1.6.0.0.21.php deleted file mode 100644 index f8656fc61349e..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.20-1.6.0.0.21.php +++ /dev/null @@ -1,120 +0,0 @@ - array( - 'attribute_group_name' => $newGeneralTabName, - 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newGeneralTabName)), - 'tab_group_code' => 'basic', - 'sort_order' => 10 - ), - 'Images' => array( - 'attribute_group_name' => $newImagesTabName, - 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newImagesTabName)), - 'tab_group_code' => 'basic', - 'sort_order' => 20 - ), - 'Meta Information' => array( - 'attribute_group_name' => $newMetaTabName, - 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newMetaTabName)), - 'tab_group_code' => 'basic', - 'sort_order' => 30 - ), - 'Prices' => array( - 'attribute_group_name' => $newPriceTabName, - 'attribute_group_code' => preg_replace('/[^a-z0-9]+/', '-', strtolower($newPriceTabName)), - 'tab_group_code' => 'advanced', - 'sort_order' => 40 - ), - 'Design' => array('attribute_group_code' => 'design', 'tab_group_code' => 'advanced', 'sort_order' => 50) -); - -$entityTypeId = $this->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY); -$attributeSetId = $this->getAttributeSetId($entityTypeId, 'Default'); - -//Rename attribute tabs -foreach ($tabNames as $tabName => $tab) { - $groupId = $this->getAttributeGroupId($entityTypeId, $attributeSetId, $tabName); - if ($groupId) { - foreach ($tab as $propertyName => $propertyValue) { - $this->updateAttributeGroup($entityTypeId, $attributeSetId, $groupId, $propertyName, $propertyValue); - } - } -} - -//Add new tab -$this->addAttributeGroup($entityTypeId, $attributeSetId, $autosettingsTabName, 60); -$this->updateAttributeGroup($entityTypeId, $attributeSetId, 'Autosettings', 'attribute_group_code', 'autosettings'); -$this->updateAttributeGroup($entityTypeId, $attributeSetId, 'Autosettings', 'tab_group_code', 'advanced'); - -//New attributes order and properties -$properties = array('is_required', 'default_value', 'frontend_input_renderer'); -$attributesOrder = array( - //Product Details tab - 'name' => array($newGeneralTabName => 10), - 'sku' => array($newGeneralTabName => 20), - 'price' => array($newGeneralTabName => 30), - 'image' => array($newGeneralTabName => 50), - 'weight' => array($newGeneralTabName => 70, 'is_required' => 0), - 'category_ids' => array($newGeneralTabName => 80), - 'description' => array($newGeneralTabName => 90, 'is_required' => 0), - 'status' => array( - $newGeneralTabName => 100, - 'is_required' => 0, - 'default_value' => 1, - 'frontend_input_renderer' => 'Magento\Framework\Data\Form\Element\Hidden' - ), - //Autosettings tab - 'short_description' => array($autosettingsTabName => 0, 'is_required' => 0), - 'visibility' => array($autosettingsTabName => 20, 'is_required' => 0), - 'news_from_date' => array($autosettingsTabName => 30), - 'news_to_date' => array($autosettingsTabName => 40), - 'country_of_manufacture' => array($autosettingsTabName => 50) -); - -foreach ($attributesOrder as $key => $value) { - $attribute = $this->getAttribute($entityTypeId, $key); - if ($attribute) { - foreach ($value as $propertyName => $propertyValue) { - if (in_array($propertyName, $properties)) { - $this->updateAttribute($entityTypeId, $attribute['attribute_id'], $propertyName, $propertyValue); - } else { - $this->addAttributeToGroup( - $entityTypeId, - $attributeSetId, - $propertyName, - $attribute['attribute_id'], - $propertyValue - ); - } - } - } -} diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.21-1.6.0.0.22.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.21-1.6.0.0.22.php deleted file mode 100644 index ed4cab5cc3617..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.21-1.6.0.0.22.php +++ /dev/null @@ -1,56 +0,0 @@ -updateAttribute( - $this->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY), - 'weight', - 'backend_model', - 'Magento\Catalog\Model\Product\Attribute\Backend\Weight' -); -$this->updateAttribute( - $this->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY), - 'name', - 'frontend_class', - 'validate-length maximum-length-255' -); -$this->updateAttribute( - $this->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY), - 'sku', - 'frontend_class', - 'validate-length maximum-length-64' -); -$this->updateAttribute( - $this->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY), - 'qty', - 'frontend_class', - 'validate-number' -); -$this->updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'weight', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight' -); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.23-1.6.0.0.24.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.23-1.6.0.0.24.php deleted file mode 100644 index eaa6c462be4b1..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.23-1.6.0.0.24.php +++ /dev/null @@ -1,67 +0,0 @@ -updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'category_ids', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category' -); - -$this->updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'image', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\BaseImage' -); - -$this->updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'weight', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight' -); - -$this->updateAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'available_sort_by', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Category\Helper\Sortby\Available' -); - -$this->updateAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'default_sort_by', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Category\Helper\Sortby\DefaultSortby' -); - -$this->updateAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'filter_price_range', - 'frontend_input_renderer', - 'Magento\Catalog\Block\Adminhtml\Category\Helper\Pricestep' -); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.24-1.6.0.0.25.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.24-1.6.0.0.25.php deleted file mode 100644 index 1202e785c6b07..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.24-1.6.0.0.25.php +++ /dev/null @@ -1,31 +0,0 @@ -updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'status', - 'source_model', - 'Magento\Catalog\Model\Product\Attribute\Source\Status' -); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.27-1.6.0.0.28.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.27-1.6.0.0.28.php deleted file mode 100644 index 7258eeaaefe87..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.27-1.6.0.0.28.php +++ /dev/null @@ -1,28 +0,0 @@ -updateAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, 'is_required_in_admin_store', '1'); -} diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.28-1.6.0.0.29.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.28-1.6.0.0.29.php deleted file mode 100644 index e3fd6521cb6ba..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.28-1.6.0.0.29.php +++ /dev/null @@ -1,39 +0,0 @@ -getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY); -$attributeSetId = $this->getAttributeSetId($entityTypeId, 'Default'); -$groupId = $this->getAttributeGroupId($entityTypeId, $attributeSetId, $oldTabName); - -$this->updateAttributeGroup($entityTypeId, $attributeSetId, $groupId, 'attribute_group_name', $newTabName); -$this->updateAttributeGroup( - $entityTypeId, - $attributeSetId, - $groupId, - 'attribute_group_code', - preg_replace('/[^a-z0-9]+/', '-', strtolower($newTabName)) -); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.4-1.6.0.0.5.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.4-1.6.0.0.5.php deleted file mode 100644 index dc149b98540a7..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.4-1.6.0.0.5.php +++ /dev/null @@ -1,64 +0,0 @@ -createEavAttributeResource(); - -$multiSelectAttributeCodes = $eavResource->getAttributeCodesByFrontendType('multiselect'); - -foreach ($multiSelectAttributeCodes as $attributeCode) { - /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */ - $attribute = $installer->getAttribute('catalog_product', $attributeCode); - if ($attribute) { - $attributeTable = $installer->getAttributeTable('catalog_product', $attributeCode); - $select = $installer->getConnection()->select()->from( - array('e' => $attributeTable) - )->where( - "e.attribute_id=?", - $attribute['attribute_id'] - )->where( - 'e.value LIKE "%,,%"' - ); - $result = $installer->getConnection()->fetchAll($select); - - if ($result) { - foreach ($result as $row) { - if (isset($row['value']) && !empty($row['value'])) { - // 1,2,,,3,5 --> 1,2,3,5 - $row['value'] = preg_replace('/,{2,}/', ',', $row['value'], -1, $replaceCnt); - - if ($replaceCnt) { - $installer->getConnection()->update( - $attributeTable, - array('value' => $row['value']), - "value_id=" . $row['value_id'] - ); - } - } - } - } - } -} diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.5-1.6.0.0.6.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.5-1.6.0.0.6.php deleted file mode 100644 index 9e29094ab1cd3..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.5-1.6.0.0.6.php +++ /dev/null @@ -1,33 +0,0 @@ -updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'options_container', - 'frontend_label', - 'Display Product Options In' -); diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.8-1.6.0.0.9.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.8-1.6.0.0.9.php deleted file mode 100644 index 31afb374b12db..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.8-1.6.0.0.9.php +++ /dev/null @@ -1,38 +0,0 @@ -getAttribute('catalog_product', 'weight'); - -if ($attribute) { - $installer->updateAttribute( - $attribute['entity_type_id'], - $attribute['attribute_id'], - 'frontend_input', - $attribute['attribute_code'] - ); -} diff --git a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.9-1.6.0.0.10.php b/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.9-1.6.0.0.10.php deleted file mode 100644 index 7dbbc001ebc58..0000000000000 --- a/app/code/Magento/Catalog/data/catalog_setup/data-upgrade-1.6.0.0.9-1.6.0.0.10.php +++ /dev/null @@ -1,42 +0,0 @@ -addAttribute( - 'catalog_product', - 'group_price', - array( - 'type' => 'decimal', - 'label' => 'Group Price', - 'input' => 'text', - 'backend' => 'Magento\Catalog\Model\Product\Attribute\Backend\Groupprice', - 'required' => false, - 'sort_order' => 6, - 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE, - 'apply_to' => 'simple,virtual', - 'group' => 'Prices' - ) -); diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index fffae3fe39e52..eb3b702fd823e 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -26,13 +26,16 @@ - - + + + + + - + @@ -59,7 +62,6 @@ - @@ -68,6 +70,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -193,7 +218,7 @@ - + @@ -210,7 +235,7 @@ - + @@ -266,11 +291,6 @@ Magento\Catalog\Model\Indexer\Product\Flat\TableData - - - Magento\Catalog\Model\Layer\Category - - Magento\Catalog\Model\Layer\Category\FilterableAttributeList @@ -291,6 +311,11 @@ Magento\Catalog\Model\Layer\Search + + + Magento\Indexer\Model\IndexerInterface + + @@ -347,19 +372,19 @@ - + - Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider\Crosssell - Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider\Upsell - Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider\Related + Magento\Catalog\Model\ProductLink\CollectionProvider\Crosssell + Magento\Catalog\Model\ProductLink\CollectionProvider\Upsell + Magento\Catalog\Model\ProductLink\CollectionProvider\Related - + - \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\ProductEntity\DefaultConverter + Magento\Catalog\Model\ProductLink\Converter\DefaultConverter @@ -465,14 +490,83 @@ - + + + Magento\Catalog\Model\Product\Option\Type\File\ValidatorInfo\Proxy + Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile\Proxy + + + Magento\Catalog\Model\Layer\Search\ItemCollectionProvider Magento\Catalog\Model\Layer\Category\StateKey Magento\Catalog\Model\Layer\Search\CollectionFilter + + + + Magento\Catalog\Model\Layer\Category\ItemCollectionProvider + Magento\Catalog\Model\Layer\Category\StateKey + Magento\Catalog\Model\Layer\Category\CollectionFilter + + + + + Magento\Catalog\Model\Layer\Search\Context + + + + + Magento\Catalog\Model\Layer\Category\Context + + + + + + Magento\Catalog\Model\Layer\Filter\Dynamic\Auto + Magento\Catalog\Model\Layer\Filter\Dynamic\Improved + Magento\Catalog\Model\Layer\Filter\Dynamic\Manual + + + + + + + Magento\Catalog\Model\Layer\Category + Magento\Catalog\Model\Layer\Search + + + + + Magento\Catalog\Model\Category\AttributeRepository\Proxy + + + + + Magento\Catalog\Model\Product\Attribute\Repository\Proxy + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Catalog/etc/module.xml b/app/code/Magento/Catalog/etc/module.xml index 916a5eaf8a343..e5e324bb5fb56 100644 --- a/app/code/Magento/Catalog/etc/module.xml +++ b/app/code/Magento/Catalog/etc/module.xml @@ -24,7 +24,7 @@ */ --> - + diff --git a/app/code/Magento/Catalog/etc/webapi.xml b/app/code/Magento/Catalog/etc/webapi.xml index 6f3bd03167932..5d29ad8e5428e 100644 --- a/app/code/Magento/Catalog/etc/webapi.xml +++ b/app/code/Magento/Catalog/etc/webapi.xml @@ -25,400 +25,402 @@ --> + + - + - - + + - - + + - - + + - - + + + - + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - + - - + + - + - + - + - - + + - + - - + + - - + + - - + + - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - + + - + - + - - + + - + - + - - + + + + - - + + - - + + + + - + - - + + - + + - + - + - - + + - - + + - - + + - - + + - - + + + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Catalog/i18n/de_DE.csv b/app/code/Magento/Catalog/i18n/de_DE.csv index 5248fb6353e76..8b0df7438ce01 100644 --- a/app/code/Magento/Catalog/i18n/de_DE.csv +++ b/app/code/Magento/Catalog/i18n/de_DE.csv @@ -255,7 +255,6 @@ Categories,Kategorien "A total of %1 record(s) have been updated.","A total of %1 record(s) have been updated." "Something went wrong while updating the product(s) status.","Something went wrong while updating the product(s) status." "Please make sure to define SKU values for all processed products.","Please make sure to define SKU values for all processed products." -"Please refresh "Product EAV" in System -> Index Management.","Please refresh "Product EAV" in System -> Index Management." "A total of %1 record(s) were updated.","A total of %1 record(s) were updated." "Something went wrong while updating the product(s) attributes.","Something went wrong while updating the product(s) attributes." "Please select products for attributes update.","Please select products for attributes update." diff --git a/app/code/Magento/Catalog/i18n/en_US.csv b/app/code/Magento/Catalog/i18n/en_US.csv index 5887784287b99..2cfe7083932dd 100644 --- a/app/code/Magento/Catalog/i18n/en_US.csv +++ b/app/code/Magento/Catalog/i18n/en_US.csv @@ -255,7 +255,6 @@ Categories,Categories "A total of %1 record(s) have been updated.","A total of %1 record(s) have been updated." "Something went wrong while updating the product(s) status.","Something went wrong while updating the product(s) status." "Please make sure to define SKU values for all processed products.","Please make sure to define SKU values for all processed products." -"Please refresh "Product EAV" in System -> Index Management.","Please refresh "Product EAV" in System -> Index Management." "A total of %1 record(s) were updated.","A total of %1 record(s) were updated." "Something went wrong while updating the product(s) attributes.","Something went wrong while updating the product(s) attributes." "Please select products for attributes update.","Please select products for attributes update." diff --git a/app/code/Magento/Catalog/i18n/es_ES.csv b/app/code/Magento/Catalog/i18n/es_ES.csv index d86c9b05058a1..83b48a5ad10cb 100644 --- a/app/code/Magento/Catalog/i18n/es_ES.csv +++ b/app/code/Magento/Catalog/i18n/es_ES.csv @@ -255,7 +255,6 @@ Categories,Categorías "A total of %1 record(s) have been updated.","A total of %1 record(s) have been updated." "Something went wrong while updating the product(s) status.","Something went wrong while updating the product(s) status." "Please make sure to define SKU values for all processed products.","Please make sure to define SKU values for all processed products." -"Please refresh "Product EAV" in System -> Index Management.","Please refresh "Product EAV" in System -> Index Management." "A total of %1 record(s) were updated.","A total of %1 record(s) were updated." "Something went wrong while updating the product(s) attributes.","Something went wrong while updating the product(s) attributes." "Please select products for attributes update.","Please select products for attributes update." diff --git a/app/code/Magento/Catalog/i18n/fr_FR.csv b/app/code/Magento/Catalog/i18n/fr_FR.csv index 4c2595d01bf68..62cb82be60950 100644 --- a/app/code/Magento/Catalog/i18n/fr_FR.csv +++ b/app/code/Magento/Catalog/i18n/fr_FR.csv @@ -255,7 +255,6 @@ Categories,catégories "A total of %1 record(s) have been updated.","A total of %1 record(s) have been updated." "Something went wrong while updating the product(s) status.","Something went wrong while updating the product(s) status." "Please make sure to define SKU values for all processed products.","Please make sure to define SKU values for all processed products." -"Please refresh "Product EAV" in System -> Index Management.","Please refresh "Product EAV" in System -> Index Management." "A total of %1 record(s) were updated.","A total of %1 record(s) were updated." "Something went wrong while updating the product(s) attributes.","Something went wrong while updating the product(s) attributes." "Please select products for attributes update.","Please select products for attributes update." diff --git a/app/code/Magento/Catalog/i18n/nl_NL.csv b/app/code/Magento/Catalog/i18n/nl_NL.csv index 8a3940a19a4e9..ee1eb9baee9d9 100644 --- a/app/code/Magento/Catalog/i18n/nl_NL.csv +++ b/app/code/Magento/Catalog/i18n/nl_NL.csv @@ -255,7 +255,6 @@ Categories,Categoriën "A total of %1 record(s) have been updated.","A total of %1 record(s) have been updated." "Something went wrong while updating the product(s) status.","Something went wrong while updating the product(s) status." "Please make sure to define SKU values for all processed products.","Please make sure to define SKU values for all processed products." -"Please refresh "Product EAV" in System -> Index Management.","Please refresh "Product EAV" in System -> Index Management." "A total of %1 record(s) were updated.","A total of %1 record(s) were updated." "Something went wrong while updating the product(s) attributes.","Something went wrong while updating the product(s) attributes." "Please select products for attributes update.","Please select products for attributes update." diff --git a/app/code/Magento/Catalog/i18n/pt_BR.csv b/app/code/Magento/Catalog/i18n/pt_BR.csv index 5717e8f7b64b1..3e0887c87547d 100644 --- a/app/code/Magento/Catalog/i18n/pt_BR.csv +++ b/app/code/Magento/Catalog/i18n/pt_BR.csv @@ -255,7 +255,6 @@ Categories,Categorias "A total of %1 record(s) have been updated.","A total of %1 record(s) have been updated." "Something went wrong while updating the product(s) status.","Something went wrong while updating the product(s) status." "Please make sure to define SKU values for all processed products.","Please make sure to define SKU values for all processed products." -"Please refresh "Product EAV" in System -> Index Management.","Please refresh "Product EAV" in System -> Index Management." "A total of %1 record(s) were updated.","A total of %1 record(s) were updated." "Something went wrong while updating the product(s) attributes.","Something went wrong while updating the product(s) attributes." "Please select products for attributes update.","Please select products for attributes update." diff --git a/app/code/Magento/Catalog/i18n/zh_CN.csv b/app/code/Magento/Catalog/i18n/zh_CN.csv index 9a431375ea5e7..4774b64706d9a 100644 --- a/app/code/Magento/Catalog/i18n/zh_CN.csv +++ b/app/code/Magento/Catalog/i18n/zh_CN.csv @@ -255,7 +255,6 @@ Categories,分类 "A total of %1 record(s) have been updated.","A total of %1 record(s) have been updated." "Something went wrong while updating the product(s) status.","Something went wrong while updating the product(s) status." "Please make sure to define SKU values for all processed products.","Please make sure to define SKU values for all processed products." -"Please refresh "Product EAV" in System -> Index Management.","Please refresh "Product EAV" in System -> Index Management." "A total of %1 record(s) were updated.","A total of %1 record(s) were updated." "Something went wrong while updating the product(s) attributes.","Something went wrong while updating the product(s) attributes." "Please select products for attributes update.","Please select products for attributes update." diff --git a/app/code/Magento/Catalog/sql/catalog_setup/install-1.6.0.0.0.php b/app/code/Magento/Catalog/sql/catalog_setup/install-1.6.0.0.0.php deleted file mode 100644 index faf56feb30d41..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/install-1.6.0.0.0.php +++ /dev/null @@ -1,3889 +0,0 @@ -startSetup(); - -/** - * Create table 'catalog_product_entity' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_set_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute Set ID' -)->addColumn( - 'type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 32, - array('nullable' => false, 'default' => 'simple'), - 'Type ID' -)->addColumn( - 'sku', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 64, - array(), - 'SKU' -)->addColumn( - 'has_options', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('nullable' => false, 'default' => '0'), - 'Has Options' -)->addColumn( - 'required_options', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Required Options' -)->addColumn( - 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - array(), - 'Creation Time' -)->addColumn( - 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - array(), - 'Update Time' -)->addIndex( - $installer->getIdxName('catalog_product_entity', array('entity_type_id')), - array('entity_type_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity', array('attribute_set_id')), - array('attribute_set_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity', array('sku')), - array('sku') -)->addForeignKey( - $installer->getFkName('catalog_product_entity', 'attribute_set_id', 'eav_attribute_set', 'attribute_set_id'), - 'attribute_set_id', - $installer->getTable('eav_attribute_set'), - 'attribute_set_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity', 'entity_type_id', 'eav_entity_type', 'entity_type_id'), - 'entity_type_id', - $installer->getTable('eav_entity_type'), - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Table' -); -$installer->getConnection()->createTable($table); - - - -/** - * Create table 'catalog_product_entity_datetime' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_datetime') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, - null, - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_datetime', - array('entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_datetime', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_datetime', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_product_entity_datetime', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_datetime', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_datetime', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Datetime Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_decimal' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_decimal') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_decimal', - array('entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_decimal', array('store_id')), - array('store_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_decimal', array('attribute_id')), - array('attribute_id') -)->addForeignKey( - $installer->getFkName('catalog_product_entity_decimal', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_decimal', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_decimal', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Decimal Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_int' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_int') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_int', - array('entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_int', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_int', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_product_entity_int', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_int', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_int', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Integer Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_text' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_text') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_text', - array('entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_text', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_text', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_product_entity_text', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_text', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_text', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Text Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_varchar' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_varchar') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_varchar', - array('entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_varchar', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_varchar', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_product_entity_varchar', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_varchar', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_varchar', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Varchar Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_gallery' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_gallery') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'default' => '0'), - 'Position' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array('nullable' => true, 'default' => null), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_gallery', - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_gallery', array('entity_id')), - array('entity_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_gallery', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_gallery', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_product_entity_gallery', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_gallery', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_gallery', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Gallery Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_entity' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_entity') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_set_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attriute Set ID' -)->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Parent Category ID' -)->addColumn( - 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - array(), - 'Creation Time' -)->addColumn( - 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - array(), - 'Update Time' -)->addColumn( - 'path', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array('nullable' => false), - 'Tree Path' -)->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false), - 'Position' -)->addColumn( - 'level', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'default' => '0'), - 'Tree Level' -)->addColumn( - 'children_count', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false), - 'Child Count' -)->addIndex( - $installer->getIdxName('catalog_category_entity', array('level')), - array('level') -)->setComment( - 'Catalog Category Table' -); -$installer->getConnection()->createTable($table); - - -/** - * Create table 'catalog_category_entity_datetime' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_entity_datetime') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, - null, - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_category_entity_datetime', - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_category_entity_datetime', array('entity_id')), - array('entity_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_datetime', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_datetime', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_category_entity_datetime', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_datetime', 'entity_id', 'catalog_category_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_category_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_datetime', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Category Datetime Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_entity_decimal' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_entity_decimal') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_category_entity_decimal', - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_category_entity_decimal', array('entity_id')), - array('entity_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_decimal', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_decimal', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_category_entity_decimal', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_decimal', 'entity_id', 'catalog_category_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_category_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_decimal', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Category Decimal Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_entity_int' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_entity_int') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_category_entity_int', - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_category_entity_int', array('entity_id')), - array('entity_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_int', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_int', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_category_entity_int', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_int', 'entity_id', 'catalog_category_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_category_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_int', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Category Integer Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_entity_text' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_entity_text') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_category_entity_text', - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_category_entity_text', array('entity_id')), - array('entity_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_text', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_text', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_category_entity_text', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_text', 'entity_id', 'catalog_category_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_category_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_text', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Category Text Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_entity_varchar' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_entity_varchar') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity Type ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array(), - 'Value' -)->addIndex( - $installer->getIdxName( - 'catalog_category_entity_varchar', - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_category_entity_varchar', array('entity_id')), - array('entity_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_varchar', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_category_entity_varchar', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName('catalog_category_entity_varchar', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_varchar', 'entity_id', 'catalog_category_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_category_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_entity_varchar', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Category ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Product ID' -)->addColumn( - 'position', - \Magento\Framework\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', 'entity_id'), - 'category_id', - $installer->getTable('catalog_category_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_product', 'product_id', 'catalog_product_entity', 'entity_id'), - 'product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Category ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Product ID' -)->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true), - 'Position' -)->addColumn( - 'is_parent', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Parent' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Store ID' -)->addColumn( - 'visibility', - \Magento\Framework\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', 'entity_id'), - 'category_id', - $installer->getTable('catalog_category_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_product_index', 'product_id', 'catalog_product_entity', 'entity_id'), - 'product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_category_product_index', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Compare Item ID' -)->addColumn( - 'visitor_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Visitor ID' -)->addColumn( - 'customer_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true), - 'Customer ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true), - 'Store 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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_compare_item', 'product_id', 'catalog_product_entity', 'entity_id'), - 'product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_compare_item', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_SET_NULL, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Product ID' -)->addColumn( - 'website_id', - \Magento\Framework\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', 'store_website', 'website_id'), - 'website_id', - $installer->getTable('store_website'), - 'website_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_website', 'product_id', 'catalog_product_entity', 'entity_id'), - 'product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Product ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Store ID' -)->addColumn( - 'visibility', - \Magento\Framework\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', 'entity_id'), - 'product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_enabled_index', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Link Type ID' -)->addColumn( - 'code', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 32, - array('nullable' => true, 'default' => null), - '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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Link ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'linked_product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Linked Product ID' -)->addColumn( - 'link_type_id', - \Magento\Framework\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'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('link_type_id', 'product_id', 'linked_product_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::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') -)->addForeignKey( - $installer->getFkName('catalog_product_link', 'linked_product_id', 'catalog_product_entity', 'entity_id'), - 'linked_product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_link', 'product_id', 'catalog_product_entity', 'entity_id'), - 'product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Product Link Attribute ID' -)->addColumn( - 'link_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Link Type ID' -)->addColumn( - 'product_link_attribute_code', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 32, - array('nullable' => true, 'default' => null), - 'Product Link Attribute Code' -)->addColumn( - 'data_type', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 32, - array('nullable' => true, 'default' => null), - '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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'product_link_attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true), - 'Product Link Attribute ID' -)->addColumn( - 'link_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'unsigned' => true), - 'Link ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'default' => '0.0000'), - 'Value' -)->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'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('product_link_attribute_id', 'link_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'product_link_attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true), - 'Product Link Attribute ID' -)->addColumn( - 'link_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'unsigned' => true), - 'Link ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'default' => '0'), - 'Value' -)->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'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('product_link_attribute_id', 'link_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'product_link_attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product Link Attribute ID' -)->addColumn( - 'link_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'unsigned' => true), - 'Link ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array(), - 'Value' -)->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'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('product_link_attribute_id', 'link_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Link Varchar Attribute Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_tier_price' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_tier_price') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'all_groups', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '1'), - 'Is Applicable To All Customer Groups' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Customer Group ID' -)->addColumn( - 'qty', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'default' => '1.0000'), - 'QTY' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'default' => '0.0000'), - 'Value' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false), - 'Website ID' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_tier_price', - array('entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_tier_price', array('customer_group_id')), - array('customer_group_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_tier_price', array('website_id')), - array('website_id') -)->addForeignKey( - $installer->getFkName( - 'catalog_product_entity_tier_price', - 'customer_group_id', - 'customer_group', - 'customer_group_id' - ), - 'customer_group_id', - $installer->getTable('customer_group'), - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_tier_price', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_tier_price', 'website_id', 'store_website', 'website_id'), - 'website_id', - $installer->getTable('store_website'), - 'website_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Tier Price Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_media_gallery' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_media_gallery') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Attribute ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array(), - 'Value' -)->addIndex( - $installer->getIdxName('catalog_product_entity_media_gallery', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_media_gallery', array('entity_id')), - array('entity_id') -)->addForeignKey( - $installer->getFkName('catalog_product_entity_media_gallery', 'attribute_id', 'eav_attribute', 'attribute_id'), - 'attribute_id', - $installer->getTable('eav_attribute'), - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_media_gallery', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Media Gallery Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_entity_media_gallery_value' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_media_gallery_value') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Value ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Store ID' -)->addColumn( - 'label', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array(), - 'Label' -)->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true), - 'Position' -)->addColumn( - 'disabled', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Disabled' -)->addIndex( - $installer->getIdxName('catalog_product_entity_media_gallery_value', array('store_id')), - array('store_id') -)->addForeignKey( - $installer->getFkName( - 'catalog_product_entity_media_gallery_value', - 'value_id', - 'catalog_product_entity_media_gallery', - 'value_id' - ), - 'value_id', - $installer->getTable('catalog_product_entity_media_gallery'), - 'value_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_media_gallery_value', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Option ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'type', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 50, - array('nullable' => true, 'default' => null), - 'Type' -)->addColumn( - 'is_require', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('nullable' => false, 'default' => '1'), - 'Is Required' -)->addColumn( - 'sku', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 64, - array(), - 'SKU' -)->addColumn( - 'max_characters', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true), - 'Max Characters' -)->addColumn( - 'file_extension', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 50, - array(), - 'File Extension' -)->addColumn( - 'image_size_x', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true), - 'Image Size X' -)->addColumn( - 'image_size_y', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true), - 'Image Size Y' -)->addColumn( - 'sort_order', - \Magento\Framework\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', 'entity_id'), - 'product_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Option Price ID' -)->addColumn( - 'option_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Option ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'default' => '0.0000'), - 'Price' -)->addColumn( - 'price_type', - \Magento\Framework\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'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('option_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_option_price', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Option Title ID' -)->addColumn( - 'option_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Option ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'title', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array('nullable' => true, 'default' => null), - 'Title' -)->addIndex( - $installer->getIdxName( - 'catalog_product_option_title', - array('option_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('option_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_option_title', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Option Type ID' -)->addColumn( - 'option_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Option ID' -)->addColumn( - 'sku', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 64, - array(), - 'SKU' -)->addColumn( - 'sort_order', - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Option Type Price ID' -)->addColumn( - 'option_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Option Type ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'default' => '0.0000'), - 'Price' -)->addColumn( - 'price_type', - \Magento\Framework\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'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('option_type_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_option_type_price', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), - 'Option Type Title ID' -)->addColumn( - 'option_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Option Type ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'title', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array('nullable' => true, 'default' => null), - 'Title' -)->addIndex( - $installer->getIdxName( - 'catalog_product_option_type_title', - array('option_type_id', 'store_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('option_type_id', 'store_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_option_type_title', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Attribute ID' -)->addColumn( - 'frontend_input_renderer', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array(), - 'Frontend Input Renderer' -)->addColumn( - 'is_global', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '1'), - 'Is Global' -)->addColumn( - 'is_visible', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '1'), - 'Is Visible' -)->addColumn( - 'is_searchable', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Searchable' -)->addColumn( - 'is_filterable', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Filterable' -)->addColumn( - 'is_comparable', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Comparable' -)->addColumn( - 'is_visible_on_front', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Visible On Front' -)->addColumn( - 'is_html_allowed_on_front', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is HTML Allowed On Front' -)->addColumn( - 'is_used_for_price_rules', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Used For Price Rules' -)->addColumn( - 'is_filterable_in_search', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Filterable In Search' -)->addColumn( - 'used_in_product_listing', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Used In Product Listing' -)->addColumn( - 'used_for_sort_by', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Used For Sorting' -)->addColumn( - 'apply_to', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array('nullable' => true), - 'Apply To' -)->addColumn( - 'is_visible_in_advanced_search', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Visible In Advanced Search' -)->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'default' => '0'), - 'Position' -)->addColumn( - 'is_wysiwyg_enabled', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is WYSIWYG Enabled' -)->addColumn( - 'is_used_for_promo_rules', - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Parent ID' -)->addColumn( - 'child_id', - \Magento\Framework\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', 'entity_id'), - 'child_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_relation', 'parent_id', 'catalog_product_entity', 'entity_id'), - 'parent_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Store ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Value' -)->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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_eav', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_eav', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Store ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'primary' => true), - 'Value' -)->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', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_eav_decimal', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_eav_decimal', 'store_id', 'store', 'store_id'), - 'store_id', - $installer->getTable('store'), - 'store_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'tax_class_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'default' => '0'), - 'Tax Class ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Price' -)->addColumn( - 'final_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Final Price' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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('min_price')), - array('min_price') -)->addForeignKey( - $installer->getFkName('catalog_product_index_price', 'customer_group_id', 'customer_group', 'customer_group_id'), - 'customer_group_id', - $installer->getTable('customer_group'), - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_price', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_price', 'website_id', 'store_website', 'website_id'), - 'website_id', - $installer->getTable('store_website'), - 'website_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'min_price', - \Magento\Framework\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_group', - 'customer_group_id' - ), - 'customer_group_id', - $installer->getTable('customer_group'), - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_tier_price', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_tier_price', 'website_id', 'store_website', 'website_id'), - 'website_id', - $installer->getTable('store_website'), - 'website_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\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', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'website_date', - \Magento\Framework\DB\Ddl\Table::TYPE_DATE, - null, - array(), - 'Website Date' -)->addColumn( - 'rate', - \Magento\Framework\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', 'store_website', 'website_id'), - 'website_id', - $installer->getTable('store_website'), - 'website_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Website Index Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_index_price_cfg_opt_agr_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_cfg_opt_agr_idx') -)->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Parent ID' -)->addColumn( - 'child_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Child ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_price_cfg_opt_agr_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_cfg_opt_agr_tmp') -)->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Parent ID' -)->addColumn( - 'child_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Child ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_price_cfg_opt_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_cfg_opt_idx') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_price_cfg_opt_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_cfg_opt_tmp') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_price_final_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_final_idx') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'tax_class_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'default' => '0'), - 'Tax Class ID' -)->addColumn( - 'orig_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Original Price' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Price' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Tier Price' -)->addColumn( - 'base_tier', - \Magento\Framework\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_index_price_final_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_final_tmp') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'tax_class_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'default' => '0'), - 'Tax Class ID' -)->addColumn( - 'orig_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Original Price' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Price' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Tier Price' -)->addColumn( - 'base_tier', - \Magento\Framework\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_index_price_opt_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_opt_idx') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_price_opt_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_opt_tmp') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_price_opt_agr_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_opt_agr_idx') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'option_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Option ID' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_price_opt_agr_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_opt_agr_tmp') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'option_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'), - 'Option ID' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\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_index_eav_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_eav_idx') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Store ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Value' -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_idx', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_idx', array('store_id')), - array('store_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_idx', array('value')), - array('value') -)->setComment( - 'Catalog Product EAV Indexer Index Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_index_eav_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_eav_tmp') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Store ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Value' -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_tmp', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_tmp', array('store_id')), - array('store_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_tmp', array('value')), - array('value') -)->setComment( - 'Catalog Product EAV Indexer Temp Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_index_eav_decimal_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_eav_decimal_idx') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Store ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'primary' => true), - 'Value' -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_decimal_idx', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_decimal_idx', array('store_id')), - array('store_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_decimal_idx', array('value')), - array('value') -)->setComment( - 'Catalog Product EAV Decimal Indexer Index Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_index_eav_decimal_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_eav_decimal_tmp') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'attribute_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Attribute ID' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Store ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'primary' => true), - 'Value' -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_decimal_tmp', array('attribute_id')), - array('attribute_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_decimal_tmp', array('store_id')), - array('store_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_eav_decimal_tmp', array('value')), - array('value') -)->setComment( - 'Catalog Product EAV Decimal Indexer Temp Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_index_price_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_idx') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'tax_class_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'default' => '0'), - 'Tax Class ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Price' -)->addColumn( - 'final_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Final Price' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Tier Price' -)->addIndex( - $installer->getIdxName('catalog_product_index_price_idx', array('customer_group_id')), - array('customer_group_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_price_idx', array('website_id')), - array('website_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_price_idx', array('min_price')), - array('min_price') -)->setComment( - 'Catalog Product Price Indexer Index Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_index_price_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_index_price_tmp') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'tax_class_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'default' => '0'), - 'Tax Class ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Price' -)->addColumn( - 'final_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Final Price' -)->addColumn( - 'min_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addColumn( - 'max_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Max Price' -)->addColumn( - 'tier_price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Tier Price' -)->addIndex( - $installer->getIdxName('catalog_product_index_price_tmp', array('customer_group_id')), - array('customer_group_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_price_tmp', array('website_id')), - array('website_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_price_tmp', array('min_price')), - array('min_price') -)->setComment( - 'Catalog Product Price Indexer Temp Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_product_index_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_product_index_idx') -)->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Category ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'default' => '0'), - 'Position' -)->addColumn( - 'is_parent', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Parent' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'visibility', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false), - 'Visibility' -)->addIndex( - $installer->getIdxName('catalog_category_product_index_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_index_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_product_index_tmp') -)->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Category ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'position', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('nullable' => false, 'default' => '0'), - 'Position' -)->addColumn( - 'is_parent', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Is Parent' -)->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Store ID' -)->addColumn( - 'visibility', - \Magento\Framework\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_index_enbl_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_product_index_enbl_idx') -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'visibility', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Visibility' -)->addIndex( - $installer->getIdxName('catalog_category_product_index_enbl_idx', array('product_id')), - array('product_id') -)->setComment( - 'Catalog Category Product Enabled Indexer Index Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_product_index_enbl_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_product_index_enbl_tmp') -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'visibility', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Visibility' -)->addIndex( - $installer->getIdxName('catalog_category_product_index_enbl_tmp', array('product_id')), - array('product_id') -)->setComment( - 'Catalog Category Product Enabled Indexer Temp Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_anc_categs_index_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_anc_categs_index_idx') -)->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Category ID' -)->addColumn( - 'path', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array('nullable' => true, 'default' => null), - 'Path' -)->addIndex( - $installer->getIdxName('catalog_category_anc_categs_index_idx', array('category_id')), - array('category_id') -)->setComment( - 'Catalog Category Anchor Indexer Index Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_anc_categs_index_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_anc_categs_index_tmp') -)->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Category ID' -)->addColumn( - 'path', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - array('nullable' => true, 'default' => null), - 'Path' -)->addIndex( - $installer->getIdxName('catalog_category_anc_categs_index_tmp', array('category_id')), - array('category_id') -)->setComment( - 'Catalog Category Anchor Indexer Temp Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_category_anc_products_index_idx' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_anc_products_index_idx') -)->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Category ID' -)->addColumn( - 'product_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Product ID' -)->addColumn( - 'position', - \Magento\Framework\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_anc_products_index_tmp' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_category_anc_products_index_tmp') -)->addColumn( - 'category_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Category ID' -)->addColumn( - 'product_id', - \Magento\Framework\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); - -$installer->endSetup(); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/install-2.0.0.php b/app/code/Magento/Catalog/sql/catalog_setup/install-2.0.0.php new file mode 100644 index 0000000000000..8e57e4ec2e23c --- /dev/null +++ b/app/code/Magento/Catalog/sql/catalog_setup/install-2.0.0.php @@ -0,0 +1,4530 @@ +startSetup(); + +/** + * Create table 'catalog_product_entity' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_product_entity')) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_set_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute Set ID' + ) + ->addColumn( + 'type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 32, + ['nullable' => false, 'default' => 'simple'], + 'Type ID' + ) + ->addColumn( + 'sku', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 64, + [], + 'SKU' + ) + ->addColumn( + 'has_options', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['nullable' => false, 'default' => '0'], + 'Has Options' + ) + ->addColumn( + 'required_options', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Required Options' + ) + ->addColumn( + 'created_at', + \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + null, + [], + 'Creation Time' + ) + ->addColumn( + 'updated_at', + \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + null, + [], + 'Update Time' + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity', ['entity_type_id']), + ['entity_type_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity', ['attribute_set_id']), + ['attribute_set_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity', ['sku']), + ['sku'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity', 'attribute_set_id', 'eav_attribute_set', 'attribute_set_id'), + 'attribute_set_id', + $installer->getTable('eav_attribute_set'), + 'attribute_set_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity', 'entity_type_id', 'eav_entity_type', 'entity_type_id'), + 'entity_type_id', + $installer->getTable('eav_entity_type'), + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Product Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_entity_datetime' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_product_entity_datetime')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, + null, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_datetime', + ['entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_datetime', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_datetime', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_datetime', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_datetime', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_datetime', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Product Datetime Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_entity_decimal' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_product_entity_decimal')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_decimal', + ['entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_decimal', ['store_id']), + ['store_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_decimal', ['attribute_id']), + ['attribute_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_decimal', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_decimal', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_decimal', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Product Decimal Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_entity_int' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_product_entity_int')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_int', + ['entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_int', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_int', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_int', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_int', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_int', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Product Integer Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_entity_text' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_product_entity_text')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + '64k', + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_text', + ['entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_text', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_text', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_text', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_text', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_text', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Product Text Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_entity_varchar' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_product_entity_varchar')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_varchar', + ['entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_varchar', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_varchar', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_varchar', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_varchar', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_varchar', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Product Varchar Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_entity_gallery' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_product_entity_gallery')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'position', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'default' => '0'], + 'Position' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + ['nullable' => true, 'default' => null], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_gallery', + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_gallery', ['entity_id']), + ['entity_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_gallery', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_gallery', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_gallery', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_gallery', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_gallery', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Product Gallery Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_category_entity' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_category_entity')) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_set_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attriute Set ID' + ) + ->addColumn( + 'parent_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Parent Category ID' + ) + ->addColumn( + 'created_at', + \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + null, + [], + 'Creation Time' + ) + ->addColumn( + 'updated_at', + \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + null, + [], + 'Update Time' + ) + ->addColumn( + 'path', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + ['nullable' => false], + 'Tree Path' + ) + ->addColumn( + 'position', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false], + 'Position' + ) + ->addColumn( + 'level', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'default' => '0'], + 'Tree Level' + ) + ->addColumn( + 'children_count', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false], + 'Child Count' + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity', ['level']), + ['level'] + ) + ->setComment('Catalog Category Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_category_entity_datetime' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_category_entity_datetime')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, + null, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_category_entity_datetime', + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_datetime', ['entity_id']), + ['entity_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_datetime', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_datetime', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_datetime', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_datetime', 'entity_id', 'catalog_category_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_category_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_datetime', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Category Datetime Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_category_entity_decimal' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_category_entity_decimal')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_category_entity_decimal', + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_decimal', ['entity_id']), + ['entity_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_decimal', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_decimal', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_decimal', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_decimal', 'entity_id', 'catalog_category_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_category_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_decimal', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Category Decimal Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_category_entity_int' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_category_entity_int')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_category_entity_int', + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_int', ['entity_id']), + ['entity_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_int', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_int', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_int', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_int', 'entity_id', 'catalog_category_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_category_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_int', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Category Integer Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_category_entity_text' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_category_entity_text')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + '64k', + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_category_entity_text', + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_text', ['entity_id']), + ['entity_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_text', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_text', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_text', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_text', 'entity_id', 'catalog_category_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_category_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_text', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment('Catalog Category Text Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_category_entity_varchar' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog_category_entity_varchar')) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity Type ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_category_entity_varchar', + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_type_id', 'entity_id', 'attribute_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_varchar', ['entity_id']), + ['entity_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_varchar', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_category_entity_varchar', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_varchar', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_varchar', 'entity_id', 'catalog_category_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_category_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_entity_varchar', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Category ID' + ) + ->addColumn( + 'product_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Product ID' + ) + ->addColumn( + 'position', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'default' => '0'], + 'Position' + ) + ->addIndex( + $installer->getIdxName('catalog_category_product', ['product_id']), + ['product_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_category_product', 'category_id', 'catalog_category_entity', 'entity_id'), + 'category_id', + $installer->getTable('catalog_category_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_category_product', 'product_id', 'catalog_product_entity', 'entity_id'), + 'product_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Category ID' + ) + ->addColumn( + 'product_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Product ID' + ) + ->addColumn( + 'position', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => false, 'nullable' => true, 'default' => null], + 'Position' + ) + ->addColumn( + 'is_parent', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Parent' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'visibility', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false], + 'Visibility' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_category_product_index', + ['product_id', 'store_id', 'category_id', 'visibility'] + ), + ['product_id', 'store_id', 'category_id', 'visibility'] + ) + ->addIndex( + $installer->getIdxName( + 'catalog_category_product_index', + ['store_id', 'category_id', 'visibility', 'is_parent', 'position'] + ), + ['store_id', 'category_id', 'visibility', 'is_parent', 'position'] + ) + ->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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Compare Item ID' + ) + ->addColumn( + 'visitor_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Visitor ID' + ) + ->addColumn( + 'customer_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true], + 'Customer ID' + ) + ->addColumn( + 'product_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Product ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true], + 'Store ID' + ) + ->addIndex( + $installer->getIdxName('catalog_compare_item', ['product_id']), + ['product_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_compare_item', ['visitor_id', 'product_id']), + ['visitor_id', 'product_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_compare_item', ['customer_id', 'product_id']), + ['customer_id', 'product_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_compare_item', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_compare_item', 'customer_id', 'customer_entity', 'entity_id'), + 'customer_id', + $installer->getTable('customer_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_compare_item', 'product_id', 'catalog_product_entity', 'entity_id'), + 'product_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_compare_item', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_SET_NULL, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Product ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addIndex( + $installer->getIdxName('catalog_product_website', ['website_id']), + ['website_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_website', 'website_id', 'store_website', 'website_id'), + 'website_id', + $installer->getTable('store_website'), + 'website_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_website', 'product_id', 'catalog_product_entity', 'entity_id'), + 'product_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment( + 'Catalog Product To Website Linkage 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', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Link Type ID' + ) + ->addColumn( + 'code', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 32, + ['nullable' => true, 'default' => null], + '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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Link ID' + ) + ->addColumn( + 'product_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Product ID' + ) + ->addColumn( + 'linked_product_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Linked Product ID' + ) + ->addColumn( + 'link_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Link Type ID' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_link', + ['link_type_id', 'product_id', 'linked_product_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['link_type_id', 'product_id', 'linked_product_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_link', ['product_id']), + ['product_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_link', ['linked_product_id']), + ['linked_product_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_link', 'linked_product_id', 'catalog_product_entity', 'entity_id'), + 'linked_product_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_link', 'product_id', 'catalog_product_entity', 'entity_id'), + 'product_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Product Link Attribute ID' + ) + ->addColumn( + 'link_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Link Type ID' + ) + ->addColumn( + 'product_link_attribute_code', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 32, + ['nullable' => true, 'default' => null], + 'Product Link Attribute Code' + ) + ->addColumn( + 'data_type', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 32, + ['nullable' => true, 'default' => null], + 'Data Type' + ) + ->addIndex( + $installer->getIdxName('catalog_product_link_attribute', ['link_type_id']), + ['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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'product_link_attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true], + 'Product Link Attribute ID' + ) + ->addColumn( + 'link_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'unsigned' => true], + 'Link ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'default' => '0.0000'], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_link_attribute_decimal', ['link_id']), + ['link_id'] + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_link_attribute_decimal', + ['product_link_attribute_id', 'link_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['product_link_attribute_id', 'link_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'product_link_attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true], + 'Product Link Attribute ID' + ) + ->addColumn( + 'link_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'unsigned' => true], + 'Link ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'default' => '0'], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_link_attribute_int', ['link_id']), + ['link_id'] + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_link_attribute_int', + ['product_link_attribute_id', 'link_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['product_link_attribute_id', 'link_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'product_link_attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Product Link Attribute ID' + ) + ->addColumn( + 'link_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'unsigned' => true], + 'Link ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_link_attribute_varchar', ['link_id']), + ['link_id'] + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_link_attribute_varchar', + ['product_link_attribute_id', 'link_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['product_link_attribute_id', 'link_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment( + 'Catalog Product Link Varchar Attribute Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_entity_tier_price' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_entity_tier_price') + ) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'all_groups', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '1'], + 'Is Applicable To All Customer Groups' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Customer Group ID' + ) + ->addColumn( + 'qty', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'default' => '1.0000'], + 'QTY' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'default' => '0.0000'], + 'Value' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false], + 'Website ID' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_tier_price', + ['entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_tier_price', ['customer_group_id']), + ['customer_group_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_tier_price', ['website_id']), + ['website_id'] + ) + ->addForeignKey( + $installer->getFkName( + 'catalog_product_entity_tier_price', + 'customer_group_id', + 'customer_group', + 'customer_group_id' + ), + 'customer_group_id', + $installer->getTable('customer_group'), + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_tier_price', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_tier_price', 'website_id', 'store_website', 'website_id'), + 'website_id', + $installer->getTable('store_website'), + 'website_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment( + 'Catalog Product Tier Price Attribute Backend Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_entity_media_gallery' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_entity_media_gallery') + ) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Attribute ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + [], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_media_gallery', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_media_gallery', ['entity_id']), + ['entity_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_media_gallery', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName( + 'catalog_product_entity_media_gallery', + 'entity_id', + 'catalog_product_entity', + 'entity_id' + ), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment( + 'Catalog Product Media Gallery Attribute Backend Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_entity_media_gallery_value' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_entity_media_gallery_value') + ) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Value ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'label', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + [], + 'Label' + ) + ->addColumn( + 'position', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true], + 'Position' + ) + ->addColumn( + 'disabled', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Disabled' + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_media_gallery_value', ['store_id']), + ['store_id'] + ) + ->addForeignKey( + $installer->getFkName( + 'catalog_product_entity_media_gallery_value', + 'value_id', + 'catalog_product_entity_media_gallery', + 'value_id' + ), + 'value_id', + $installer->getTable('catalog_product_entity_media_gallery'), + 'value_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_media_gallery_value', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Option ID' + ) + ->addColumn( + 'product_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Product ID' + ) + ->addColumn( + 'type', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 50, + ['nullable' => true, 'default' => null], + 'Type' + ) + ->addColumn( + 'is_require', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['nullable' => false, 'default' => '1'], + 'Is Required' + ) + ->addColumn( + 'sku', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 64, + [], + 'SKU' + ) + ->addColumn( + 'max_characters', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true], + 'Max Characters' + ) + ->addColumn( + 'file_extension', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 50, + [], + 'File Extension' + ) + ->addColumn( + 'image_size_x', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true], + 'Image Size X' + ) + ->addColumn( + 'image_size_y', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true], + 'Image Size Y' + ) + ->addColumn( + 'sort_order', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Sort Order' + ) + ->addIndex( + $installer->getIdxName('catalog_product_option', ['product_id']), + ['product_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_option', 'product_id', 'catalog_product_entity', 'entity_id'), + 'product_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Option Price ID' + ) + ->addColumn( + 'option_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Option ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'default' => '0.0000'], + 'Price' + ) + ->addColumn( + 'price_type', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 7, + ['nullable' => false, 'default' => 'fixed'], + 'Price Type' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_option_price', + ['option_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['option_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_option_price', ['store_id']), + ['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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_option_price', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Option Title ID' + ) + ->addColumn( + 'option_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Option ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'title', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + ['nullable' => true, 'default' => null], + 'Title' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_option_title', + ['option_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['option_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_option_title', ['store_id']), + ['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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_option_title', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Option Type ID' + ) + ->addColumn( + 'option_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Option ID' + ) + ->addColumn( + 'sku', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 64, + [], + 'SKU' + ) + ->addColumn( + 'sort_order', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Sort Order' + ) + ->addIndex( + $installer->getIdxName('catalog_product_option_type_value', ['option_id']), + ['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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Option Type Price ID' + ) + ->addColumn( + 'option_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Option Type ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'default' => '0.0000'], + 'Price' + ) + ->addColumn( + 'price_type', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 7, + ['nullable' => false, 'default' => 'fixed'], + 'Price Type' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_option_type_price', + ['option_type_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['option_type_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_option_type_price', ['store_id']), + ['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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_option_type_price', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Option Type Title ID' + ) + ->addColumn( + 'option_type_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Option Type ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'title', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + ['nullable' => true, 'default' => null], + 'Title' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_option_type_title', + ['option_type_id', 'store_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['option_type_id', 'store_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_option_type_title', ['store_id']), + ['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', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_option_type_title', 'store_id', 'store', 'store_id'), + 'store_id', + $installer->getTable('store'), + 'store_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Attribute ID' + ) + ->addColumn( + 'frontend_input_renderer', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + [], + 'Frontend Input Renderer' + ) + ->addColumn( + 'is_global', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '1'], + 'Is Global' + ) + ->addColumn( + 'is_visible', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '1'], + 'Is Visible' + ) + ->addColumn( + 'is_searchable', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Searchable' + ) + ->addColumn( + 'is_filterable', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Filterable' + ) + ->addColumn( + 'is_comparable', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Comparable' + ) + ->addColumn( + 'is_visible_on_front', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Visible On Front' + ) + ->addColumn( + 'is_html_allowed_on_front', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is HTML Allowed On Front' + ) + ->addColumn( + 'is_used_for_price_rules', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Used For Price Rules' + ) + ->addColumn( + 'is_filterable_in_search', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Filterable In Search' + ) + ->addColumn( + 'used_in_product_listing', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Used In Product Listing' + ) + ->addColumn( + 'used_for_sort_by', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Used For Sorting' + ) + ->addColumn( + 'apply_to', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 255, + ['nullable' => true], + 'Apply To' + ) + ->addColumn( + 'is_visible_in_advanced_search', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Visible In Advanced Search' + ) + ->addColumn( + 'position', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'default' => '0'], + 'Position' + ) + ->addColumn( + 'is_wysiwyg_enabled', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is WYSIWYG Enabled' + ) + ->addColumn( + 'is_used_for_promo_rules', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Used For Promo Rules' + ) + ->addColumn( + 'is_required_in_admin_store', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Required In Admin Store' + ) + ->addIndex( + $installer->getIdxName('catalog_eav_attribute', ['used_for_sort_by']), + ['used_for_sort_by'] + ) + ->addIndex( + $installer->getIdxName('catalog_eav_attribute', ['used_in_product_listing']), + ['used_in_product_listing'] + ) + ->addForeignKey( + $installer->getFkName('catalog_eav_attribute', 'attribute_id', 'eav_attribute', 'attribute_id'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Parent ID' + ) + ->addColumn( + 'child_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Child ID' + ) + ->addIndex( + $installer->getIdxName('catalog_product_relation', ['child_id']), + ['child_id'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_relation', 'child_id', 'catalog_product_entity', 'entity_id'), + 'child_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_relation', 'parent_id', 'catalog_product_entity', 'entity_id'), + 'parent_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Store ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav', ['store_id']), + ['store_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav', ['value']), + ['value'] + ) + ->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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Store ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'primary' => false], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal', ['store_id']), + ['store_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal', ['value']), + ['value'] + ) + ->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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'tax_class_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'default' => '0'], + 'Tax Class ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Price' + ) + ->addColumn( + 'final_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Final Price' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price', ['customer_group_id']), + ['customer_group_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price', ['min_price']), + ['min_price'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price', ['website_id', 'customer_group_id', 'min_price']), + ['website_id', 'customer_group_id', 'min_price'] + ) + ->addForeignKey( + $installer->getFkName( + 'catalog_product_index_price', + 'customer_group_id', + 'customer_group', + 'customer_group_id' + ), + 'customer_group_id', + $installer->getTable('customer_group'), + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_index_price', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_index_price', 'website_id', 'store_website', 'website_id'), + 'website_id', + $installer->getTable('store_website'), + 'website_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_tier_price', ['customer_group_id']), + ['customer_group_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_tier_price', ['website_id']), + ['website_id'] + ) + ->addForeignKey( + $installer->getFkName( + 'catalog_product_index_tier_price', + 'customer_group_id', + 'customer_group', + 'customer_group_id' + ), + 'customer_group_id', + $installer->getTable('customer_group'), + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_index_tier_price', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_index_tier_price', 'website_id', 'store_website', 'website_id'), + 'website_id', + $installer->getTable('store_website'), + 'website_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\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', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'website_date', + \Magento\Framework\DB\Ddl\Table::TYPE_DATE, + null, + [], + 'Website Date' + ) + ->addColumn( + 'rate', + \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT, + null, + ['default' => '1.0000'], + 'Rate' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_website', ['website_date']), + ['website_date'] + ) + ->addForeignKey( + $installer->getFkName('catalog_product_index_website', 'website_id', 'store_website', 'website_id'), + 'website_id', + $installer->getTable('store_website'), + 'website_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment( + 'Catalog Product Website Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_cfg_opt_agr_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_cfg_opt_agr_idx') + ) + ->addColumn( + 'parent_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Parent ID' + ) + ->addColumn( + 'child_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Child ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setComment( + 'Catalog Product Price Indexer Config Option Aggregate Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_cfg_opt_agr_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_cfg_opt_agr_tmp') + ) + ->addColumn( + 'parent_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Parent ID' + ) + ->addColumn( + 'child_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Child ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product Price Indexer Config Option Aggregate Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_cfg_opt_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_cfg_opt_idx') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setComment( + 'Catalog Product Price Indexer Config Option Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_cfg_opt_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_cfg_opt_tmp') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product Price Indexer Config Option Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_final_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_final_idx') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'tax_class_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'default' => '0'], + 'Tax Class ID' + ) + ->addColumn( + 'orig_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Original Price' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Price' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'base_tier', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Base Tier' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->addColumn( + 'base_group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Base Group Price' + ) + ->setComment( + 'Catalog Product Price Indexer Final Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_final_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_final_tmp') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'tax_class_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'default' => '0'], + 'Tax Class ID' + ) + ->addColumn( + 'orig_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Original Price' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Price' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'base_tier', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Base Tier' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->addColumn( + 'base_group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Base Group Price' + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product Price Indexer Final Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_opt_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_opt_idx') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setComment( + 'Catalog Product Price Indexer Option Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_opt_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_opt_tmp') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product Price Indexer Option Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_opt_agr_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_opt_agr_idx') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'option_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Option ID' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setComment( + 'Catalog Product Price Indexer Option Aggregate Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_opt_agr_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_opt_agr_tmp') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'option_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'], + 'Option ID' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product Price Indexer Option Aggregate Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_eav_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_eav_idx') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Store ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_idx', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_idx', ['store_id']), + ['store_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_idx', ['value']), + ['value'] + ) + ->setComment( + 'Catalog Product EAV Indexer Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_eav_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_eav_tmp') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Store ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_tmp', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_tmp', ['store_id']), + ['store_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_tmp', ['value']), + ['value'] + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product EAV Indexer Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_eav_decimal_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_eav_decimal_idx') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Store ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'primary' => true], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal_idx', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal_idx', ['store_id']), + ['store_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal_idx', ['value']), + ['value'] + ) + ->setComment( + 'Catalog Product EAV Decimal Indexer Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_eav_decimal_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_eav_decimal_tmp') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'attribute_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Attribute ID' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Store ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'primary' => false], + 'Value' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal_tmp', ['attribute_id']), + ['attribute_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal_tmp', ['store_id']), + ['store_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_eav_decimal_tmp', ['value']), + ['value'] + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product EAV Decimal Indexer Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_idx' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_idx') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'tax_class_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'default' => '0'], + 'Tax Class ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Price' + ) + ->addColumn( + 'final_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Final Price' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price_idx', ['customer_group_id']), + ['customer_group_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price_idx', ['website_id']), + ['website_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price_idx', ['min_price']), + ['min_price'] + ) + ->setComment( + 'Catalog Product Price Indexer Index Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_price_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_price_tmp') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'tax_class_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'default' => '0'], + 'Tax Class ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Price' + ) + ->addColumn( + 'final_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Final Price' + ) + ->addColumn( + 'min_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addColumn( + 'max_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Max Price' + ) + ->addColumn( + 'tier_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Tier Price' + ) + ->addColumn( + 'group_price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Group price' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price_tmp', ['customer_group_id']), + ['customer_group_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price_tmp', ['website_id']), + ['website_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_price_tmp', ['min_price']), + ['min_price'] + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Product Price Indexer Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_category_product_index_tmp' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_category_product_index_tmp') + ) + ->addColumn( + 'category_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Category ID' + ) + ->addColumn( + 'product_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Product ID' + ) + ->addColumn( + 'position', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['nullable' => false, 'default' => '0'], + 'Position' + ) + ->addColumn( + 'is_parent', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Is Parent' + ) + ->addColumn( + 'store_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Store ID' + ) + ->addColumn( + 'visibility', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false], + 'Visibility' + ) + ->addIndex( + $installer->getIdxName('catalog_category_product_index_tmp', ['product_id', 'category_id', 'store_id']), + ['product_id', 'category_id', 'store_id'] + ) + ->setOption( + 'type', + \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY + ) + ->setComment( + 'Catalog Category Product Indexer Temp Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_entity_group_price' + */ +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_entity_group_price') + ) + ->addColumn( + 'value_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + 'Value ID' + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Entity ID' + ) + ->addColumn( + 'all_groups', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '1'], + 'Is Applicable To All Customer Groups' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'default' => '0'], + 'Customer Group ID' + ) + ->addColumn( + 'value', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + ['nullable' => false, 'default' => '0.0000'], + 'Value' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false], + 'Website ID' + ) + ->addIndex( + $installer->getIdxName( + 'catalog_product_entity_group_price', + ['entity_id', 'all_groups', 'customer_group_id', 'website_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['entity_id', 'all_groups', 'customer_group_id', 'website_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_group_price', ['customer_group_id']), + ['customer_group_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_entity_group_price', ['website_id']), + ['website_id'] + ) + ->addForeignKey( + $installer->getFkName( + 'catalog_product_entity_group_price', + 'customer_group_id', + 'customer_group', + 'customer_group_id' + ), + 'customer_group_id', + $installer->getTable('customer_group'), + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_group_price', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_entity_group_price', 'website_id', 'store_website', 'website_id'), + 'website_id', + $installer->getTable('store_website'), + 'website_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment( + 'Catalog Product Group Price Attribute Backend Table' + ); +$installer->getConnection() + ->createTable($table); + +/** + * Create table 'catalog_product_index_group_price' + */ + +$table = $installer->getConnection() + ->newTable( + $installer->getTable('catalog_product_index_group_price') + ) + ->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Entity ID' + ) + ->addColumn( + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Customer Group ID' + ) + ->addColumn( + 'website_id', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['unsigned' => true, 'nullable' => false, 'primary' => true], + 'Website ID' + ) + ->addColumn( + 'price', + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + '12,4', + [], + 'Min Price' + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_group_price', ['customer_group_id']), + ['customer_group_id'] + ) + ->addIndex( + $installer->getIdxName('catalog_product_index_group_price', ['website_id']), + ['website_id'] + ) + ->addForeignKey( + $installer->getFkName( + 'catalog_product_index_group_price', + 'customer_group_id', + 'customer_group', + 'customer_group_id' + ), + 'customer_group_id', + $installer->getTable('customer_group'), + 'customer_group_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_index_group_price', 'entity_id', 'catalog_product_entity', 'entity_id'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName('catalog_product_index_group_price', 'website_id', 'store_website', 'website_id'), + 'website_id', + $installer->getTable('store_website'), + 'website_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + ) + ->setComment( + 'Catalog Product Group Price Index Table' + ); +$installer->getConnection() + ->createTable($table); + +$installer->endSetup(); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.11-1.6.0.0.12.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.11-1.6.0.0.12.php deleted file mode 100644 index 23e7f5ecd9744..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.11-1.6.0.0.12.php +++ /dev/null @@ -1,32 +0,0 @@ -getConnection()->addIndex( - $installer->getTable('catalog_product_index_price'), - $installer->getIdxName('catalog_product_index_price', $indexFields), - $indexFields -); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.2-1.6.0.0.3.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.2-1.6.0.0.3.php deleted file mode 100644 index ef3572333cb6c..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.2-1.6.0.0.3.php +++ /dev/null @@ -1,48 +0,0 @@ -getTable('catalog_product_index_eav_decimal'); -$indexName = $installer->getConnection()->getPrimaryKeyName($tableName); - - -$tableNameTmp = $installer->getTable('catalog_product_index_eav_decimal_tmp'); -$indexNameTmp = $installer->getConnection()->getPrimaryKeyName($tableNameTmp); - -$fields = array('entity_id', 'attribute_id', 'store_id'); - -$installer->getConnection()->addIndex( - $tableName, - $indexName, - $fields, - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY -); - -$installer->getConnection()->addIndex( - $tableNameTmp, - $indexNameTmp, - $fields, - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY -); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.25-1.6.0.0.26.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.25-1.6.0.0.26.php deleted file mode 100644 index fe4401d846063..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.25-1.6.0.0.26.php +++ /dev/null @@ -1,46 +0,0 @@ -getConnection(); - -$connection->dropForeignKey( - $this->getTable('catalog_category_product_index'), - $this->getFkName('catalog_category_product_index', 'category_id', 'catalog_category_entity', 'entity_id') -)->dropForeignKey( - $this->getTable('catalog_category_product_index'), - $this->getFkName('catalog_category_product_index', 'product_id', 'catalog_product_entity', 'entity_id') -)->dropForeignKey( - $this->getTable('catalog_category_product_index'), - $this->getFkName('catalog_category_product_index', 'store_id', 'store', 'store_id') -); - -$connection->dropTable($this->getTable('catalog_product_enabled_index')); -$connection->dropTable($this->getTable('catalog_category_product_index_idx')); -$connection->dropTable($this->getTable('catalog_category_product_index_enbl_idx')); -$connection->dropTable($this->getTable('catalog_category_product_index_enbl_tmp')); -$connection->dropTable($this->getTable('catalog_category_anc_categs_index_idx')); -$connection->dropTable($this->getTable('catalog_category_anc_categs_index_tmp')); -$connection->dropTable($this->getTable('catalog_category_anc_products_index_idx')); -$connection->dropTable($this->getTable('catalog_category_anc_products_index_tmp')); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.26-1.6.0.0.27.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.26-1.6.0.0.27.php deleted file mode 100644 index d96ff3e253e5c..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.26-1.6.0.0.27.php +++ /dev/null @@ -1,59 +0,0 @@ -startSetup(); - -$this->getConnection()->dropForeignKey( - $this->getTable('catalog_product_index_eav'), - $this->getFkName('catalog_product_index_eav', 'attribute_id', 'eav_attribute', 'attribute_id') -); - -$this->getConnection()->dropForeignKey( - $this->getTable('catalog_product_index_eav'), - $this->getFkName('catalog_product_index_eav', 'entity_id', 'catalog_product_entity', 'entity_id') -); - -$this->getConnection()->dropForeignKey( - $this->getTable('catalog_product_index_eav'), - $this->getFkName('catalog_product_index_eav', 'store_id', 'store', 'store_id') -); - -$this->getConnection()->dropForeignKey( - $this->getTable('catalog_product_index_eav_decimal'), - $this->getFkName('catalog_product_index_eav_decimal', 'attribute_id', 'eav_attribute', 'attribute_id') -); - -$this->getConnection()->dropForeignKey( - $this->getTable('catalog_product_index_eav_decimal'), - $this->getFkName('catalog_product_index_eav_decimal', 'entity_id', 'catalog_product_entity', 'entity_id') -); - -$this->getConnection()->dropForeignKey( - $this->getTable('catalog_product_index_eav_decimal'), - $this->getFkName('catalog_product_index_eav_decimal', 'store_id', 'store', 'store_id') -); - -$this->endSetup(); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.27-1.6.0.0.28.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.27-1.6.0.0.28.php deleted file mode 100644 index 2c6b5eaf8ef8e..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.27-1.6.0.0.28.php +++ /dev/null @@ -1,36 +0,0 @@ -getConnection()->addColumn( - $this->getTable('catalog_eav_attribute'), - 'is_required_in_admin_store', - array( - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'default' => '0', - 'comment' => 'Is Required In Admin Store' - ) -); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.4-1.6.0.0.5.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.4-1.6.0.0.5.php deleted file mode 100644 index 03e31c841eac9..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.4-1.6.0.0.5.php +++ /dev/null @@ -1,38 +0,0 @@ -getConnection()->modifyColumn( - $installer->getTable('catalog_category_product_index'), - 'position', - array( - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'unsigned' => false, - 'nullable' => true, - 'default' => null, - 'comment' => 'Position' - ) -); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.6-1.6.0.0.7.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.6-1.6.0.0.7.php deleted file mode 100644 index ce665c8663617..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.6-1.6.0.0.7.php +++ /dev/null @@ -1,37 +0,0 @@ -getConnection()->addColumn( - $installer->getTable('catalog_category_anc_products_index_tmp'), - 'position', - array( - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'unsigned' => true, - 'nullable' => true, - 'comment' => 'Position' - ) -); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.7-1.6.0.0.8.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.7-1.6.0.0.8.php deleted file mode 100644 index 0eafd3ea2c44f..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.7-1.6.0.0.8.php +++ /dev/null @@ -1,74 +0,0 @@ -getConnection(); - -$connection->addIndex( - $installer->getTable('catalog_category_product_index_tmp'), - $installer->getIdxName('catalog_category_product_index_tmp', array('product_id', 'category_id', 'store_id')), - array('product_id', 'category_id', 'store_id') -); - -$table = $installer->getTable('catalog_category_product_index_enbl_idx'); -$connection->dropIndex($table, 'IDX_CATALOG_CATEGORY_PRODUCT_INDEX_ENBL_IDX_PRODUCT_ID'); -$connection->addIndex( - $table, - $installer->getIdxName('catalog_category_product_index_enbl_idx', array('product_id', 'visibility')), - array('product_id', 'visibility') -); - - -$table = $installer->getTable('catalog_category_product_index_enbl_tmp'); -$connection->dropIndex($table, 'IDX_CATALOG_CATEGORY_PRODUCT_INDEX_ENBL_TMP_PRODUCT_ID'); -$connection->addIndex( - $table, - $installer->getIdxName('catalog_category_product_index_enbl_tmp', array('product_id', 'visibility')), - array('product_id', 'visibility') -); - -$connection->addIndex( - $installer->getTable('catalog_category_anc_products_index_idx'), - $installer->getIdxName('catalog_category_anc_products_index_idx', array('category_id', 'product_id', 'position')), - array('category_id', 'product_id', 'position') -); - -$connection->addIndex( - $installer->getTable('catalog_category_anc_products_index_tmp'), - $installer->getIdxName('catalog_category_anc_products_index_tmp', array('category_id', 'product_id', 'position')), - array('category_id', 'product_id', 'position') -); - -$connection->addIndex( - $installer->getTable('catalog_category_anc_categs_index_idx'), - $installer->getIdxName('catalog_category_anc_categs_index_idx', array('path', 'category_id')), - array('path', 'category_id') -); - -$connection->addIndex( - $installer->getTable('catalog_category_anc_categs_index_tmp'), - $installer->getIdxName('catalog_category_anc_categs_index_tmp', array('path', 'category_id')), - array('path', 'category_id') -); diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.8-1.6.0.0.9.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.8-1.6.0.0.9.php deleted file mode 100644 index c0f00870705a9..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.8-1.6.0.0.9.php +++ /dev/null @@ -1,46 +0,0 @@ -getConnection(); -$memoryTables = array( - 'catalog_category_anc_categs_index_tmp', - 'catalog_category_anc_products_index_tmp', - 'catalog_category_product_index_enbl_tmp', - 'catalog_category_product_index_tmp', - 'catalog_product_index_eav_decimal_tmp', - 'catalog_product_index_eav_tmp', - 'catalog_product_index_price_cfg_opt_agr_tmp', - 'catalog_product_index_price_cfg_opt_tmp', - 'catalog_product_index_price_final_tmp', - 'catalog_product_index_price_opt_agr_tmp', - 'catalog_product_index_price_opt_tmp', - 'catalog_product_index_price_tmp' -); - -foreach ($memoryTables as $table) { - $connection->changeTableEngine($this->getTable($table), \Magento\Framework\DB\Adapter\Pdo\Mysql::ENGINE_MEMORY); -} diff --git a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.9-1.6.0.0.10.php b/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.9-1.6.0.0.10.php deleted file mode 100644 index 5822843b12924..0000000000000 --- a/app/code/Magento/Catalog/sql/catalog_setup/upgrade-1.6.0.0.9-1.6.0.0.10.php +++ /dev/null @@ -1,216 +0,0 @@ -getConnection(); - -/** - * Create table 'catalog_product_entity_group_price' - */ -$table = $installer->getConnection()->newTable( - $installer->getTable('catalog_product_entity_group_price') -)->addColumn( - 'value_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('identity' => true, 'nullable' => false, 'primary' => true), - 'Value ID' -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Entity ID' -)->addColumn( - 'all_groups', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '1'), - 'Is Applicable To All Customer Groups' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'default' => '0'), - 'Customer Group ID' -)->addColumn( - 'value', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array('nullable' => false, 'default' => '0.0000'), - 'Value' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false), - 'Website ID' -)->addIndex( - $installer->getIdxName( - 'catalog_product_entity_group_price', - array('entity_id', 'all_groups', 'customer_group_id', 'website_id'), - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - array('entity_id', 'all_groups', 'customer_group_id', 'website_id'), - array('type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE) -)->addIndex( - $installer->getIdxName('catalog_product_entity_group_price', array('customer_group_id')), - array('customer_group_id') -)->addIndex( - $installer->getIdxName('catalog_product_entity_group_price', array('website_id')), - array('website_id') -)->addForeignKey( - $installer->getFkName( - 'catalog_product_entity_group_price', - 'customer_group_id', - 'customer_group', - 'customer_group_id' - ), - 'customer_group_id', - $installer->getTable('customer_group'), - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_group_price', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_entity_group_price', 'website_id', 'store_website', 'website_id'), - 'website_id', - $installer->getTable('store_website'), - 'website_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Group Price Attribute Backend Table' -); -$installer->getConnection()->createTable($table); - -/** - * Create table 'catalog_product_index_group_price' - */ -$table = $connection->newTable( - $installer->getTable('catalog_product_index_group_price') -)->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Entity ID' -)->addColumn( - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Customer Group ID' -)->addColumn( - 'website_id', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - null, - array('unsigned' => true, 'nullable' => false, 'primary' => true), - 'Website ID' -)->addColumn( - 'price', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - array(), - 'Min Price' -)->addIndex( - $installer->getIdxName('catalog_product_index_group_price', array('customer_group_id')), - array('customer_group_id') -)->addIndex( - $installer->getIdxName('catalog_product_index_group_price', array('website_id')), - array('website_id') -)->addForeignKey( - $installer->getFkName( - 'catalog_product_index_group_price', - 'customer_group_id', - 'customer_group', - 'customer_group_id' - ), - 'customer_group_id', - $installer->getTable('customer_group'), - 'customer_group_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_group_price', 'entity_id', 'catalog_product_entity', 'entity_id'), - 'entity_id', - $installer->getTable('catalog_product_entity'), - 'entity_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->addForeignKey( - $installer->getFkName('catalog_product_index_group_price', 'website_id', 'store_website', 'website_id'), - 'website_id', - $installer->getTable('store_website'), - 'website_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE -)->setComment( - 'Catalog Product Group Price Index Table' -); -$connection->createTable($table); - -$finalPriceIndexerTables = array('catalog_product_index_price_final_idx', 'catalog_product_index_price_final_tmp'); - -$priceIndexerTables = array( - 'catalog_product_index_price_opt_agr_idx', - 'catalog_product_index_price_opt_agr_tmp', - 'catalog_product_index_price_opt_idx', - 'catalog_product_index_price_opt_tmp', - 'catalog_product_index_price_idx', - 'catalog_product_index_price_tmp', - 'catalog_product_index_price_cfg_opt_agr_idx', - 'catalog_product_index_price_cfg_opt_agr_tmp', - 'catalog_product_index_price_cfg_opt_idx', - 'catalog_product_index_price_cfg_opt_tmp', - 'catalog_product_index_price' -); - -foreach ($finalPriceIndexerTables as $table) { - $connection->addColumn( - $installer->getTable($table), - 'group_price', - array('type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'length' => '12,4', 'comment' => 'Group price') - ); - $connection->addColumn( - $installer->getTable($table), - 'base_group_price', - array('type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'length' => '12,4', 'comment' => 'Base Group Price') - ); -} - -foreach ($priceIndexerTables as $table) { - $connection->addColumn( - $installer->getTable($table), - 'group_price', - array('type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'length' => '12,4', 'comment' => 'Group price') - ); -} diff --git a/app/code/Magento/Catalog/view/adminhtml/requirejs-config.js b/app/code/Magento/Catalog/view/adminhtml/requirejs-config.js new file mode 100644 index 0000000000000..9bea1b0cdb824 --- /dev/null +++ b/app/code/Magento/Catalog/view/adminhtml/requirejs-config.js @@ -0,0 +1,37 @@ +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License (AFL 3.0) + * that is bundled with this package in the file LICENSE_AFL.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/afl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +var config = { + map: { + '*': { + categoryForm: 'Magento_Catalog/catalog/category/form', + newCategoryDialog: 'Magento_Catalog/js/new-category-dialog', + categoryTree: 'Magento_Catalog/js/category-tree', + productGallery: 'Magento_Catalog/js/product-gallery', + baseImage: 'Magento_Catalog/catalog/base-image-uploader' + } + }, + deps: [ + "Magento_Catalog/catalog/product" + ] +}; \ No newline at end of file diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit.phtml index 04c32963cab2b..577a7ae607e59 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit.phtml @@ -57,7 +57,7 @@ require([ if (confirm('')){ if (useAjax){ tree.nodeForDelete = categoryId; - updateContent(url, {}, true); + updateContent(url, {}, true, true); } else { location.href = url; } @@ -67,14 +67,19 @@ require([ /** * Update category content area */ - function updateContent(url, params, refreshTree) { - var win = this; - var params = jQuery.extend(params || {}, { + function updateContent(url, params, refreshTree, deleteAction) { + var node = tree.getNodeById(tree.currentNodeId), + parentNode = node && node.parentNode, + parentId, + redirectUrl, + params; + + params = jQuery.extend(params || {}, { form_key: FORM_KEY }); - + if (params.node_name) { - this.tree.getNodeById(tree.currentNodeId).currentNode.setText(params.node_name); + node.setText(params.node_name); } (function($){ @@ -85,6 +90,16 @@ require([ context: $('body'), showLoader: true }).done(function(data){ + if (deleteAction && parentNode) { + parentId = parentNode.id; + + redirectUrl = !parentNode.isRoot ? + tree.buildUrl(parentId) : + tree.getBaseUrl(); + + location.href = redirectUrl; + } + if (data.content) { $('.page-actions').floatingHeader('destroy'); try { @@ -92,7 +107,7 @@ require([ tinyMCE.execCommand('mceRemoveControl', false, $(element).attr('id')); }); $categoryContainer.html(''); - } catch(e) { + } catch (e) { alert(e.message); } $categoryContainer.html(data.content).trigger('contentUpdated'); @@ -101,16 +116,19 @@ require([ tinyMCE.execCommand('mceRemoveControl', false, $(element).attr('id')); tinyMCE.execCommand('mceAddControl', true, $(element).attr('id')); }); - $('.page-actions').floatingHeader({ 'title': '.category-edit-title'}); + $('.page-actions').floatingHeader({ + 'title': '.category-edit-title' + }); try { if (refreshTree) { - win.refreshTreeArea(); + window.refreshTreeArea(); } } catch (e) { alert(e.message); }; }, 25); } + if (data.messages && data.messages.length > 0) { $('.messages').html(data.messages); } @@ -123,6 +141,9 @@ require([ */ function refreshTreeArea(transport) { + var config, + url; + if (tree && window.editingCategoryBreadcrumbs) { // category deleted - delete its node if (tree.nodeForDelete) { @@ -140,24 +161,9 @@ require([ tree.addNodeTo = false; if (parent) { // Check maybe tree became somehow not synced with ajax and we're trying to add to unknown node - var node = new Ext.tree.AsyncTreeNode(editingCategoryBreadcrumbs[editingCategoryBreadcrumbs.length - 1]); - node.loaded = true; - tree.currentNodeId = node.id; - parent.appendChild(node); - - if (parent.expanded) { - tree.selectCurrentNode(); - } else { - var timer; - parent.expand(); - var f = function(){ - if(parent.expanded){ // done expanding - clearInterval(timer); - tree.selectCurrentNode(); - } - }; - timer = setInterval(f, 200); - } + config = editingCategoryBreadcrumbs[editingCategoryBreadcrumbs.length - 1]; + + window.location.href = tree.buildUrl(config.id); } } diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit/form.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit/form.phtml index 698ead9021ddc..fa2f9a280819e 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit/form.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit/form.phtml @@ -21,6 +21,10 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ + +/** @var \Magento\Catalog\Block\Adminhtml\Category\Edit\Form $this */ +$parentId = $this->getParentCategoryId(); +$categoryId = $this->getCategoryId(); ?>

escapeHtml($this->getHeader()) . ($this->getCategoryId() ? ' (' . __('ID: %1', $this->getCategoryId()) . ')' : '') ?>

@@ -42,13 +46,19 @@ -
+ + + + + +
@@ -56,7 +66,7 @@
diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml index 4a36c8ff9b0de..3286c15781286 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml @@ -31,7 +31,7 @@
-