diff --git a/.github/.htaccess b/.github/.htaccess new file mode 100644 index 0000000000000..707c26b075e16 --- /dev/null +++ b/.github/.htaccess @@ -0,0 +1,8 @@ + + order allow,deny + deny from all + += 2.4> + Require all denied + + diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000000..4e82725a7fb08 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at engcom@magento.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md diff --git a/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md similarity index 100% rename from ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE.md diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/.gitignore b/.gitignore index bae558e0e5b9a..94c3bf76a2bd1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /.metadata /.project /.settings +/.vscode atlassian* /nbproject /robots.txt diff --git a/.htaccess b/.htaccess index 90b9c16a5a8c0..4298b10d9ca7a 100644 --- a/.htaccess +++ b/.htaccess @@ -36,7 +36,7 @@ ############################################ ## adjust memory limit - php_value memory_limit 768M + php_value memory_limit 756M php_value max_execution_time 18000 ############################################ @@ -59,7 +59,7 @@ ############################################ ## adjust memory limit - php_value memory_limit 768M + php_value memory_limit 756M php_value max_execution_time 18000 ############################################ @@ -203,76 +203,166 @@ RedirectMatch 403 /\.git - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all - - - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + + + + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + # For 404s and 403s that aren't handled by the application, show plain 404 response diff --git a/.htaccess.sample b/.htaccess.sample index 3b61bb672ec8a..a521a347232f5 100644 --- a/.htaccess.sample +++ b/.htaccess.sample @@ -35,7 +35,7 @@ ############################################ ## adjust memory limit - php_value memory_limit 768M + php_value memory_limit 756M php_value max_execution_time 18000 ############################################ @@ -111,7 +111,8 @@ ############################################ ## enable rewrites - Options +FollowSymLinks + # The following line has better security but add some performance overhead - see https://httpd.apache.org/docs/2.4/en/misc/perf-tuning.html + Options -FollowSymLinks +SymLinksIfOwnerMatch RewriteEngine on ############################################ @@ -179,76 +180,166 @@ RedirectMatch 403 /\.git - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all - - - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + + + + + order allow,deny + deny from all + + = 2.4> + Require all denied + - order allow,deny - deny from all + + order allow,deny + deny from all + + = 2.4> + Require all denied + # For 404s and 403s that aren't handled by the application, show plain 404 response diff --git a/.travis.yml b/.travis.yml index 42c2bcab0c901..3265cc575cdca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,8 +29,7 @@ env: - TEST_SUITE=integration INTEGRATION_INDEX=1 - TEST_SUITE=integration INTEGRATION_INDEX=2 - TEST_SUITE=integration INTEGRATION_INDEX=3 - - TEST_SUITE=functional ACCEPTANCE_INDEX=1 - - TEST_SUITE=functional ACCEPTANCE_INDEX=2 + - TEST_SUITE=functional matrix: exclude: - php: 7.0 @@ -40,9 +39,7 @@ matrix: - php: 7.0 env: TEST_SUITE=js GRUNT_COMMAND=static - php: 7.0 - env: TEST_SUITE=functional ACCEPTANCE_INDEX=1 - - php: 7.0 - env: TEST_SUITE=functional ACCEPTANCE_INDEX=2 + env: TEST_SUITE=functional cache: apt: true directories: @@ -55,7 +52,6 @@ install: composer install --no-interaction --prefer-dist before_script: ./dev/travis/before_script.sh script: # Set arguments for variants of phpunit based tests; '|| true' prevents failing script when leading test fails - - test $TEST_SUITE = "static" && TEST_FILTER='--filter "Magento\\Test\\Php\\LiveCodeTest"' || true - test $TEST_SUITE = "functional" && TEST_FILTER='dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests.php' || true # The scripts for grunt/phpunit type tests diff --git a/.user.ini b/.user.ini index 8c0b765e0551c..bfc3a86d88e20 100644 --- a/.user.ini +++ b/.user.ini @@ -1,4 +1,4 @@ -memory_limit = 768M +memory_limit = 756M max_execution_time = 18000 session.auto_start = off suhosin.session.cryptua = off \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ef841ec0337f2..a5e94e46f89d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,919 @@ +2.2.2 +============= +* GitHub issues: + * [#9968](https://github.com/magento/magento2/issues/9968) -- Canceled invoice can be canceled again (fixed in [#11261](https://github.com/magento/magento2/pull/11261)) + * [#11310](https://github.com/magento/magento2/issues/11310) -- Method "getChildren" sort ordering (fixed in [#11342](https://github.com/magento/magento2/pull/11342)) + * [#11332](https://github.com/magento/magento2/issues/11332) -- How to Fix the wrong input format of Customer date of birth (fixed in [#11351](https://github.com/magento/magento2/pull/11351)) + * [#11207](https://github.com/magento/magento2/issues/11207) -- Shipment API won't append comment to email (fixed in [#11383](https://github.com/magento/magento2/pull/11383)) + * [#10795](https://github.com/magento/magento2/issues/10795) -- Shipping method radios have duplicate IDs on cart page (fixed in [#11406](https://github.com/magento/magento2/pull/11406)) + * [#10941](https://github.com/magento/magento2/issues/10941) -- Responsive Design Issue on Mobile with Magento 2.1.9 (fixed in [#11430](https://github.com/magento/magento2/pull/11430)) + * [#10007](https://github.com/magento/magento2/issues/10007) -- ProductAlert: Product alerts not showing in admin side product edit page (fixed in [#11445](https://github.com/magento/magento2/pull/11445)) + * [#10231](https://github.com/magento/magento2/issues/10231) -- Custom URL Rewrite Not working (fixed in [#11470](https://github.com/magento/magento2/pull/11470)) + * [#11176](https://github.com/magento/magento2/issues/11176) -- Configured table prefix is not recognized in CLI admin:user:create (fixed in [#11199](https://github.com/magento/magento2/pull/11199)) + * [#11275](https://github.com/magento/magento2/issues/11275) -- Call to a member function addCrumb() (fixed in [#11299](https://github.com/magento/magento2/pull/11299)) + * [#10441](https://github.com/magento/magento2/issues/10441) -- State/Province Not displayed after edit Billing Address on Sales Orders - Backend Admin. (fixed in [#11381](https://github.com/magento/magento2/pull/11381)) + * [#11140](https://github.com/magento/magento2/issues/11140) -- Going to '/admin' while using storecodes in url and a different adminhtml url will throw exception (fixed in [#11460](https://github.com/magento/magento2/pull/11460)) + * [#10765](https://github.com/magento/magento2/issues/10765) -- Export data from grid not adding custom rendered data magento2 (fixed in [#11437](https://github.com/magento/magento2/pull/11437)) + * [#7678](https://github.com/magento/magento2/issues/7678) -- StockItemCriteria::setProductsFilter doesn't work with array of ids (fixed in [#11500](https://github.com/magento/magento2/pull/11500)) + * [#9783](https://github.com/magento/magento2/issues/9783) -- Multiple parameters in widget.xml not allowed (fixed in [#11495](https://github.com/magento/magento2/pull/11495)) + * [#10824](https://github.com/magento/magento2/issues/10824) -- Cannot add new columns to item grid in admin sales_order_view layout (fixed in [#11235](https://github.com/magento/magento2/pull/11235)) + * [#9919](https://github.com/magento/magento2/issues/9919) -- Pattern Validation via UI Component Fails to Interpret String as RegEx Pattern (fixed in [#11565](https://github.com/magento/magento2/pull/11565)) + * [#5439](https://github.com/magento/magento2/issues/5439) -- Newsletter subscription (fixed in [#11317](https://github.com/magento/magento2/pull/11317)) + * [#10856](https://github.com/magento/magento2/issues/10856) -- Sync billing with shipping address on Admin Reorder and Admin Customer Create Order page does not work for Existing address selected (fixed in [#11385](https://github.com/magento/magento2/pull/11385)) + * [#10025](https://github.com/magento/magento2/issues/10025) -- Integration tests don't reset the database (fixed in [#11499](https://github.com/magento/magento2/pull/11499)) + * [#10301](https://github.com/magento/magento2/issues/10301) -- Customer review report search Bug in 2.1.x, 2.2 (fixed in [#11522](https://github.com/magento/magento2/pull/11522)) + * [#11540](https://github.com/magento/magento2/issues/11540) -- Magento sets iso invalid language code in html header (fixed in [#11561](https://github.com/magento/magento2/pull/11561)) + * [#11586](https://github.com/magento/magento2/issues/11586) -- Cron install / remove via command messes up stderr 2>&1 entries (fixed in [#11591](https://github.com/magento/magento2/pull/11591)) + * [#6350](https://github.com/magento/magento2/issues/6350) -- Frontend: Datepicker/calendar control does not use the store locale (fixed in [#11057](https://github.com/magento/magento2/pull/11057)) + * [#11328](https://github.com/magento/magento2/issues/11328) -- app:config:dump adds extra space every time in multiline array value (fixed in [#11439](https://github.com/magento/magento2/pull/11439)) + * [#7591](https://github.com/magento/magento2/issues/7591) -- PayPal module, "didgit" misspelling (fixed in [#11673](https://github.com/magento/magento2/pull/11673)) + * [#7767](https://github.com/magento/magento2/issues/7767) -- in system.xml translate phrase not work (fixed in [#11675](https://github.com/magento/magento2/pull/11675)) + * [#7915](https://github.com/magento/magento2/issues/7915) -- customer objects are equal to eachother after observing event customer_save_after_data_object (fixed in [#11676](https://github.com/magento/magento2/pull/11676)) + * [#10275](https://github.com/magento/magento2/issues/10275) -- Admin global search - submit by enter doesn't work (fixed in [#11250](https://github.com/magento/magento2/pull/11250)) + * [#11022](https://github.com/magento/magento2/issues/11022) -- GET v1/products/attribute-sets/sets/list inconsistent return result (fixed in [#11421](https://github.com/magento/magento2/pull/11421)) + * [#5956](https://github.com/magento/magento2/issues/5956) -- Untranslatable string "Please enter the same value again." (fixed in [#11440](https://github.com/magento/magento2/pull/11440)) + * [#9944](https://github.com/magento/magento2/issues/9944) -- Name attribute shows empty when creating custom fields on product creation form (fixed in [#11637](https://github.com/magento/magento2/pull/11637)) + * [#10168](https://github.com/magento/magento2/issues/10168) -- Coupon codes not showing in invoice (fixed in [#11635](https://github.com/magento/magento2/pull/11635)) + * [#9763](https://github.com/magento/magento2/issues/9763) -- When go checkout,Cart Price Rules 25%test coupon code can go wrong (fixed in [#11710](https://github.com/magento/magento2/pull/11710)) + * [#11157](https://github.com/magento/magento2/issues/11157) -- nginx.sample.conf missing heath_check.php? (fixed in [#11690](https://github.com/magento/magento2/pull/11690)) + * [#11322](https://github.com/magento/magento2/issues/11322) -- User.ini files specify 768M - Docs recommend at least 1G (fixed in [#11734](https://github.com/magento/magento2/pull/11734)) + * [#7927](https://github.com/magento/magento2/issues/7927) -- Dashboard graph has broken y-axis range (fixed in [#11751](https://github.com/magento/magento2/pull/11751)) + * [#7099](https://github.com/magento/magento2/issues/7099) -- Admin: field labels wrapping poorly (fixed in [#11745](https://github.com/magento/magento2/pull/11745)) + * [#9869](https://github.com/magento/magento2/issues/9869) -- datetime type product attribute showing current date (fixed in [#11749](https://github.com/magento/magento2/pull/11749)) + * [#11365](https://github.com/magento/magento2/issues/11365) -- "Ignore this notification" isn't working (fixed in [#11410](https://github.com/magento/magento2/pull/11410)) + * [#6891](https://github.com/magento/magento2/issues/6891) -- Add-to-cart checkbox still visible when $canItemsAddToCart = false (fixed in [#11610](https://github.com/magento/magento2/pull/11610)) + * [#11729](https://github.com/magento/magento2/issues/11729) -- Exported Excel with negative number can't be opened by MS Office (fixed in [#11757](https://github.com/magento/magento2/pull/11757)) + * [#6924](https://github.com/magento/magento2/issues/6924) -- Magento 2.1.0 - "General system exception happened" on Import .csv (fixed in [#11363](https://github.com/magento/magento2/pull/11363)) + * [#7640](https://github.com/magento/magento2/issues/7640) -- X-Magento-Tags header containing whitespaces causes exception (fixed in [#11767](https://github.com/magento/magento2/pull/11767)) + * [#4711](https://github.com/magento/magento2/issues/4711) -- Improve error reporting for products images import (fixed in [#11779](https://github.com/magento/magento2/pull/11779)) + * [#4696](https://github.com/magento/magento2/issues/4696) -- Admin product search - Pressing enter does not submit (fixed in [#11827](https://github.com/magento/magento2/pull/11827)) + * [#11581](https://github.com/magento/magento2/issues/11581) -- Reference to wrong / non-existing class (fixed in [#11830](https://github.com/magento/magento2/pull/11830)) + * [#10908](https://github.com/magento/magento2/issues/10908) -- [2.2.0-rc3.0] Language switcher is broken when using multiple times (fixed in [#11337](https://github.com/magento/magento2/pull/11337)) + * [#11211](https://github.com/magento/magento2/issues/11211) -- Store View switcher not working on front-end and it throws an error (fixed in [#11337](https://github.com/magento/magento2/pull/11337)) + * [#2991](https://github.com/magento/magento2/issues/2991) -- Products added to cart with REST API give total prices equal to zero (fixed in [#11458](https://github.com/magento/magento2/pull/11458)) + * [#10032](https://github.com/magento/magento2/issues/10032) -- Download back-up .tgz always takes the latest that's created (fixed in [#11595](https://github.com/magento/magento2/pull/11595)) + * [#11534](https://github.com/magento/magento2/issues/11534) -- Values of Visual Swatch Attribute drop down is not work correct (fixed in [#11747](https://github.com/magento/magento2/pull/11747)) + * [#10291](https://github.com/magento/magento2/issues/10291) -- Magento 2 Loading custom option dropdown issue (fixed in [#11824](https://github.com/magento/magento2/pull/11824)) + * [#11095](https://github.com/magento/magento2/issues/11095) -- Magento_Tax "postcode is a required field" when upgrading from 2.1.9 to 2.2 (fixed in [#11651](https://github.com/magento/magento2/pull/11651)) + * [#8236](https://github.com/magento/magento2/issues/8236) -- CMS blocks are not validated against having same store and identifier (fixed in [#11802](https://github.com/magento/magento2/pull/11802)) + * [#4808](https://github.com/magento/magento2/issues/4808) -- The price of product custom option can't be set to 0. (fixed in [#11843](https://github.com/magento/magento2/pull/11843)) + * [#9566](https://github.com/magento/magento2/issues/9566) -- Status label is wrong in admin (fixed in [#11397](https://github.com/magento/magento2/pull/11397)) + * [#5015](https://github.com/magento/magento2/issues/5015) -- Report error csv doesn't work when trying to import a csv file with semicolon delimiter (fixed in [#11732](https://github.com/magento/magento2/pull/11732)) + * [#10682](https://github.com/magento/magento2/issues/10682) -- Meta description and keywords transform to html entities for non latin/cyrilic characters in category and product pages (fixed in [#11829](https://github.com/magento/magento2/pull/11829)) + * [#10185](https://github.com/magento/magento2/issues/10185) -- New Orders are not in Order grid after data migration from M 1.7.0.2 to M 2.1.7 (fixed in [#11911](https://github.com/magento/magento2/pull/11911)) + * [#8970](https://github.com/magento/magento2/issues/8970) -- Cannot assign products to categories not under tree root (fixed in [#11817](https://github.com/magento/magento2/pull/11817)) + * [#9028](https://github.com/magento/magento2/issues/9028) -- You cannot set a 303 redirect response using a result factory (fixed in [#11405](https://github.com/magento/magento2/pull/11405)) + * [#11697](https://github.com/magento/magento2/issues/11697) -- Theme: Added html node to page xml root, cause validation error (fixed in [#11858](https://github.com/magento/magento2/pull/11858)) + * [#8954](https://github.com/magento/magento2/issues/8954) -- Error While Trying To Load Quote Item Collection Using Magento\Quote\Model\ResourceModel\QuoteItem\Collection::getItems() (fixed in [#11869](https://github.com/magento/magento2/pull/11869)) + * [#8799](https://github.com/magento/magento2/issues/8799) -- Image brackground (fixed in [#11889](https://github.com/magento/magento2/pull/11889)) + * [#11868](https://github.com/magento/magento2/issues/11868) -- "Add Products" button has been duplicated after the customer group was changed (fixed in [#11949](https://github.com/magento/magento2/pull/11949)) + * [#11898](https://github.com/magento/magento2/issues/11898) -- Zip code Netherlands should allow zipcode without space (fixed in [#11959](https://github.com/magento/magento2/pull/11959)) + * [#11996](https://github.com/magento/magento2/issues/11996) -- Magento 2 Store Code validation regex: doesn't support uppercase letters in store code (fixed in [#12011](https://github.com/magento/magento2/pull/12011)) + * [#7995](https://github.com/magento/magento2/issues/7995) -- If you leave as default, shipping lines disappear (fixed in [#12013](https://github.com/magento/magento2/pull/12013)) + * [#8846](https://github.com/magento/magento2/issues/8846) -- Attribute option value uniqueness is not checked if created via REST Api (fixed in [#11785](https://github.com/magento/magento2/pull/11785)) + * [#11700](https://github.com/magento/magento2/issues/11700) -- "Something Went Wrong" error for limited access admin user (fixed in [#11993](https://github.com/magento/magento2/pull/11993)) + * [#12017](https://github.com/magento/magento2/issues/12017) -- Cross-sell product placeholder image size issue (fixed in [#12018](https://github.com/magento/magento2/pull/12018)) + * [#10583](https://github.com/magento/magento2/issues/10583) -- Checkout place order exception when using a new address (fixed in [#11556](https://github.com/magento/magento2/pull/11556)) + * [#4004](https://github.com/magento/magento2/issues/4004) -- Newsletter Subscriber create-date not set, and change_status_at broken (fixed in [#11879](https://github.com/magento/magento2/pull/11879)) + * [#7225](https://github.com/magento/magento2/issues/7225) -- [BUG] [Magento 2.1.2] Programmatically creating an empty dropdown attribute, "apply_to" is set to NULL (from "simple") after adding options through store admin (fixed in [#11588](https://github.com/magento/magento2/pull/11588)) + * [#11197](https://github.com/magento/magento2/issues/11197) -- Blank page at the checkout 'shipping' step (fixed in [#11958](https://github.com/magento/magento2/pull/11958)) + * [#11880](https://github.com/magento/magento2/issues/11880) -- Magento 2.1.9 Configurable::getUsedProducts returns a different array after product collections is cached (fixed in [#12107](https://github.com/magento/magento2/pull/12107)) + * [#10811](https://github.com/magento/magento2/issues/10811) -- Replace FollowSymLinks with SymLinksIfOwnerMatch (fixed in [#11461](https://github.com/magento/magento2/pull/11461)) + * [#10920](https://github.com/magento/magento2/issues/10920) -- Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import (fixed in [#11719](https://github.com/magento/magento2/pull/11719)) + * [#6802](https://github.com/magento/magento2/issues/6802) -- Magento\Search\Helper\getSuggestUrl() not used in search template (fixed in [#11722](https://github.com/magento/magento2/pull/11722)) + * [#9151](https://github.com/magento/magento2/issues/9151) -- Sitemap.xml: lastmod timestamp can contain invalid dates (fixed in [#11902](https://github.com/magento/magento2/pull/11902)) + * [#10195](https://github.com/magento/magento2/issues/10195) -- Order relation child is not set during edit operation. (fixed in [#11988](https://github.com/magento/magento2/pull/11988)) + * [#11793](https://github.com/magento/magento2/issues/11793) -- Magento2.1.5 admin shipping report shows wrong currency code (fixed in [#11962](https://github.com/magento/magento2/pull/11962)) + * [#6661](https://github.com/magento/magento2/issues/6661) -- XHTML templates Don't Use Schema URNs (fixed in [#12031](https://github.com/magento/magento2/pull/12031)) + * [#12079](https://github.com/magento/magento2/issues/12079) -- Products in cart report error when we have grouped or bundle product (fixed in [#12082](https://github.com/magento/magento2/pull/12082)) + * [#9768](https://github.com/magento/magento2/issues/9768) -- Admin dashboard Most Viewed Products Tab only gives default attribute set's products (fixed in [#12139](https://github.com/magento/magento2/pull/12139)) + * [#6238](https://github.com/magento/magento2/issues/6238) -- Meta description allows too many characters (fixed in [#11914](https://github.com/magento/magento2/pull/11914)) + * [#11230](https://github.com/magento/magento2/issues/11230) -- Unit test fails after fresh installation (fixed in [#12144](https://github.com/magento/magento2/pull/12144)) + * [#10810](https://github.com/magento/magento2/issues/10810) -- Add support of apache2.4 commands in htaccess (fixed in [#11459](https://github.com/magento/magento2/pull/11459)) + * [#10834](https://github.com/magento/magento2/issues/10834) -- signing in after selecting checkout button, will not end up to checkout page! (fixed in [#11876](https://github.com/magento/magento2/pull/11876)) + * [#10477](https://github.com/magento/magento2/issues/10477) -- Cart price rule has failed if use dropdown attribute (fixed in [#11274](https://github.com/magento/magento2/pull/11274)) + * [#11832](https://github.com/magento/magento2/issues/11832) -- Create order (on Customer edit page) - not working from admin environment (fixed in [#11952](https://github.com/magento/magento2/pull/11952)) + * [#10014](https://github.com/magento/magento2/issues/10014) -- Newsletter subscriptions status not isolated between multi stores (fixed in [#12035](https://github.com/magento/magento2/pull/12035)) + * [#11532](https://github.com/magento/magento2/issues/11532) -- Duplicate Simple Product Throws Error: Undefined offset: 0 in SaveHandler.php on line 122 (fixed in [#12001](https://github.com/magento/magento2/pull/12001)) + * [#10628](https://github.com/magento/magento2/issues/10628) -- Color attribute swatches are not visible if sorting is enabled (fixed in [#12077](https://github.com/magento/magento2/pull/12077)) + * [#8022](https://github.com/magento/magento2/issues/8022) -- Uncaught Error: Call to a member function addItem() on array in app/code/Magento/Sales/Model/Order/Shipment.php (fixed in [#12173](https://github.com/magento/magento2/pull/12173)) +* GitHub pull requests: + * [#11240](https://github.com/magento/magento2/pull/11240) -- Virtual Theme load: Check for null to actually reach the code that handles this case to t… (by @leptoquark1) + * [#11261](https://github.com/magento/magento2/pull/11261) -- Prevent invoice cancelation multiple times 2.2-develop [Backport] (by @osrecio) + * [#11342](https://github.com/magento/magento2/pull/11342) -- ADDED $sortByPostion flag to getChildren() (by @denisristic) + * [#11351](https://github.com/magento/magento2/pull/11351) -- Fix the wrong input format of Customer date of birth (by @manuelson) + * [#11359](https://github.com/magento/magento2/pull/11359) -- [Backport 2.2-develop] Unable to manage (install/uninstall) cron via bin/magento cron:install / cron:remove with multiple installations against same crontab (by @adrian-martinez-interactiv4) + * [#11383](https://github.com/magento/magento2/pull/11383) -- Append shipment comment to shipment if appendComment is true (by @JeroenVanLeusden) + * [#11406](https://github.com/magento/magento2/pull/11406) -- Added carrier code to ID to distinguish shipping methods (by @peterjaap) + * [#11430](https://github.com/magento/magento2/pull/11430) -- Fix toolbar-amount placing in mobile device (by @slackerzz) + * [#11445](https://github.com/magento/magento2/pull/11445) -- Show product alerts in admin product detail [backport 2.2] (by @raumatbel) + * [#11470](https://github.com/magento/magento2/pull/11470) -- FR#10231_22 Custom URL Rewrite Not working [backport 2.2] (by @mrodespin) + * [#11493](https://github.com/magento/magento2/pull/11493) -- Add "optional" translation in checkout password field (by @JeroenVanLeusden) + * [#11199](https://github.com/magento/magento2/pull/11199) -- Add db-prefix from env conf when command admin:user:create is executed (by @osrecio) + * [#11299](https://github.com/magento/magento2/pull/11299) -- Update Guest.php (by @lano-vargas) + * [#11381](https://github.com/magento/magento2/pull/11381) -- Save region correctly to save sales address from admin (by @raumatbel) + * [#11460](https://github.com/magento/magento2/pull/11460) -- [ISSUE-11140][BUGFIX] Skip store code admin from being detected in ca… (by @diglin) + * [#11505](https://github.com/magento/magento2/pull/11505) -- [Backport-2.2] Retain additional cron history by default (by @mpchadwick) + * [#11437](https://github.com/magento/magento2/pull/11437) -- Add `confirmation` and `lock_expires ` to customer export csv - Fix issue 10765 (by @convenient) + * [#11486](https://github.com/magento/magento2/pull/11486) -- [Backport 2.2]Add VAT number to email source variables (by @JeroenVanLeusden) + * [#11495](https://github.com/magento/magento2/pull/11495) -- MAGETWO-75743: Fix for #9783 Multiple parameters in widget.… (by @diazwatson) + * [#11500](https://github.com/magento/magento2/pull/11500) -- MAGETWO-81245: Handling all setProductsFilter items in array as arguments (by @kirmorozov) + * [#11555](https://github.com/magento/magento2/pull/11555) -- Travis CI functional tests maintenance for 2.2-develop (by @ishakhsuvarov) + * [#11235](https://github.com/magento/magento2/pull/11235) -- [2.2-develop] Add static test to detect blocks without name attribute (by @ihor-sviziev) + * [#11569](https://github.com/magento/magento2/pull/11569) -- Fixed double space typo (by @dverkade) + * [#11565](https://github.com/magento/magento2/pull/11565) -- Fix "pattern" UI Component validation (by @bap14) + * [#11317](https://github.com/magento/magento2/pull/11317) -- [Backport 2.2-develop] Send email to subscribers only when are new (by @osrecio) + * [#11385](https://github.com/magento/magento2/pull/11385) -- Fix #10856: Sync billing with shipping address on Admin Order Page (by @joni-jones) + * [#11499](https://github.com/magento/magento2/pull/11499) -- Ensure database is cleared/Magento reinstalled when TESTS_CLEANUP is enabled (by @joshuaswarren) + * [#11510](https://github.com/magento/magento2/pull/11510) -- Add interaction to admin:user:create command (by @cmuench) + * [#11522](https://github.com/magento/magento2/pull/11522) -- [Backport 2.2-develop] Fix Filter Customer Report Review (by @osrecio) + * [#11553](https://github.com/magento/magento2/pull/11553) -- [2.2 Backport] ProductRepository sku cache is corrupted when cacheLimit is reached (by @heldchen) + * [#11561](https://github.com/magento/magento2/pull/11561) -- Magento sets ISO invalid language code (by @crissanclick) + * [#11591](https://github.com/magento/magento2/pull/11591) -- [Backport 2.2-develop] #11586 Fix duplicated crontab 2>&1 expression (by @adrian-martinez-interactiv4) + * [#11439](https://github.com/magento/magento2/pull/11439) -- [Backport 2.2-develop] #11328 : app:config:dump adds extra space every time in multiline array value (by @adrian-martinez-interactiv4) + * [#11675](https://github.com/magento/magento2/pull/11675) -- MAGETWO-77672: in system.xml translate phrase not work, if comment starts from new line. (by @nmalevanec) + * [#11673](https://github.com/magento/magento2/pull/11673) -- [BACKPORT 2.2] [TASK] Removed Typo in Paypal TestCase didgit => digit (by @lewisvoncken) + * [#11704](https://github.com/magento/magento2/pull/11704) -- [Backport 2.2-develop] Travis: surround variable TRAVIS_BRANCH with double-quotes instead of single-quotes (by @adrian-martinez-interactiv4) + * [#11677](https://github.com/magento/magento2/pull/11677) -- [BACKPORT 2.2] [TASK] Moved Customer Groups Menu Item from Other sett… (by @lewisvoncken) + * [#11676](https://github.com/magento/magento2/pull/11676) -- #7915: customer objects are equal to eachother after observing event customer_save_after_data_object (by @RomaKis) + * [#11250](https://github.com/magento/magento2/pull/11250) -- Fixing #10275 keyboard submit of adminhtml suggest form. (by @romainruaud) + * [#11421](https://github.com/magento/magento2/pull/11421) -- FIX #11022 in 2.2-develop: Filter Groups of search criteria parameter have not been included for further processing (by @davidverholen) + * [#11440](https://github.com/magento/magento2/pull/11440) -- Add missing translations in Magento_UI (by @JeroenVanLeusden) + * [#11643](https://github.com/magento/magento2/pull/11643) -- Fixed ability to set field config from layout xml #11302 [backport 2.2] (by @vovayatsyuk) + * [#11637](https://github.com/magento/magento2/pull/11637) -- MAGETWO-81311: Check the length of the array before attempting to sli… (by @briscoda) + * [#11635](https://github.com/magento/magento2/pull/11635) -- Coupon codes not showing in invoice (by @crissanclick) + * [#11690](https://github.com/magento/magento2/pull/11690) -- Add a health check to the NGINX configuration sample (by @andrewhowdencom) + * [#11710](https://github.com/magento/magento2/pull/11710) -- Allow coupon code with special charater to be applied to order in checkout (by @gabrielqs-redstage) + * [#11720](https://github.com/magento/magento2/pull/11720) -- Fix Notice: freePackageValue is undefined (by @amenk) + * [#11734](https://github.com/magento/magento2/pull/11734) -- [TASK] Updated user.ini according to Magento DevDocs (by @lewisvoncken) + * [#11751](https://github.com/magento/magento2/pull/11751) -- [Backport 2.2-develop] Dashboard Fix Y Axis for range (by @osrecio) + * [#11749](https://github.com/magento/magento2/pull/11749) -- [Backport 2.2-develop] Fix datetime type product that show current date when is empty in grids (by @enriquei4) + * [#11745](https://github.com/magento/magento2/pull/11745) -- [Backport 2.2-develop] Fix label to avoid wrapping poorly,now break by word (by @enriquei4) + * [#11765](https://github.com/magento/magento2/pull/11765) -- Allows modules with underscores in name to add blocks to layout via XML (by @bentideswell) + * [#11410](https://github.com/magento/magento2/pull/11410) -- "Ignore this notification" isn't working (by @crissanclick) + * [#11607](https://github.com/magento/magento2/pull/11607) -- [Backport 2.2-develop] Fix AcountManagementTest unit test fail randomly (by @adrian-martinez-interactiv4) + * [#11610](https://github.com/magento/magento2/pull/11610) -- FR#6891_22 Add-to-cart checkbox still visible when = false (by @mrodespin) + * [#11757](https://github.com/magento/magento2/pull/11757) -- Fix #11729 - negative value in excel export [M2.2] (by @hauso) + * [#11363](https://github.com/magento/magento2/pull/11363) -- Issue #6924: Unmask exception message during product import (by @tim-bezhashvyly) + * [#11425](https://github.com/magento/magento2/pull/11425) -- Magento setup:install interactive shell (by @denisristic) + * [#11767](https://github.com/magento/magento2/pull/11767) -- 7640: X-Magento-Tags header containing whitespaces causes exception (by @nmalevanec) + * [#11779](https://github.com/magento/magento2/pull/11779) -- MAGETWO-4711: Improve error reporting for products images import. (by @p-bystritsky) + * [#11830](https://github.com/magento/magento2/pull/11830) -- Fix #11581: Reference to wrong / non-existing class (by @dverkade) + * [#11827](https://github.com/magento/magento2/pull/11827) -- Admin product search - Pressing enter does not submit #4696 (by @bohemiorulo) + * [#11337](https://github.com/magento/magento2/pull/11337) -- #11211 Fix Store View switcher (by @thiagolima-bm) + * [#11458](https://github.com/magento/magento2/pull/11458) -- Products added to cart with REST API give total prices equal to zero (by @peterjaap) + * [#11595](https://github.com/magento/magento2/pull/11595) -- Fix issue #10032 - Download back-up .tgz always takes the latest that's created (2.2-develop) (by @PieterCappelle) + * [#11747](https://github.com/magento/magento2/pull/11747) -- [Backport 2.2-develop] FIX show visual swatches in admin - product attribute (by @enriquei4) + * [#11824](https://github.com/magento/magento2/pull/11824) -- Magetwo 70954: Remove the component.clear from the custom options type. This causes the 'elem' array to become out of sync with the recordData (by @briscoda) + * [#11651](https://github.com/magento/magento2/pull/11651) -- [BUGFIX] Solved error while upgrading from 2.1 to 2.2 (by @lewisvoncken) + * [#11802](https://github.com/magento/magento2/pull/11802) -- #8236 FIX CMS blocks (by @thiagolima-bm) + * [#11843](https://github.com/magento/magento2/pull/11843) -- Save the price 0 as price in custom options [backport 2.2] (by @raumatbel) + * [#11854](https://github.com/magento/magento2/pull/11854) -- FilterBuilder Doc Block Update (by @ByteCreation) + * [#11397](https://github.com/magento/magento2/pull/11397) -- Fix for #9566: Show the correct label in the admin (by @michielgerritsen) + * [#11732](https://github.com/magento/magento2/pull/11732) -- MAGETWO-5015: Report error csv doesn't work when trying to import a csv file with semicolon delimiter. (by @p-bystritsky) + * [#11829](https://github.com/magento/magento2/pull/11829) -- Fix #10682: Meta description and keywords transform to html entities (by @dverkade) + * [#11933](https://github.com/magento/magento2/pull/11933) -- Changed constructor typo in Javascript class (by @dverkade) + * [#11911](https://github.com/magento/magento2/pull/11911) -- Order grid - Sort by Purchase Date Desc by default (by @ihor-sviziev) + * [#11817](https://github.com/magento/magento2/pull/11817) -- GITHUB-8970: Cannot assign products to categories not under tree root. (by @p-bystritsky) + * [#11405](https://github.com/magento/magento2/pull/11405) -- Allow setting of http response status code in a Redirection (by @gabrielqs-redstage) + * [#11858](https://github.com/magento/magento2/pull/11858) -- #11697 Theme: Added html node to page xml root, cause validation error (by @adrian-martinez-interactiv4) + * [#11869](https://github.com/magento/magento2/pull/11869) -- Resolve Error While Trying To Load Quote Item Collection Using Magent… (by @neeta-wagento) + * [#11889](https://github.com/magento/magento2/pull/11889) -- Save background color correctly in images. [backport 2.2] (by @raumatbel) + * [#11917](https://github.com/magento/magento2/pull/11917) -- [BACKPORT 2.2] [TASK] Add resetPassword call to the webapi (by @lewisvoncken) + * [#11949](https://github.com/magento/magento2/pull/11949) -- 11868: "Add Products" button has been duplicated after the customer group was changed. (by @nmalevanec) + * [#11959](https://github.com/magento/magento2/pull/11959) -- #11898 - Change NL PostCode Pattern (by @osrecio) + * [#11620](https://github.com/magento/magento2/pull/11620) -- Check attribute unique between same fields in magento commerce (by @raumatbel) + * [#11770](https://github.com/magento/magento2/pull/11770) -- Product attribute creation page handles Storefront tab visibility wrong (by @euronetzrt) + * [#11863](https://github.com/magento/magento2/pull/11863) -- Update wrong layout update xml handle installed in CMS Home Page by default (by @adrian-martinez-interactiv4) + * [#12011](https://github.com/magento/magento2/pull/12011) -- [backport 2.2] Magento 2 Store Code validation regex: doesn't support uppercase letters in store code (by @manuelson) + * [#12013](https://github.com/magento/magento2/pull/12013) -- Add validation for number of street lines (by @crissanclick) + * [#11785](https://github.com/magento/magento2/pull/11785) -- fix #8846: avoid duplicated attribute option values (by @gomencal) + * [#11993](https://github.com/magento/magento2/pull/11993) -- 11700: "Something Went Wrong" error for limited access admin user (by @RomaKis) + * [#12018](https://github.com/magento/magento2/pull/12018) -- Magento 2.2.0 Solution for Cross-sell product placeholder image size … (by @emiprotech) + * [#11556](https://github.com/magento/magento2/pull/11556) -- Fix #10583: Checkout place order exception when using a new address (by @joni-jones) + * [#11879](https://github.com/magento/magento2/pull/11879) -- #4004: Newsletter Subscriber create-date not set, and change_status_at broken (by @nemesis-back) + * [#11588](https://github.com/magento/magento2/pull/11588) -- Fix Issue #7225 - Remove hardcoding of apply_to when saving attributes (by @MartinPeverelli) + * [#11958](https://github.com/magento/magento2/pull/11958) -- 11197: Blank page at the checkout 'shipping' step[backport]. (by @nmalevanec) + * [#12091](https://github.com/magento/magento2/pull/12091) -- Fix "Undefined variable: responseAjax" notice when trying to save a shipment package (by @lazyguru) + * [#11461](https://github.com/magento/magento2/pull/11461) -- [ISSUE-10811][BUGFIX] Update .htaccess.sample to replace FollowSymLin… (by @diglin) + * [#11719](https://github.com/magento/magento2/pull/11719) -- 10920: Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import. (by @nmalevanec) + * [#11722](https://github.com/magento/magento2/pull/11722) -- 6802: Magento\Search\Helper\getSuggestUrl() not used in search template. (by @nmalevanec) + * [#11857](https://github.com/magento/magento2/pull/11857) -- CMS Page - CMS Page - Force validate layout update xml in production mode when saving CMS Page - Handle layout update xml validation exceptions (by @adrian-martinez-interactiv4) + * [#11902](https://github.com/magento/magento2/pull/11902) -- #9151: [Github] Sitemap.xml: lastmod timestamp can contain invalid dates (by @serhii-balko) + * [#11947](https://github.com/magento/magento2/pull/11947) -- Fix json encoded attribute backend type when attribute value is null (by @tkotosz) + * [#11962](https://github.com/magento/magento2/pull/11962) -- 11793: Magento2.1.5 admin shipping report shows wrong currency code (by @RomaKis) + * [#11988](https://github.com/magento/magento2/pull/11988) -- 10195: Order relation child is not set during edit operation(backport from 2.3 to 2.2) (by @RomaKis) + * [#12031](https://github.com/magento/magento2/pull/12031) -- Improve urn in xhtml (by @enriquei4) + * [#12082](https://github.com/magento/magento2/pull/12082) -- Products in cart report error when we have grouped or bundle product (by @mihaifaget) + * [#12131](https://github.com/magento/magento2/pull/12131) -- [Backport 2.2] Close PayPal popup window in case of rejected request #10820 (by @vovayatsyuk) + * [#12139](https://github.com/magento/magento2/pull/12139) -- 9768: Admin dashboard Most Viewed Products Tab only gives default attribute set's products(backport for 2.2) (by @RomaKis) + * [#11914](https://github.com/magento/magento2/pull/11914) -- [BACKPORT 2.2] [BUGFIX] All UI input fields should have maxlength of 255 because of V… (by @lewisvoncken) + * [#11944](https://github.com/magento/magento2/pull/11944) -- Report Handled Exceptions To New Relic (by @mpchadwick) + * [#12144](https://github.com/magento/magento2/pull/12144) -- Removed FileClassScannerTest dependency to "Magento_Catalog" (by @wexo-team) + * [#11459](https://github.com/magento/magento2/pull/11459) -- close #10810 Migrates Apache Access Syntax to 2.4 on Apache >= 2.4 (by @jonashrem) + * [#11968](https://github.com/magento/magento2/pull/11968) -- Fix bug: Customer import deletes exiting customer entity Fields (by @jalogut) + * [#12061](https://github.com/magento/magento2/pull/12061) -- Cleanup for object manager references and depricated method (by @atishgoswami) + * [#12136](https://github.com/magento/magento2/pull/12136) -- update button.phtml overcomplicated translation phrase. 2.2 (by @ChuckyK) + * [#11876](https://github.com/magento/magento2/pull/11876) -- After logging in customer is now not redirecting to Customer Dashboard by default (by @p-bystritsky) + * [#11274](https://github.com/magento/magento2/pull/11274) -- Fix #10477 Check cart rule subselect conditions against quote item children too (by @marinagociu) + * [#11952](https://github.com/magento/magento2/pull/11952) -- 11832: Create order (on Customer edit page) - not working from admin environment (by @RomaKis) + * [#12035](https://github.com/magento/magento2/pull/12035) -- Fix newsletter subscriptions between stores (by @sbaixauli) + * [#12001](https://github.com/magento/magento2/pull/12001) -- 11532: Duplicate Simple Product Throws Error: Undefined offset: 0 in SaveHandler.php on line 122 (by @RomaKis) + * [#12077](https://github.com/magento/magento2/pull/12077) -- 10628: Color attribute swatches are not visible if sorting is enabled (by @RomaKis) + * [#12130](https://github.com/magento/magento2/pull/12130) -- [Backport 2.2] MAGETWO-71697: Fix possible bug when saving address with empty street line #10582 (by @vovayatsyuk) + * [#12141](https://github.com/magento/magento2/pull/12141) -- Fix js error when disable/enable wysiwyg editor (by @vovayatsyuk) + * [#12173](https://github.com/magento/magento2/pull/12173) -- 8022: Uncaught Error: Call to a member function addItem() on array in app/code/Magento/Sales/Model/Order/Shipment.php(backport to 2.2) (by @RomaKis) + +2.2.1 +============= +* GitHub issues: + * [#4248](https://github.com/magento/magento2/issues/4248) -- Validations not working on customer registration on DOB field. (fixed in [#11067](https://github.com/magento/magento2/pull/11067)) + * [#6350](https://github.com/magento/magento2/issues/6350) -- Frontend: Datepicker/calendar control does not use the store locale (fixed in [#11067](https://github.com/magento/magento2/pull/11067)) + * [#6858](https://github.com/magento/magento2/issues/6858) -- DatePicker date format does not reflect user's locale (fixed in [#11067](https://github.com/magento/magento2/pull/11067)) + * [#6831](https://github.com/magento/magento2/issues/6831) -- Magento 2.1.1 Invalid input date format 'Invalid date' (fixed in [#11067](https://github.com/magento/magento2/pull/11067)) + * [#9743](https://github.com/magento/magento2/issues/9743) -- Invalid date when customer validate with French locale (fixed in [#11067](https://github.com/magento/magento2/pull/11067)) + * [#6712](https://github.com/magento/magento2/issues/6712) -- Footer Links Widget CSS Issue (fixed in [#11063](https://github.com/magento/magento2/pull/11063)) + * [#9008](https://github.com/magento/magento2/issues/9008) -- Error Message Is Confusing When Code Base Is Behind Database Module Version (fixed in [#11064](https://github.com/magento/magento2/pull/11064)) + * [#9981](https://github.com/magento/magento2/issues/9981) -- M2 suggests running setup:upgrade if version number of module is higher than expected (fixed in [#11064](https://github.com/magento/magento2/pull/11064)) + * [#10824](https://github.com/magento/magento2/issues/10824) -- Cannot add new columns to item grid in admin sales_order_view layout (fixed in [#11076](https://github.com/magento/magento2/pull/11076)) + * [#10417](https://github.com/magento/magento2/issues/10417) -- Wysywig editor shows broken image icons (fixed in [#11048](https://github.com/magento/magento2/pull/11048)) + * [#10697](https://github.com/magento/magento2/issues/10697) -- Product Import: Additional data: Invalid URL key (fixed in [#11049](https://github.com/magento/magento2/pull/11049)) + * [#10474](https://github.com/magento/magento2/issues/10474) -- Error message in product review form not being translated (fixed in [#11069](https://github.com/magento/magento2/pull/11069)) + * [#9877](https://github.com/magento/magento2/issues/9877) -- getCacheTags for price issue (fixed in [#11154](https://github.com/magento/magento2/pull/11154)) + * [#10738](https://github.com/magento/magento2/issues/10738) -- Empty attribute label is displayed on product page when other language used. (fixed in [#11168](https://github.com/magento/magento2/pull/11168)) + * [#9900](https://github.com/magento/magento2/issues/9900) -- Cms module collections missing event prefix (fixed in [#11223](https://github.com/magento/magento2/pull/11223)) + * [#11044](https://github.com/magento/magento2/issues/11044) -- magento setup:upgrade prompts to run compilation, even in developer mode (fixed in [#11050](https://github.com/magento/magento2/pull/11050)) + * [#10775](https://github.com/magento/magento2/issues/10775) -- 404 Forbidden sounds not right (fixed in [#11134](https://github.com/magento/magento2/pull/11134)) + * [#11231](https://github.com/magento/magento2/issues/11231) -- Can't close mobile search bar once typed (fixed in [#11246](https://github.com/magento/magento2/pull/11246)) + * [#10317](https://github.com/magento/magento2/issues/10317) -- Region is being overridden when changing from a required-state country to one that is not required (fixed in [#11254](https://github.com/magento/magento2/pull/11254)) + * [#11089](https://github.com/magento/magento2/issues/11089) -- setup:config:set --key append instead of replace (fixed in [#11155](https://github.com/magento/magento2/pull/11155)) + * [#7582](https://github.com/magento/magento2/issues/7582) -- Payment methods in payments title in wrong language (fixed in [#11165](https://github.com/magento/magento2/pull/11165)) + * [#5105](https://github.com/magento/magento2/issues/5105) -- Error While send Invoice with Grouped Products (fixed in [#11297](https://github.com/magento/magento2/pull/11297)) + * [#11163](https://github.com/magento/magento2/issues/11163) -- Magento 2.2.0 Pages showing error: Data key is missing: code-entity (fixed in [#11205](https://github.com/magento/magento2/pull/11205)) + * [#11329](https://github.com/magento/magento2/issues/11329) -- Unable to proceed massaction "Update attributes" with required multiple select attribute (fixed in [#11349](https://github.com/magento/magento2/pull/11349)) + * [#8958](https://github.com/magento/magento2/issues/8958) -- Hint mistake in english language (fixed in [#11390](https://github.com/magento/magento2/pull/11390)) +* GitHub pull requests: + * [#11067](https://github.com/magento/magento2/pull/11067) -- Fix dob date validation on custom locale (by @joachimVT) + * [#11054](https://github.com/magento/magento2/pull/11054) -- Add dev:tests:run parameter to pass arguments to phpunit (by @schmengler) + * [#11056](https://github.com/magento/magento2/pull/11056) -- Do not disable maintenance mode after running a backup. (by @stevenvdp) + * [#11058](https://github.com/magento/magento2/pull/11058) -- Escape html before replace new line with break (by @Quinten) + * [#11063](https://github.com/magento/magento2/pull/11063) -- 6712 Remove additional margin for footer links widget; prevents layou… (by @fragdochkarl) + * [#11064](https://github.com/magento/magento2/pull/11064) -- Show different message if DB module version is higher than code modul… (by @schmengler) + * [#11076](https://github.com/magento/magento2/pull/11076) -- Backport to 2.2 of #10824: add name for order items grid default renderer block (by @gsomoza) + * [#11048](https://github.com/magento/magento2/pull/11048) -- Fix #10417 (by @PieterCappelle) + * [#11049](https://github.com/magento/magento2/pull/11049) -- Vague error message for invalid url_key for category (by @avdb) + * [#11069](https://github.com/magento/magento2/pull/11069) -- Error message in product review form not being translated (by @Echron) + * [#11127](https://github.com/magento/magento2/pull/11127) -- Add missing return statements in setters (by @niccifor) + * [#11138](https://github.com/magento/magento2/pull/11138) -- Added template as argument to the store address renderer to allow custom formatting (by @jokeputs) + * [#11147](https://github.com/magento/magento2/pull/11147) -- Fix the correct removal of the images and the removal of all images in the catalog (by @raumatbel) + * [#11154](https://github.com/magento/magento2/pull/11154) -- Issue #9877: Backport of: getCacheTags for price issue #10930 (by @denysbabenko) + * [#11160](https://github.com/magento/magento2/pull/11160) -- Ported Down changes from PR#10919 (by @strell) + * [#11200](https://github.com/magento/magento2/pull/11200) -- Delete CallExit function for After plugin logic execution 2.2-develop [BackPort] (by @osrecio) + * [#11168](https://github.com/magento/magento2/pull/11168) -- Fixed issue #10738: Don't display attribute label if defined as "none" in layout (by @maksek) + * [#11223](https://github.com/magento/magento2/pull/11223) -- Cms page/block eventprefix fix issue 9900 (by @convenient) + * [#11229](https://github.com/magento/magento2/pull/11229) -- Disable secret key validation on admin noroute to fix redirect loop (by @convenient) + * [#11050](https://github.com/magento/magento2/pull/11050) -- Only prompt for deploy command in production mode (by @schmengler) + * [#11134](https://github.com/magento/magento2/pull/11134) -- Fix 404 status header (by @Zifius) + * [#11084](https://github.com/magento/magento2/pull/11084) -- Fix in stripped min length validation when value has special characters (by @rubenRP) + * [#11246](https://github.com/magento/magento2/pull/11246) -- Can't close mobile search bar (by @crissanclick) + * [#11254](https://github.com/magento/magento2/pull/11254) -- Fix for #10317 Disable region list when switching to a region optional country. (by @romainruaud) + * [#11155](https://github.com/magento/magento2/pull/11155) -- Refactor ConfigGenerator to replace/set crypt key instead of append (by @renttek) + * [#11291](https://github.com/magento/magento2/pull/11291) -- Fix #9243 - Upgrade ZF components. Zend_Service (by @dverkade) + * [#11165](https://github.com/magento/magento2/pull/11165) -- #7582: use setStoreId after custom load method to give storeId precedence (by @bka) + * [#11297](https://github.com/magento/magento2/pull/11297) -- Fix for issue #5105 - Error While send Invoice with Grouped Products (by @michielgerritsen) + * [#11327](https://github.com/magento/magento2/pull/11327) -- Fix #10812: htaccess Options override (by @dverkade) + * [#11081](https://github.com/magento/magento2/pull/11081) -- Text updated. (by @RakeshJesadiya) + * [#11183](https://github.com/magento/magento2/pull/11183) -- FIX for #11166 Index Handling Fatal Error (by @larsroettig) + * [#11205](https://github.com/magento/magento2/pull/11205) -- Fixes #11163 missing data key code-entity in CMS page edit form (by @Tomasz-Silpion) + * [#11219](https://github.com/magento/magento2/pull/11219) -- Fix typo in sessionStorage polyfill (by @mszydlo) + * [#11249](https://github.com/magento/magento2/pull/11249) -- Add a payload extender to the default shipping-save-processor (Backport to 2.2) (by @navarr) + * [#11345](https://github.com/magento/magento2/pull/11345) -- Use US English spelling for "Optimization". (by @davidangel) + * [#11349](https://github.com/magento/magento2/pull/11349) -- Bug fix update attributes (by @manuelson) + * [#11390](https://github.com/magento/magento2/pull/11390) -- Fix typo in design rule hint message (by @jahvi) + +2.2.0 +============= +* GitHub issues: + * [#8287](https://github.com/magento/magento2/issues/8287) -- InputException while updating cart with Minimum order amount enabled (fixed in [#8474](https://github.com/magento/magento2/pull/8474)) + * [#8315](https://github.com/magento/magento2/issues/8315) -- Error with StdoTest (fixed in [#8487](https://github.com/magento/magento2/pull/8487)) + * [#5808](https://github.com/magento/magento2/issues/5808) -- [2.1.0] Problem on mobile when catalog gallery allowfullscreen is false (fixed in [#8434](https://github.com/magento/magento2/pull/8434)) + * [#8392](https://github.com/magento/magento2/issues/8392) -- Initial loading of the related-products sorting fails in Edge-Mode (fixed in [#8467](https://github.com/magento/magento2/pull/8467)) + * [#8076](https://github.com/magento/magento2/issues/8076) -- Currency Setup in admin throws in_array error when a single value is selected (fixed in [#8077](https://github.com/magento/magento2/pull/8077)) + * [#8277](https://github.com/magento/magento2/issues/8277) -- CatalogImportExport uploader can't handle HTTPS images (fixed in [#8278](https://github.com/magento/magento2/pull/8278)) + * [#7353](https://github.com/magento/magento2/issues/7353) -- Crosssells are never shown when using product/list/items.phtml template (fixed in [#8602](https://github.com/magento/magento2/pull/8602)) + * [#8632](https://github.com/magento/magento2/issues/8632) -- Location of wishlist.js file is incorrect (fixed in [#8633](https://github.com/magento/magento2/pull/8633)) + * [#6634](https://github.com/magento/magento2/issues/6634) -- Yes/No attribute value is not shown on a product details page (fixed in [#8623](https://github.com/magento/magento2/pull/8623)) + * [#8566](https://github.com/magento/magento2/issues/8566) -- Setting 'show_out_of_stock' to 'No' has no effect (fixed in [#8736](https://github.com/magento/magento2/pull/8736)) + * [#6706](https://github.com/magento/magento2/issues/6706) -- Notice undefined index when changes swatch attribute (fixed in [#6707](https://github.com/magento/magento2/pull/6707)) + * [#6855](https://github.com/magento/magento2/issues/6855) -- Create order via backend doesn't work after using NL translation for order-header (fixed in [#6856](https://github.com/magento/magento2/pull/6856)) + * [#8515](https://github.com/magento/magento2/issues/8515) -- Downloadable product is available for download even if order state is set canceled. (fixed in [#8917](https://github.com/magento/magento2/pull/8917)) + * [#8871](https://github.com/magento/magento2/issues/8871) -- Typo in Pull Request Template (fixed in [#8908](https://github.com/magento/magento2/pull/8908)) + * [#3791](https://github.com/magento/magento2/issues/3791) -- Error review when customer is not logged (fixed in [#9001](https://github.com/magento/magento2/pull/9001)) + * [#9017](https://github.com/magento/magento2/issues/9017) -- Duplicate call to $this->getLinkField(); (fixed in [#9057](https://github.com/magento/magento2/pull/9057)) + * [#7498](https://github.com/magento/magento2/issues/7498) -- Grammar Mistake: You don't subscribe to our newsletter. (fixed in [#9080](https://github.com/magento/magento2/pull/9080)) + * [#9078](https://github.com/magento/magento2/issues/9078) -- Does not translate "Track All Shipments" in My Account, view order (fixed in [#9095](https://github.com/magento/magento2/pull/9095)) + * [#5731](https://github.com/magento/magento2/issues/5731) -- FPT label not translatable in the totals on the cart page. (fixed in [#9204](https://github.com/magento/magento2/pull/9204)) + * [#5040](https://github.com/magento/magento2/issues/5040) -- Change 'select' to 'query' in AbstractSearchResult (fixed in [#5043](https://github.com/magento/magento2/pull/5043)) + * [#8761](https://github.com/magento/magento2/issues/8761) -- Popup-Modal not closing on Safari/Windows (fixed in [#8824](https://github.com/magento/magento2/pull/8824)) + * [#7549](https://github.com/magento/magento2/issues/7549) -- Google API Tracking code missing single quote after account number (fixed in [#9084](https://github.com/magento/magento2/pull/9084)) + * [#1146](https://github.com/magento/magento2/issues/1146) -- A few issues when you use /pub as DocumentRoot (fixed in [#9094](https://github.com/magento/magento2/pull/9094)) + * [#2802](https://github.com/magento/magento2/issues/2802) -- Sitemap generation in wrong folder when vhost is connected to pub folder (fixed in [#9094](https://github.com/magento/magento2/pull/9094)) + * [#9200](https://github.com/magento/magento2/issues/9200) -- Create new CLI command: Enable DB logging (fixed in [#9264](https://github.com/magento/magento2/pull/9264)) + * [#9199](https://github.com/magento/magento2/issues/9199) -- Create New CLI command: Generate Varnish VCL file (fixed in [#9286](https://github.com/magento/magento2/pull/9286)) + * [#6822](https://github.com/magento/magento2/issues/6822) -- CSS Minify Option Breaks inline SVG XML (fixed in [#9027](https://github.com/magento/magento2/pull/9027)) + * [#8552](https://github.com/magento/magento2/issues/8552) -- CSS Minifying not compatible with CSS3 calc() function (fixed in [#9027](https://github.com/magento/magento2/pull/9027)) + * [#9236](https://github.com/magento/magento2/issues/9236) -- Upgrade ZF components. Zend_Json (fixed in [#9262](https://github.com/magento/magento2/pull/9262) and [#9261](https://github.com/magento/magento2/pull/9261) and [#9344](https://github.com/magento/magento2/pull/9344) and [#9753](https://github.com/magento/magento2/pull/9753) and [#9754](https://github.com/magento/magento2/pull/9754)) + * [#7523](https://github.com/magento/magento2/issues/7523) -- Zend_Db_Statement_Exception after refreshing browser with empty category (fixed in [#9400](https://github.com/magento/magento2/pull/9400)) + * [#9237](https://github.com/magento/magento2/issues/9237) -- Upgrade ZF components. Zend_Log (fixed in [#9285](https://github.com/magento/magento2/pull/9285)) + * [#9518](https://github.com/magento/magento2/issues/9518) -- Chrome version 58 causes problems with selections in the tinymce editor (fixed in [#9540](https://github.com/magento/magento2/pull/9540)) + * [#9241](https://github.com/magento/magento2/issues/9241) -- Upgrade ZF components. Zend_Wildfire (fixed in [#9622](https://github.com/magento/magento2/pull/9622)) + * [#9239](https://github.com/magento/magento2/issues/9239) -- Upgrade ZF components. Zend_Controller (fixed in [#9622](https://github.com/magento/magento2/pull/9622)) + * [#6455](https://github.com/magento/magento2/issues/6455) -- Cookie Restriction Mode Overlay is cached by Varnish (fixed in [#9711](https://github.com/magento/magento2/pull/9711)) + * [#5596](https://github.com/magento/magento2/issues/5596) -- Google Universal Analytics does not track when Cookie Restriction is enabled (fixed in [#9713](https://github.com/magento/magento2/pull/9713)) + * [#6441](https://github.com/magento/magento2/issues/6441) -- Google Analytics Tracking Code cached by Varnish if Cookie Restriction Settings are active (fixed in [#9713](https://github.com/magento/magento2/pull/9713)) + * [#9242](https://github.com/magento/magento2/issues/9242) -- Upgrade ZF components. Zend_Session (fixed in [#9348](https://github.com/magento/magento2/pull/9348)) + * [#7279](https://github.com/magento/magento2/issues/7279) -- Bill-to Name and Ship-to Name trancated to 20 characters in backend (fixed in [#9654](https://github.com/magento/magento2/pull/9654)) + * [#6151](https://github.com/magento/magento2/issues/6151) -- Can't delete last item in cart if Minimum Order is Enable (fixed in [#9714](https://github.com/magento/magento2/pull/9714)) + * [#4272](https://github.com/magento/magento2/issues/4272) -- v2.0.4 Credit memos with adjustment fees cannot be fully refunded with a second credit memo (fixed in [#9715](https://github.com/magento/magento2/pull/9715)) + * [#6207](https://github.com/magento/magento2/issues/6207) -- Checkbox IDs for Terms and Conditions should be unique in Checkout (fixed in [#9717](https://github.com/magento/magento2/pull/9717)) + * [#7844](https://github.com/magento/magento2/issues/7844) -- Customer with unique attribute can't be saved (fixed in [#9712](https://github.com/magento/magento2/pull/9712)) + * [#6244](https://github.com/magento/magento2/issues/6244) -- Promo code label not used (fixed in [#9721](https://github.com/magento/magento2/pull/9721)) + * [#9771](https://github.com/magento/magento2/issues/9771) -- XML instruction referenceBlock does not allow template= or does it? (fixed in [#9772](https://github.com/magento/magento2/pull/9772)) + * [#8221](https://github.com/magento/magento2/issues/8221) -- Javascript "mixins" doesn't works if 'urlArgs' is in requirejs-config.js (fixed in [#9665](https://github.com/magento/magento2/pull/9665)) + * [#9278](https://github.com/magento/magento2/issues/9278) -- Create new CLI command: Enable Template Hints (fixed in [#9778](https://github.com/magento/magento2/pull/9778)) + * [#9819](https://github.com/magento/magento2/issues/9819) -- Authentication_lock settings cannot be edited in the Backend (fixed in [#9820](https://github.com/magento/magento2/pull/9820)) + * [#9216](https://github.com/magento/magento2/issues/9216) -- Coupon codes not showing in invoice print out (fixed in [#9780](https://github.com/magento/magento2/pull/9780)) + * [#9679](https://github.com/magento/magento2/issues/9679) -- Translation for layered navigation attribute option not working (fixed in [#9873](https://github.com/magento/magento2/pull/9873)) + * [#3060](https://github.com/magento/magento2/issues/3060) -- setup:static-content:deploy, setup:di:compile and deploy:mode:set will not return a non-zero exit code if any error occurs (fixed in [#7780](https://github.com/magento/magento2/pull/7780)) + * [#9421](https://github.com/magento/magento2/issues/9421) -- Inconsistent Gift Options checkbox labels (fixed in [#9525](https://github.com/magento/magento2/pull/9525)) + * [#9805](https://github.com/magento/magento2/issues/9805) -- Static tests in Windows fail due to file path mismatches (fixed in [#9902](https://github.com/magento/magento2/pull/9902)) + * [#9924](https://github.com/magento/magento2/issues/9924) -- Prefix and suffix are not prefilled in the quote shipping address (fixed in [#9925](https://github.com/magento/magento2/pull/9925)) + * [#4237](https://github.com/magento/magento2/issues/4237) -- Cron times in the database have a double timezone correction (fixed in [#9943](https://github.com/magento/magento2/pull/9943)) + * [#9426](https://github.com/magento/magento2/issues/9426) -- Incorrect order date in Orders grid (fixed in [#9941](https://github.com/magento/magento2/pull/9941)) + * [#3380](https://github.com/magento/magento2/issues/3380) -- Remove scheduled jobs after changing cron settings (fixed in [#9957](https://github.com/magento/magento2/pull/9957)) + * [#7504](https://github.com/magento/magento2/issues/7504) -- sitemap image URLs do not match with those on product pages (fixed in [#9082](https://github.com/magento/magento2/pull/9082)) + * [#8732](https://github.com/magento/magento2/issues/8732) -- The country drop-down list display incorrect after upgrade to 2.1.4 in Admin (fixed in [#9429](https://github.com/magento/magento2/pull/9429)) + * [#9680](https://github.com/magento/magento2/issues/9680) -- Adding product configurations uses sku based name (fixed in [#9681](https://github.com/magento/magento2/pull/9681)) + * [#10017](https://github.com/magento/magento2/issues/10017) -- Customer Backend: Confirmation Flag is being overwritten by save of the Customer (fixed in [#9681](https://github.com/magento/magento2/pull/9681)) + * [#2266](https://github.com/magento/magento2/issues/2266) -- Action column menu does not stay over the action column (fixed in [#10082](https://github.com/magento/magento2/pull/10082)) + * [#5381](https://github.com/magento/magento2/issues/5381) -- Cannot create a `etc/view.xml` file with an `images` tag with an attribute `module` other than `Magento_Catalog` (fixed in [#10052](https://github.com/magento/magento2/pull/10052)) + * [#6337](https://github.com/magento/magento2/issues/6337) -- Not able to translate page layout head titles (fixed in [#9992](https://github.com/magento/magento2/pull/9992)) + * [#3872](https://github.com/magento/magento2/issues/3872) -- Slash as category URL suffix gives 404 error on all category pages (fixed in [#10043](https://github.com/magento/magento2/pull/10043)) + * [#4660](https://github.com/magento/magento2/issues/4660) -- Multiple URLs causes duplicated content (fixed in [#10043](https://github.com/magento/magento2/pull/10043)) + * [#4876](https://github.com/magento/magento2/issues/4876) -- Product URL Suffix "/" results in 404 error (fixed in [#10043](https://github.com/magento/magento2/pull/10043)) + * [#8264](https://github.com/magento/magento2/issues/8264) -- Custom URL Rewrite where the request path ends with a forward slash is not matched (fixed in [#10043](https://github.com/magento/magento2/pull/10043)) + * [#6396](https://github.com/magento/magento2/issues/6396) -- Cart Price Rules: Category selection UI for Conditions do not come up. (fixed in [#10094](https://github.com/magento/magento2/pull/10094)) + * [#10124](https://github.com/magento/magento2/issues/10124) -- Wrong order of "width" x "height" when uploading image to admin under Content>Design Config (fixed in [#10126](https://github.com/magento/magento2/pull/10126)) + * [#6594](https://github.com/magento/magento2/issues/6594) -- Magento 2.1 EE: simplexml_load_string() error in custom widget (fixed in [#10151](https://github.com/magento/magento2/pull/10151)) + * [#10148](https://github.com/magento/magento2/issues/10148) -- Developer ACL incorrect (fixed in [#10149](https://github.com/magento/magento2/pull/10149)) + * [#9445](https://github.com/magento/magento2/issues/9445) -- Cart 860 does not contain item 1204 (fixed in [#10059](https://github.com/magento/magento2/pull/10059)) +* GitHub pull requests: + * [#4078](https://github.com/magento/magento2/pull/4078) -- Add logo folder to list of allowed resources (by @thaiphan) + * [#4355](https://github.com/magento/magento2/pull/4355) -- Enforce password and password-confirm as strings (by @nevvermind) + * [#4175](https://github.com/magento/magento2/pull/4175) -- PHP 7 (by @rafaelstz) + * [#4669](https://github.com/magento/magento2/pull/4669) -- Php 5.5 support was removed (by @fooman) + * [#4766](https://github.com/magento/magento2/pull/4766) -- The time has come for splat operator (by @orlangur) + * [#4867](https://github.com/magento/magento2/pull/4867) -- Fix commandExecutor interface mismatch (by @wexo-team) + * [#3705](https://github.com/magento/magento2/pull/3705) -- fix issue #3704 regarding integer attribute values being cast to decimal (by @digitalpianism) + * [#3750](https://github.com/magento/magento2/pull/3750) -- Add ability to show custom error message on Authorizenet place order (by @ytorbyk) + * [#3859](https://github.com/magento/magento2/pull/3859) -- Fixes _toHtml method of Checkout/Block/Cart/Link class (by @ddonnini) + * [#4017](https://github.com/magento/magento2/pull/4017) -- Add the $t to translate the message (by @mamzellejuu) + * [#4239](https://github.com/magento/magento2/pull/4239) -- Attribute Model specifiable in Propertymapper (by @liolemaire) + * [#4583](https://github.com/magento/magento2/pull/4583) -- Fix desktop spelling in lib/web/css #4557 (by @BenSpace48) + * [#2735](https://github.com/magento/magento2/pull/2735) -- Add database port to Magento Setup Model Installer (by @tkn98) + * [#4275](https://github.com/magento/magento2/pull/4275) -- Database port missing in Magento\TestFramework\Db\Mysql #3529 (by @gordonknoppe) + * [#4372](https://github.com/magento/magento2/pull/4372) -- Remove unused property + use ::class (by @nevvermind) + * [#2274](https://github.com/magento/magento2/pull/2274) -- TypeError: this.trigger is not a function (by @daim2k5) + * [#3050](https://github.com/magento/magento2/pull/3050) -- Replace PrototypeJS (by @srenon) + * [#3436](https://github.com/magento/magento2/pull/3436) -- Fix stripped-min-length check (by @avoelkl) + * [#3638](https://github.com/magento/magento2/pull/3638) -- Fix #3637 Add missing catalogsearch layout for swatches. (by @romainruaud) + * [#3633](https://github.com/magento/magento2/pull/3633) -- #768 - fix Missing acl.xml for the Magento_Checkout module (by @tzyganu) + * [#3708](https://github.com/magento/magento2/pull/3708) -- Add 'yyyy' to nomalizedDate method map for adminhtml i18n (by @Amakata) + * [#3973](https://github.com/magento/magento2/pull/3973) -- fix bug on newsletter subscription action when user use an existing email already subscribed (by @manfrinm) + * [#3932](https://github.com/magento/magento2/pull/3932) -- Update Date.php (by @Maddesto) + * [#3907](https://github.com/magento/magento2/pull/3907) -- Update Layout.php (by @Maddesto) + * [#4051](https://github.com/magento/magento2/pull/4051) -- Fix "minimum-length" option of the "validate-length" JS validation (by @adragus-inviqa) + * [#4269](https://github.com/magento/magento2/pull/4269) -- ConfigurableProduct validator, first check if array item exists (by @BlackIkeEagle) + * [#4496](https://github.com/magento/magento2/pull/4496) -- Access element through jQuery (by @sikker) + * [#4631](https://github.com/magento/magento2/pull/4631) -- Previous is spelt incorrectly (by @BenSpace48) + * [#4882](https://github.com/magento/magento2/pull/4882) -- Fix handling is_region_required key as optional (by @komsitr) + * [#5028](https://github.com/magento/magento2/pull/5028) -- Load jquery using requirejs to print page (by @Bartlomiejsz) + * [#1957](https://github.com/magento/magento2/pull/1957) -- Add required interface implementation (by @udovicic) + * [#2492](https://github.com/magento/magento2/pull/2492) -- No translation from "Orders and Returns" footer links (by @mageho) + * [#3749](https://github.com/magento/magento2/pull/3749) -- Stop screen loader on payment error (by @ytorbyk) + * [#4901](https://github.com/magento/magento2/pull/4901) -- Fix XML validation value type of post-code to "boolean" (by @adragus-inviqa) + * [#5066](https://github.com/magento/magento2/pull/5066) -- Add underscore as dependency to quote.js (by @Bartlomiejsz) + * [#5116](https://github.com/magento/magento2/pull/5116) -- Fixes invalid json objects in the order email templates. (by @hostep) + * [#5095](https://github.com/magento/magento2/pull/5095) -- Fix integration test expectation to match count of countries in the database (by @Vinai) + * [#5200](https://github.com/magento/magento2/pull/5200) -- Adminhtml sales view - Escape remoteIp (by @convenient) + * [#4294](https://github.com/magento/magento2/pull/4294) -- Static deploy flags (by @denisristic) + * [#3137](https://github.com/magento/magento2/pull/3137) -- Update nginx.conf.sample (by @thaiphan) + * [#3746](https://github.com/magento/magento2/pull/3746) -- Add HttpInterface methods and add up-casts for type safety (by @Vinai) + * [#4354](https://github.com/magento/magento2/pull/4354) -- Adds test for getDataUsingMethod using digits (by @fooman) + * [#4396](https://github.com/magento/magento2/pull/4396) -- Don't hardcode the Magento_Backend::admin index (by @annybs) + * [#4491](https://github.com/magento/magento2/pull/4491) -- Correction: variable naming for user roles & role id (by @MagePsycho) + * [#4519](https://github.com/magento/magento2/pull/4519) -- Create auth.json.sample (by @rafaelstz) + * [#3688](https://github.com/magento/magento2/pull/3688) -- added partial fix for issue #2617. (by @whizkid79) + * [#3770](https://github.com/magento/magento2/pull/3770) -- Bugfix: Unable to activate search form on phone (by @vovayatsyuk) + * [#4011](https://github.com/magento/magento2/pull/4011) -- Fixed post var name for update attributes (by @Corefix) + * [#2791](https://github.com/magento/magento2/pull/2791) -- Update Template.php (by @liam-wiltshire) + * [#5496](https://github.com/magento/magento2/pull/5496) -- Fixes #5495 (Mobile navigation submenus need two clicks to open) (by @ajpevers) + * [#5725](https://github.com/magento/magento2/pull/5725) -- Fix/translation in validation files (by @dvynograd) + * [#5915](https://github.com/magento/magento2/pull/5915) -- Added missing translation to range grid filter (by @maqlec) + * [#5884](https://github.com/magento/magento2/pull/5884) -- Use alias already defined in requirejs-config.js (by @kassner) + * [#4388](https://github.com/magento/magento2/pull/4388) -- Fixed column description for "website_id" column (by @ikk0) + * [#1628](https://github.com/magento/magento2/pull/1628) -- Add cache of configuration files list (by @otakarmare) + * [#4791](https://github.com/magento/magento2/pull/4791) -- Replace fabpot/php-cs-fixer with friendsofphp/php-cs-fixer (by @GordonLesti) + * [#5983](https://github.com/magento/magento2/pull/5983) -- Fix 'Track your order' i18n. (by @peec) + * [#1988](https://github.com/magento/magento2/pull/1988) -- Use inline elements for inline links (by @chicgeek) + * [#6283](https://github.com/magento/magento2/pull/6283) -- Update elements.xsd (by @aholovan) + * [#1935](https://github.com/magento/magento2/pull/1935) -- Added 'target' attribute to the allowed attributes array for link block (by @fcapua-summa) + * [#4733](https://github.com/magento/magento2/pull/4733) -- Escape Js Quote for layout updates (by @bchatard) + * [#4565](https://github.com/magento/magento2/pull/4565) -- Update Container.php (by @Maddesto) + * [#4845](https://github.com/magento/magento2/pull/4845) -- Set return code for SetModeCommand (by @mc388) + * [#2037](https://github.com/magento/magento2/pull/2037) -- Correct the error message when creating wrong object for block (by @hiephm) + * [#3779](https://github.com/magento/magento2/pull/3779) -- Add dispatching of view_block_abstract_to_html_after event (by @aleron75) + * [#5741](https://github.com/magento/magento2/pull/5741) -- Update AbstractTemplate.php (by @vivek201) + * [#5145](https://github.com/magento/magento2/pull/5145) -- \Magento\CatalogInventory\Model\Stock\Status->getStockId() to return correct value (by @fe-lix-) + * [#6009](https://github.com/magento/magento2/pull/6009) -- Update README.md (by @fooman) + * [#6280](https://github.com/magento/magento2/pull/6280) -- Fixed layout for customer authentication popup (by @rogyar) + * [#6549](https://github.com/magento/magento2/pull/6549) -- Remove obsolete comment in catalog_category_view.xml (by @pdanzinger) + * [#6804](https://github.com/magento/magento2/pull/6804) -- Fix nav not working in mobile (by @slackerzz) + * [#6801](https://github.com/magento/magento2/pull/6801) -- Fixed unclosed span tag in Review module (by @PingusPepan) + * [#5045](https://github.com/magento/magento2/pull/5045) -- Fix runner for JsTestDriver based tests on OS X (by @Vinai) + * [#4958](https://github.com/magento/magento2/pull/4958) -- block newsletter title (by @slackerzz) + * [#5548](https://github.com/magento/magento2/pull/5548) -- Fix error with the WYSIWYG and Greek characters (by @sakisplus) + * [#7256](https://github.com/magento/magento2/pull/7256) -- Fix incorrect table name during catalog product indexing (by @nagno) + * [#6972](https://github.com/magento/magento2/pull/6972) -- Fix issue #6968 since checkout success title is not displayed (by @AngelVazquezArroyo) + * [#4121](https://github.com/magento/magento2/pull/4121) -- Ensure composer.json exists (by @dank00) + * [#4134](https://github.com/magento/magento2/pull/4134) -- Added call to action to compile command error (by @sammarcus) + * [#6974](https://github.com/magento/magento2/pull/6974) -- Fixed calling non exists order address->getCountry to getCountryId (by @magexo) + * [#4088](https://github.com/magento/magento2/pull/4088) -- Fix newsletter queue subscribers adding performance (by @DariuszMaciejewski) + * [#6952](https://github.com/magento/magento2/pull/6952) -- Update AccountLock.php (by @klict) + * [#5465](https://github.com/magento/magento2/pull/5465) -- Fix Magento\Review\Model\ResourceModel\Rating\Option not instantiable in setup scripts (by @adragus-inviqa) + * [#7799](https://github.com/magento/magento2/pull/7799) -- Remove duplicate code from template file. (by @dverkade) + * [#7919](https://github.com/magento/magento2/pull/7919) -- Using Dynamic Protocol Concatination (by @brobie) + * [#7921](https://github.com/magento/magento2/pull/7921) -- Removed un-used static version rewrite rule in nginx.conf.sample (by @careys7) + * [#8019](https://github.com/magento/magento2/pull/8019) -- added fr_CH to allowed locales list (by @annapivniak) + * [#8082](https://github.com/magento/magento2/pull/8082) -- issue 8080: Cron configuration loading from DB doesn't work (by @ytorbyk) + * [#8062](https://github.com/magento/magento2/pull/8062) -- Fix theme source model used in widget grid (by @Zefiryn) + * [#8232](https://github.com/magento/magento2/pull/8232) -- Fix notice during DI compilation (by @qrz-io) + * [#8306](https://github.com/magento/magento2/pull/8306) -- Remove warning from setup/src/Magento/Setup/Module/I18n/Dictionary/Writer/Csv.php (by @dmanners) + * [#8185](https://github.com/magento/magento2/pull/8185) -- Fix #7461 using the simplest approach for now (by @lazyguru) + * [#8183](https://github.com/magento/magento2/pull/8183) -- [BUGFIX] Fixed the credit memo guest email (by @nickgraz) + * [#8161](https://github.com/magento/magento2/pull/8161) -- Return focus to search input after closing autocomplete dropdown (by @evktalo) + * [#8155](https://github.com/magento/magento2/pull/8155) -- Correct php doc (by @angelomaragna) + * [#8341](https://github.com/magento/magento2/pull/8341) -- Use better function for 'Continue Shopping' url (by @dmatthew) + * [#8336](https://github.com/magento/magento2/pull/8336) -- fixing time format on admin sales order grid (by @magexo) + * [#8327](https://github.com/magento/magento2/pull/8327) -- Change order of parameters passed to LogicException in AbstractTemplate.php (by @bery) + * [#8307](https://github.com/magento/magento2/pull/8307) -- Allow digits in communication class type definition (by @cmuench) + * [#8354](https://github.com/magento/magento2/pull/8354) -- Display correctly "Add" button label for the block class \Magento\Con… (by @diglin) + * [#8246](https://github.com/magento/magento2/pull/8246) -- Fixes #7723 - saving multi select field in UI component form (by @Zefiryn) + * [#8353](https://github.com/magento/magento2/pull/8353) -- Replace into the layout adminhtml_order_shipment_new.xml block alias … (by @diglin) + * [#8395](https://github.com/magento/magento2/pull/8395) -- Added "editPost" action for customer sections.xml (by @rossluk) + * [#8383](https://github.com/magento/magento2/pull/8383) -- Issue/8382 (by @PascalBrouwers) + * [#8151](https://github.com/magento/magento2/pull/8151) -- Remove "<2.7" constraint on symfony/console (by @nicolas-grekas) + * [#8416](https://github.com/magento/magento2/pull/8416) -- Use configured product attributes in wishlist item collection (by @schmengler) + * [#8414](https://github.com/magento/magento2/pull/8414) -- Replace toGMTString with toUTCString (by @schmengler) + * [#8419](https://github.com/magento/magento2/pull/8419) -- Use page result instead of rendering layout directly in controllers (by @schmengler) + * [#8331](https://github.com/magento/magento2/pull/8331) -- Remove Zend1 Json from Magento Captcha module (by @dmanners) + * [#8252](https://github.com/magento/magento2/pull/8252) -- Customer account edit form: additional info block visible (by @Sylvco) + * [#8405](https://github.com/magento/magento2/pull/8405) -- Remove the unused Ajax/Serializer.php class (by @dmanners) + * [#8402](https://github.com/magento/magento2/pull/8402) -- Remove Zend1 db from captcha module (by @dmanners) + * [#8463](https://github.com/magento/magento2/pull/8463) -- Remove outdated comment (by @evktalo) + * [#8456](https://github.com/magento/magento2/pull/8456) -- Specifically ask for the Json Serializer object Mage Braintree (by @dmanners) + * [#8446](https://github.com/magento/magento2/pull/8446) -- Fix "each()" function call on potentially invalid data (by @giacmir) + * [#5928](https://github.com/magento/magento2/pull/5928) -- prevent double shipping method selection (by @danslo) + * [#8217](https://github.com/magento/magento2/pull/8217) -- Update DataProvider.php (by @redelschaap) + * [#8413](https://github.com/magento/magento2/pull/8413) -- Load translations for area, fixes #8412 (by @fooman) + * [#8356](https://github.com/magento/magento2/pull/8356) -- Remove Zend1 captcha from Magento2 Captcha module (by @dmanners) + * [#8474](https://github.com/magento/magento2/pull/8474) -- Fix for https://github.com/magento/magento2/issues/8287 (by @ericrisler) + * [#8487](https://github.com/magento/magento2/pull/8487) -- Mark the STDO test as skipped (by @dmanners) + * [#3155](https://github.com/magento/magento2/pull/3155) -- Remove unused variables in unit test (by @fooman) + * [#6049](https://github.com/magento/magento2/pull/6049) -- Added typo correction for table name comment (by @atishgoswami) + * [#4370](https://github.com/magento/magento2/pull/4370) -- update Catalog Helper (by @barbarich-p) + * [#4106](https://github.com/magento/magento2/pull/4106) -- Adds support for purging varnish cache based on an X-Pool header (by @davidalger) + * [#7982](https://github.com/magento/magento2/pull/7982) -- Add bin/magento commands to list store/website data (by @convenient) + * [#8434](https://github.com/magento/magento2/pull/8434) -- Problem on mobile when catalog gallery allowfullscreen is false #5808 (by @Crossmotion) + * [#8417](https://github.com/magento/magento2/pull/8417) -- add anonymize ip option for google analytics (by @thomas-villagers) + * [#8498](https://github.com/magento/magento2/pull/8498) -- Product->save() shouldn't be called directly (by @stansm) + * [#8581](https://github.com/magento/magento2/pull/8581) -- Fixed overly bold icons in Firefox Mac (by @TandyCorp) + * [#8481](https://github.com/magento/magento2/pull/8481) -- Remove zend json checkout (by @dmanners) + * [#8518](https://github.com/magento/magento2/pull/8518) -- Change link text from "Report Bugs" to "Report a Bug" (by @Zifius) + * [#8514](https://github.com/magento/magento2/pull/8514) -- Add missing name attributes to catalog_product_view layout xml (by @andrewnoble) + * [#8505](https://github.com/magento/magento2/pull/8505) -- Update the Adminhtml image tree JSON (by @dmanners) + * [#8467](https://github.com/magento/magento2/pull/8467) -- Fix for magento/magento2#8392 (by @kirashet666) + * [#8617](https://github.com/magento/magento2/pull/8617) -- Remove Zend_Json from Customer module (by @dmanners) + * [#8609](https://github.com/magento/magento2/pull/8609) -- [PHP 7.1 Compatibility] Void became a reserved word (by @orlangur) + * [#8611](https://github.com/magento/magento2/pull/8611) -- Fix #8308: test setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php crashes in debug mode (by @orlangur) + * [#8610](https://github.com/magento/magento2/pull/8610) -- Fix #8315: test setup/src/Magento/Setup/Test/Unit/Module/I18n/Dictionary/Writer/Csv/StdoTest.php crashes in debug mode (by @orlangur) + * [#7339](https://github.com/magento/magento2/pull/7339) -- Fix/xml parser issue (by @dvynograd) + * [#7345](https://github.com/magento/magento2/pull/7345) -- Fix typo (by @mpchadwick) + * [#7406](https://github.com/magento/magento2/pull/7406) -- MAGETWO-60448 (by @vasilii-b) + * [#8000](https://github.com/magento/magento2/pull/8000) -- Set static html fragments as cacheable (by @paveq) + * [#8077](https://github.com/magento/magento2/pull/8077) -- Type cast (by @deriknel) + * [#8278](https://github.com/magento/magento2/pull/8278) -- bug #8277 fixing bug with https downloading. (by @clementbeudot) + * [#8420](https://github.com/magento/magento2/pull/8420) -- Refactor contact module (by @schmengler) + * [#8519](https://github.com/magento/magento2/pull/8519) -- Make "is_required" and "is_visible" properties of telephone, company and fax attributes of addresses configurable (by @avstudnitz) + * [#8537](https://github.com/magento/magento2/pull/8537) -- Fixed missing echo statement in checkout cart coupon template (by @FrankRuis) + * [#8602](https://github.com/magento/magento2/pull/8602) -- Fixed crosssells count always null (by @koenner01) + * [#8593](https://github.com/magento/magento2/pull/8593) -- Fix #7371 (by @rossluk) + * [#8642](https://github.com/magento/magento2/pull/8642) -- Update Save.php (by @josefbehr) + * [#8633](https://github.com/magento/magento2/pull/8633) -- Fix #8632 (by @koenner01) + * [#8513](https://github.com/magento/magento2/pull/8513) -- Replace ext name spaces with dashes (as composer does when storing) (by @AydinHassan) + * [#8668](https://github.com/magento/magento2/pull/8668) -- Add correct return type in order service (by @cmuench) + * [#8677](https://github.com/magento/magento2/pull/8677) -- Fixed Doc Block for the dispatch method of the Rest Controller (by @vrann) + * [#3585](https://github.com/magento/magento2/pull/3585) -- Remove duplicate switchIsFilterable (by @GordonLesti) + * [#8132](https://github.com/magento/magento2/pull/8132) -- Fix incorrect schema definition for price (by @unfunco) + * [#2275](https://github.com/magento/magento2/pull/2275) -- Updated links to point to http://devdocs.magento.com/guides/v2.0 (by @wjarka) + * [#8683](https://github.com/magento/magento2/pull/8683) -- Fixed return type of OrderRepository::getList (by @clementbeudot) + * [#8682](https://github.com/magento/magento2/pull/8682) -- Remove unused argument (by @mfdj) + * [#2185](https://github.com/magento/magento2/pull/2185) -- unused variable (by @barbarich-p) + * [#7894](https://github.com/magento/magento2/pull/7894) -- Fix #7893 (by @andreaspenz) + * [#8623](https://github.com/magento/magento2/pull/8623) -- Fix check for boolean product attributes (by @TKlement) + * [#8678](https://github.com/magento/magento2/pull/8678) -- Fixed Issue #8425 (by @DavidLambauer) + * [#8711](https://github.com/magento/magento2/pull/8711) -- Remove Zend_Json from the persistent module remember me status observer (by @dmanners) + * [#8706](https://github.com/magento/magento2/pull/8706) -- Remove Zend_Json from the unit test in the CustomerImportExport module (by @dmanners) + * [#8723](https://github.com/magento/magento2/pull/8723) -- Add active class to search form wrapper for more theming flexibility (by @andrewkett) + * [#8768](https://github.com/magento/magento2/pull/8768) -- Fix issue #8709 (by @renatocason) + * [#8762](https://github.com/magento/magento2/pull/8762) -- Fix issue #2558 (by @renatocason) + * [#8759](https://github.com/magento/magento2/pull/8759) -- magento/magento2#8618: Apply coupon code button issue on Checkout (by @mcspronko) + * [#8776](https://github.com/magento/magento2/pull/8776) -- Range filter doesn't works with 0 values in admin #7103 (by @giacmir) + * [#7611](https://github.com/magento/magento2/pull/7611) -- Update catalog_rule_form.xml edit labels (by @fernandofauth) + * [#7650](https://github.com/magento/magento2/pull/7650) -- Add host header to varnish cache purge request (by @m0zziter) + * [#7914](https://github.com/magento/magento2/pull/7914) -- FPC JS - Fix for CORS issue (by @OZZlE) + * [#8013](https://github.com/magento/magento2/pull/8013) -- Update resets.html (by @ryantfowler) + * [#8041](https://github.com/magento/magento2/pull/8041) -- Fix USPS Priority Mail to Canada (by @jaywilliams) + * [#8014](https://github.com/magento/magento2/pull/8014) -- Update _resets.less (by @ryantfowler) + * [#8053](https://github.com/magento/magento2/pull/8053) -- Strict checking types during di compilation (by @michalderlatka) + * [#8048](https://github.com/magento/magento2/pull/8048) -- Consistent HTML tags and breaks (by @chickenland) + * [#8056](https://github.com/magento/magento2/pull/8056) -- update allowed container tags (by @steros) + * [#8158](https://github.com/magento/magento2/pull/8158) -- Fix OAuth request helper to support Authorization header value parsing with non-leading OAuth key (by @careys7) + * [#8589](https://github.com/magento/magento2/pull/8589) -- Set correct primary keys for temporary tables in product flat indexer (by @jarnooravainen) + * [#8736](https://github.com/magento/magento2/pull/8736) -- Update Stock.php (by @Corefix) + * [#8119](https://github.com/magento/magento2/pull/8119) -- Throw exception for invalid (missing) template in dev mode (by @convenient) + * [#8690](https://github.com/magento/magento2/pull/8690) -- Fix SALES_ORDER_TAX_ITEM_TAX_ID_ITEM_ID duplicates (by @mimarcel) + * [#8743](https://github.com/magento/magento2/pull/8743) -- Validate PHP classnames in di.xml files via schema (by @ktomk) + * [#8714](https://github.com/magento/magento2/pull/8714) -- Quote values in IN() predicate to avoid cast issues (by @xi-ao) + * [#8835](https://github.com/magento/magento2/pull/8835) -- Replace Zend_Json from the Magento Review module (by @dmanners) + * [#8832](https://github.com/magento/magento2/pull/8832) -- Replace Zend_Json from the Magento Quote module (by @dmanners) + * [#8839](https://github.com/magento/magento2/pull/8839) -- Rename to DataObjectTest (by @mfdj) + * [#2199](https://github.com/magento/magento2/pull/2199) -- Rename admin sidebar Products to Catalog #2060 (by @markoshust) + * [#5620](https://github.com/magento/magento2/pull/5620) -- Remove superfluous method call. (by @maksim-grib) + * [#6767](https://github.com/magento/magento2/pull/6767) -- Removed setting routerlist twice. (by @dverkade) + * [#6257](https://github.com/magento/magento2/pull/6257) -- Fix "none" is not meant to be translated in catalog_product_view layout file (by @azanelli) + * [#7645](https://github.com/magento/magento2/pull/7645) -- Storecode in url changed from default to all (by @bartlubbersen) + * [#7864](https://github.com/magento/magento2/pull/7864) -- Bugfix: Fix for not respected alternative headers in maintenance mode (by @cmuench) + * [#7794](https://github.com/magento/magento2/pull/7794) -- Check return value for getProduct() in getPrice(). (by @pbaylies) + * [#8052](https://github.com/magento/magento2/pull/8052) -- Update PurgeCache.php (by @bery) + * [#8130](https://github.com/magento/magento2/pull/8130) -- Update Options.php (by @redelschaap) + * [#8079](https://github.com/magento/magento2/pull/8079) -- FIX Backend mass delete Sql error (by @asubit) + * [#7234](https://github.com/magento/magento2/pull/7234) -- Lossless images optimalization (by @Igloczek) + * [#8685](https://github.com/magento/magento2/pull/8685) -- [PSR-2 Compliance] Fix #8612: Hundreds of PHPCS-based static tests violations in mainline (by @orlangur) + * [#7568](https://github.com/magento/magento2/pull/7568) -- Minor Update Mysql.php (by @WJdeBaas) + * [#7598](https://github.com/magento/magento2/pull/7598) -- Bugfix for _getProductCollection on a product page (by @evgk) + * [#8886](https://github.com/magento/magento2/pull/8886) -- Fix typo in app/code/Magento/Email/Test/Unit/Model/TemplateTest.php (by @orlangur) + * [#5029](https://github.com/magento/magento2/pull/5029) -- Add default swatch_image placeholder (by @Bartlomiejsz) + * [#6838](https://github.com/magento/magento2/pull/6838) -- Removed preference from di.xml (by @dverkade) + * [#7578](https://github.com/magento/magento2/pull/7578) -- Don't skip attribute options with a value of 0 from the layered navigation (by @dcabrejas) + * [#7615](https://github.com/magento/magento2/pull/7615) -- Fixes duplicate messages shown when adding items to cart (by @comdiler) + * [#7590](https://github.com/magento/magento2/pull/7590) -- Reset skippedRows array in clear method (by @ccasciotti) + * [#7701](https://github.com/magento/magento2/pull/7701) -- Allows you to have 0 as a option (by @Corefix) + * [#7748](https://github.com/magento/magento2/pull/7748) -- Remove _required class from ZIP field (by @dmitryshkolnikov) + * [#7743](https://github.com/magento/magento2/pull/7743) -- MAGETWO-61828: Text swatch "zero" not shown (by @oroskodias) + * [#8883](https://github.com/magento/magento2/pull/8883) -- Fix a typo (by @evgk) + * [#7541](https://github.com/magento/magento2/pull/7541) -- Added "Add / update" comment. Update was missing. (by @gastondisacco) + * [#8808](https://github.com/magento/magento2/pull/8808) -- Change link text from "Report a Bug" to "Report an Issue" (by @Zifius) + * [#8907](https://github.com/magento/magento2/pull/8907) -- Removed unused dependencys (by @ikrs) + * [#8910](https://github.com/magento/magento2/pull/8910) -- Prevent overwriting grunt config (by @Igloczek) + * [#7562](https://github.com/magento/magento2/pull/7562) -- Update AbstractCart.php (by @Corefix) + * [#8766](https://github.com/magento/magento2/pull/8766) -- fix $childrenWrapClass never used (by @slackerzz) + * [#8822](https://github.com/magento/magento2/pull/8822) -- Upgrade PHP CS Fixer to v2 (by @keradus) + * [#8901](https://github.com/magento/magento2/pull/8901) -- Update design_config_form.xml (by @WaPoNe) + * [#8896](https://github.com/magento/magento2/pull/8896) -- Fix all words without " (by @rafaelstz) + * [#8912](https://github.com/magento/magento2/pull/8912) -- magento/magento2#8590: M2.1.4 : ArrayBackend cannot save and Added country regions for Croatia (by @nkajic) + * [#8909](https://github.com/magento/magento2/pull/8909) -- magento/magento2#8863: Malta zipcode validation incomplete (by @mmacinko) + * [#2829](https://github.com/magento/magento2/pull/2829) -- Update final_price.phtml (by @liam-wiltshire) + * [#3869](https://github.com/magento/magento2/pull/3869) -- Optional PHP7.0 Socket Path (by @digimix) + * [#4854](https://github.com/magento/magento2/pull/4854) -- Fix admin menu bug (by @NikolasSumrak) + * [#6400](https://github.com/magento/magento2/pull/6400) -- Fix for Product Attribute's Conditions (by @NikolasSumrak) + * [#6677](https://github.com/magento/magento2/pull/6677) -- Update addCategoriesFilter to return $this (by @maciekpaprocki) + * [#6894](https://github.com/magento/magento2/pull/6894) -- Fixed phpseclib\Net\SFTP constants used in write() method (by @federivo) + * [#7117](https://github.com/magento/magento2/pull/7117) -- Add de_LU and fr_LU languages for Luxembourg (by @ajpevers) + * [#8915](https://github.com/magento/magento2/pull/8915) -- magento/magetno2#8676: I can not translate title attribute in xml fil… (by @DanijelPotocki) + * [#5446](https://github.com/magento/magento2/pull/5446) -- Fix Rest Api - GET /V1/configurable-products/{sku}/children not giving ID in response (by @k-andrew) + * [#6321](https://github.com/magento/magento2/pull/6321) -- Add missing return in resolveShippingRates (by @GordonLesti) + * [#6707](https://github.com/magento/magento2/pull/6707) -- Issue/6706 (by @PascalBrouwers) + * [#6794](https://github.com/magento/magento2/pull/6794) -- Move cache to instance of price box widget (by @JamesonNetworks) + * [#6856](https://github.com/magento/magento2/pull/6856) -- Issue/6855 (by @PascalBrouwers) + * [#6837](https://github.com/magento/magento2/pull/6837) -- Removed argument from di.xml (by @dverkade) + * [#6878](https://github.com/magento/magento2/pull/6878) -- Media attribute folder to be ignored (by @rafaelstz) + * [#6914](https://github.com/magento/magento2/pull/6914) -- Put the contants in the same docblock together (by @dverkade) + * [#6913](https://github.com/magento/magento2/pull/6913) -- Removed commented out line for ignoring coding standards (by @dverkade) + * [#7142](https://github.com/magento/magento2/pull/7142) -- [Framework][Translate] Changed translation order to allow language (by @JSchlarb) + * [#7352](https://github.com/magento/magento2/pull/7352) -- Product export duplicate rows for product with html special chars in data. Bugfix for #7350 (by @comdiler) + * [#8445](https://github.com/magento/magento2/pull/8445) -- Changed name of dispatched object in delete event (by @clementbeudot) + * [#8959](https://github.com/magento/magento2/pull/8959) -- Fixes #2461 (by @ajpevers) + * [#8950](https://github.com/magento/magento2/pull/8950) -- Remove deadcode (by @jipjop) + * [#3469](https://github.com/magento/magento2/pull/3469) -- respect depends declaration in system.xml for form element (by @phoenix-bjoern) + * [#5362](https://github.com/magento/magento2/pull/5362) -- Make CMS directive filtering error be more generic (by @erikhansen) + * [#6354](https://github.com/magento/magento2/pull/6354) -- Newsletter Email fix (by @inettman) + * [#6744](https://github.com/magento/magento2/pull/6744) -- add-product-image-label-bug (by @markpol) + * [#6773](https://github.com/magento/magento2/pull/6773) -- Allow to insert Persian characters for attributes! (by @sIiiS) + * [#6779](https://github.com/magento/magento2/pull/6779) -- Changed documentation of the cache variable (by @dverkade) + * [#6775](https://github.com/magento/magento2/pull/6775) -- Changed constructor to use interface instead of direct classname (by @dverkade) + * [#6971](https://github.com/magento/magento2/pull/6971) -- fix #6961 (by @razbakov) + * [#7097](https://github.com/magento/magento2/pull/7097) -- You -> Your (by @avitex) + * [#7414](https://github.com/magento/magento2/pull/7414) -- Fix typo (by @convenient) + * [#8005](https://github.com/magento/magento2/pull/8005) -- Prevent cross origin iframe content reading (by @Igloczek) + * [#8753](https://github.com/magento/magento2/pull/8753) -- Added Translation for required Data-Attribute (by @DavidLambauer) + * [#8778](https://github.com/magento/magento2/pull/8778) -- magento/magento2: #8765 (by @cavalier79) + * [#8914](https://github.com/magento/magento2/pull/8914) -- magento/magetno2#8529:Typo in error message "Table is not exists" (by @bvrbanec) + * [#2448](https://github.com/magento/magento2/pull/2448) -- Fix Inconsistency (by @srenon) + * [#2093](https://github.com/magento/magento2/pull/2093) -- Remove call to load() in getChildrenCategories method (by @davidalger) + * [#4179](https://github.com/magento/magento2/pull/4179) -- fix typo in Magento_Catalog toolbar less source (by @gil--) + * [#5078](https://github.com/magento/magento2/pull/5078) -- Rename $websiteId to $scopeId (by @flancer64) + * [#5207](https://github.com/magento/magento2/pull/5207) -- Table name fix - rule_customer to salesrule_customer (by @Bartlomiejsz) + * [#5858](https://github.com/magento/magento2/pull/5858) -- Save shipping discount in $total (by @flancer64) + * [#6811](https://github.com/magento/magento2/pull/6811) -- Unable to save subscription checkbox on Admin customer save (by @rich1990) + * [#6839](https://github.com/magento/magento2/pull/6839) -- Changed constructor to use an interface (by @dverkade) + * [#6912](https://github.com/magento/magento2/pull/6912) -- Changed module readme text (by @dverkade) + * [#7262](https://github.com/magento/magento2/pull/7262) -- Replace boolean cast to be able to disable frame, aspect ratio, trans… (by @joost-florijn-kega) + * [#7762](https://github.com/magento/magento2/pull/7762) -- change getId() to getPaymentId() (by @HirokazuNishi) + * [#8769](https://github.com/magento/magento2/pull/8769) -- magento/magento2#7860: Invalid comment for the method __order in Mage… (by @mcspronko) + * [#8917](https://github.com/magento/magento2/pull/8917) -- imagento/magento2#8515: Downloadable product is available for downloa… (by @nazarpadalka) + * [#8908](https://github.com/magento/magento2/pull/8908) -- magento/magento2#8871: Typo in Pull Request Template (by @tomislavsantek) + * [#8989](https://github.com/magento/magento2/pull/8989) -- Remove redundant check in if-condition (by @FabianLauer) + * [#8953](https://github.com/magento/magento2/pull/8953) -- Log level for caught exception (by @flancer64) + * [#8994](https://github.com/magento/magento2/pull/8994) -- Syntax fix (by @rafaelstz) + * [#1895](https://github.com/magento/magento2/pull/1895) -- Fix relative template references in individual Magento modules (by @davidalger) + * [#4224](https://github.com/magento/magento2/pull/4224) -- Update get.php (by @thaiphan) + * [#6567](https://github.com/magento/magento2/pull/6567) -- Always skip hidden files (by @quickshiftin) + * [#6989](https://github.com/magento/magento2/pull/6989) -- Allow extending config variables (by @adragus-inviqa) + * [#7218](https://github.com/magento/magento2/pull/7218) -- Set store id on block only when empty (by @dank00) + * [#7161](https://github.com/magento/magento2/pull/7161) -- Fix a bug resulting in incorrect offsets with dynamic row drag-n-drop functionality (by @navarr) + * [#7664](https://github.com/magento/magento2/pull/7664) -- Fix for "Stock Status" field not disappearing in admin when "Manage Stock" = No (by @comdiler) + * [#8812](https://github.com/magento/magento2/pull/8812) -- Fix count SQL on products sold collection (by @jameshalsall) + * [#8991](https://github.com/magento/magento2/pull/8991) -- Update AbstractModel.php (by @redelschaap) + * [#9001](https://github.com/magento/magento2/pull/9001) -- Fix #3791 (by @quienti) + * [#8998](https://github.com/magento/magento2/pull/8998) -- Fixed empty submenu group in backend menu (by @vovayatsyuk) + * [#8928](https://github.com/magento/magento2/pull/8928) -- Stop $this->validColumnNames array from growing and growing (by @jalogut) + * [#4149](https://github.com/magento/magento2/pull/4149) -- Fix wording of downloadable Products (by @bh-ref) + * [#4674](https://github.com/magento/magento2/pull/4674) -- Refactor repeating logic (by @nevvermind) + * [#4501](https://github.com/magento/magento2/pull/4501) -- Add Crowdin badge - official translations (by @piotrekkaminski) + * [#6243](https://github.com/magento/magento2/pull/6243) -- Set getConnection() as public method (by @flancer64) + * [#6250](https://github.com/magento/magento2/pull/6250) -- Return the same data on exit (by @flancer64) + * [#4844](https://github.com/magento/magento2/pull/4844) -- Fix typo (by @orlangur) + * [#4874](https://github.com/magento/magento2/pull/4874) -- Make NL zipcode pattern less strict (by @tdgroot) + * [#5400](https://github.com/magento/magento2/pull/5400) -- Privacy Policy translation (fixes Issue #2951) (by @MindConflicts) + * [#5671](https://github.com/magento/magento2/pull/5671) -- Fix small typo (by @adragus-inviqa) + * [#6132](https://github.com/magento/magento2/pull/6132) -- Remove an extra space while clearing indexed stock items. (by @nntoan) + * [#6840](https://github.com/magento/magento2/pull/6840) -- Removed unused variable $routerId (by @dverkade) + * [#6834](https://github.com/magento/magento2/pull/6834) -- Removed default values for title, meta description, better labels. (by @paales) + * [#7124](https://github.com/magento/magento2/pull/7124) -- Code documentation corrections (by @evktalo) + * [#7294](https://github.com/magento/magento2/pull/7294) -- Let less continue compilation if file is empty (by @timo-schmid) + * [#8648](https://github.com/magento/magento2/pull/8648) -- Remove the copyright year from file headers (by @jameshalsall) + * [#4897](https://github.com/magento/magento2/pull/4897) -- Schedule generation was broken (by @ajpevers) + * [#5503](https://github.com/magento/magento2/pull/5503) -- ACL titles are swapped (by @yireo) + * [#7344](https://github.com/magento/magento2/pull/7344) -- Fix checking active carrier against store (by @torreytsui) + * [#7221](https://github.com/magento/magento2/pull/7221) -- Typo fix (by @gastondisacco) + * [#8982](https://github.com/magento/magento2/pull/8982) -- Move blank theme dependencies out of Magento_Theme requirejs-config (by @mikeoloughlin) + * [#8930](https://github.com/magento/magento2/pull/8930) -- Improved check when CategoryProcessor attempts to create a new category (by @ccasciotti) + * [#8923](https://github.com/magento/magento2/pull/8923) -- Check of null result value in swatch-renderer.js (by @aholovan) + * [#9013](https://github.com/magento/magento2/pull/9013) -- Added JS Jasmine tests to Travis CI (by @Igloczek) + * [#9039](https://github.com/magento/magento2/pull/9039) -- Translation in adminhtml Import form (by @Nolwennig) + * [#9034](https://github.com/magento/magento2/pull/9034) -- Invalidate and refresh customer data sections on HTTP DELETE requests (by @Vinai) + * [#6322](https://github.com/magento/magento2/pull/6322) -- Admin product edit block getHeader is not used (by @kassner) + * [#7045](https://github.com/magento/magento2/pull/7045) -- In case something wrong with underlying products (by @Will-I4M) + * [#8568](https://github.com/magento/magento2/pull/8568) -- Fix quote's outdated shipping address overwriting PayPal Express shipping address (by @torreytsui) + * [#9057](https://github.com/magento/magento2/pull/9057) -- remove duplicate method call (#9017) (by @will-b) + * [#9080](https://github.com/magento/magento2/pull/9080) -- Fix grammar mistakes with subscriptions - fixes #7498 (by @sambolek) + * [#9076](https://github.com/magento/magento2/pull/9076) -- Fix typo (by @PieterCappelle) + * [#9061](https://github.com/magento/magento2/pull/9061) -- Empty resolvedScopeCodes when config cache is cleaned (by @andreas-wickberg-vaimo) + * [#9044](https://github.com/magento/magento2/pull/9044) -- Remove superfluous character in class (by @tkn98) + * [#9095](https://github.com/magento/magento2/pull/9095) -- Added translation to label argument xml. (by @mrkhoa99) + * [#9108](https://github.com/magento/magento2/pull/9108) -- Redundant expression */1 in crontab.xml (by @giacmir) + * [#9170](https://github.com/magento/magento2/pull/9170) -- Corrected class name in documentation. (by @dfelton) + * [#6778](https://github.com/magento/magento2/pull/6778) -- Changed locator class name for ObjectManager (by @dverkade) + * [#7556](https://github.com/magento/magento2/pull/7556) -- Fix merging nested in view.xml (by @torreytsui) + * [#8903](https://github.com/magento/magento2/pull/8903) -- Include Reply-To name in contact form email header (by @josephmcdermott) + * [#9140](https://github.com/magento/magento2/pull/9140) -- remove duplicate calls to initObjectManager in bootstrap class (by @sivajik34) + * [#9133](https://github.com/magento/magento2/pull/9133) -- Favicon folder added on gitignore (by @rafaelstz) + * [#9204](https://github.com/magento/magento2/pull/9204) -- FPT label not translatable in the totals on the cart page. (by @okorshenko) + * [#5043](https://github.com/magento/magento2/pull/5043) -- Change 'select' to 'query' in props (by @flancer64) + * [#5367](https://github.com/magento/magento2/pull/5367) -- Change pub/.htaccess MAGE_MODE comment (by @erikhansen) + * [#5742](https://github.com/magento/magento2/pull/5742) -- Collection walk method bug fix when specific callback function (by @jalogut) + * [#6385](https://github.com/magento/magento2/pull/6385) -- Replace EE License Placeholder text with filename (by @navarr) + * [#6443](https://github.com/magento/magento2/pull/6443) -- Refactor Option ResourceModel to allow price supporting types to be intercepted (by @navarr) + * [#6772](https://github.com/magento/magento2/pull/6772) -- Changed constructor to use an interface (by @dverkade) + * [#6910](https://github.com/magento/magento2/pull/6910) -- Good practice, license in readme file (by @rafaelstz) + * [#7506](https://github.com/magento/magento2/pull/7506) -- Add configurations for change email templates (by @kassner) + * [#7464](https://github.com/magento/magento2/pull/7464) -- Is Allowed Guest Checkout (by @hungvt) + * [#7900](https://github.com/magento/magento2/pull/7900) -- Setting proper resource name (by @ddattee) + * [#8462](https://github.com/magento/magento2/pull/8462) -- Fix product option files not copying to order dir. (by @evktalo) + * [#8824](https://github.com/magento/magento2/pull/8824) -- Popup-Modal not closing on Safari/Windows (by @Hansschouten) + * [#9062](https://github.com/magento/magento2/pull/9062) -- Upgrade JS dependencies (by @Igloczek) + * [#9084](https://github.com/magento/magento2/pull/9084) -- Fix Google Analytics typo in printing Account Number, fixes #7549 (by @sambolek) + * [#9112](https://github.com/magento/magento2/pull/9112) -- Fix attribute label on product page at different store views (by @tufahu) + * [#9103](https://github.com/magento/magento2/pull/9103) -- Cli info di (by @springerin) + * [#9165](https://github.com/magento/magento2/pull/9165) -- Improved text of exception message in case of error in module's composer.json (by @vovayatsyuk) + * [#9131](https://github.com/magento/magento2/pull/9131) -- Fix to allow Zend_Db_Expr as column default (by @scottsb) + * [#9221](https://github.com/magento/magento2/pull/9221) -- Avoid: Undefined index: value in app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php on line 157 in Ajax return (by @mhauri) + * [#9215](https://github.com/magento/magento2/pull/9215) -- Remove unused and invalid method (by @adragus-inviqa) + * [#9210](https://github.com/magento/magento2/pull/9210) -- Do not di:compile tests/ folder (by @kassner) + * [#5325](https://github.com/magento/magento2/pull/5325) -- update url guide to v2.0 (by @sIiiS) + * [#6452](https://github.com/magento/magento2/pull/6452) -- Fix Login Popup broken on iPad portrait (by @ihor-sviziev) + * [#9234](https://github.com/magento/magento2/pull/9234) -- Fix indentation in pub/.htaccess file (by @erikhansen) + * [#6266](https://github.com/magento/magento2/pull/6266) -- Change commit to rollBack on fail (by @flancer64) + * [#6792](https://github.com/magento/magento2/pull/6792) -- Make a hardcoded value in Customizable Options interceptable (by @navarr) + * [#9094](https://github.com/magento/magento2/pull/9094) -- Issue #2802, #1146: Fixing sitemap generation folder (by @JosephMaxwell) + * [#9124](https://github.com/magento/magento2/pull/9124) -- Solve issues with API (by @paales) + * [#9247](https://github.com/magento/magento2/pull/9247) -- Fixed layout handle for cms page (by @simpleadm) + * [#9257](https://github.com/magento/magento2/pull/9257) -- Fixed coding standard violations in the Framework\Message namespace (by @dverkade) + * [#9254](https://github.com/magento/magento2/pull/9254) -- Fixed coding standard violations in the Framework\Encryption namespace (by @dverkade) + * [#9253](https://github.com/magento/magento2/pull/9253) -- Fixed coding standard violations in the Framework\Event namespace (by @dverkade) + * [#9250](https://github.com/magento/magento2/pull/9250) -- Fixed coding standard violations in the Framework\Archive namespace (by @dverkade) + * [#9264](https://github.com/magento/magento2/pull/9264) -- Enable/Disable DB query logging commands (by @federivo) + * [#9260](https://github.com/magento/magento2/pull/9260) -- Fixed coding standard violations in Framework\HTTP namespace: (by @dverkade) + * [#9258](https://github.com/magento/magento2/pull/9258) -- Fixed coding standard violations in the Framework\Filesystem namespace (by @dverkade) + * [#9286](https://github.com/magento/magento2/pull/9286) -- [WIP] Varnish Vcl generator command (by @piotrkwiecinski) + * [#9282](https://github.com/magento/magento2/pull/9282) -- Fixed coding standard violations in the Framework\Filter namespace (by @dverkade) + * [#9281](https://github.com/magento/magento2/pull/9281) -- Fixed coding standard violations in Framework\Image namespace (by @dverkade) + * [#9298](https://github.com/magento/magento2/pull/9298) -- Remove php-5.6 environment from travis.yml (by @4quaternion) + * [#4816](https://github.com/magento/magento2/pull/4816) -- Fixed issue with grouped product name column renderer. It (by @wbyrnetx) + * [#5147](https://github.com/magento/magento2/pull/5147) -- Change value-assignment to a setValue call (by @wexo-team) + * [#5411](https://github.com/magento/magento2/pull/5411) -- #5236 fixes "The configuration parameter "componentType" is a required for "advanced_pricing_button" component" (by @Protazy21) + * [#7148](https://github.com/magento/magento2/pull/7148) -- Fix issue 7075 (by @rmsundar1) + * [#9027](https://github.com/magento/magento2/pull/9027) -- Make CSS minifying compatible with calc() CSS function (by @sambolek) + * [#9262](https://github.com/magento/magento2/pull/9262) -- Remove zend json from theme (by @dmanners) + * [#9261](https://github.com/magento/magento2/pull/9261) -- Remove zend json from weee (by @dmanners) + * [#9302](https://github.com/magento/magento2/pull/9302) -- Fixed coding standard violations in the Framework\Module namespace (by @dverkade) + * [#9299](https://github.com/magento/magento2/pull/9299) -- Improved check for attribute codes in "additional_attributes" field (by @ccasciotti) + * [#9293](https://github.com/magento/magento2/pull/9293) -- Deprecate unused navigation-menu.js file in blank theme (by @mikeoloughlin) + * [#9308](https://github.com/magento/magento2/pull/9308) -- Remove unnecessary FQCN in ObserverInterface (by @jameshalsall) + * [#9304](https://github.com/magento/magento2/pull/9304) -- Fixed coding standard violations in all Factory classes located in app/code (by @dverkade) + * [#9303](https://github.com/magento/magento2/pull/9303) -- Fixed coding standard violations in the Framework namespace (by @dverkade) + * [#9318](https://github.com/magento/magento2/pull/9318) -- Fixed coding standard violations in the Framework\Backup namespace (by @dverkade) + * [#9321](https://github.com/magento/magento2/pull/9321) -- Fixed coding standard violations in the Framework\Autoload, Framework\Session & Framework\Webapi namespaces (by @dverkade) + * [#9320](https://github.com/magento/magento2/pull/9320) -- Fixed coding standard violations in the Framework\Cache namespace (by @dverkade) + * [#9319](https://github.com/magento/magento2/pull/9319) -- Fixed coding standard violations in the Framework\Api namespace (by @dverkade) + * [#9334](https://github.com/magento/magento2/pull/9334) -- Fixed coding standard violations in the Framework\Controller, Framework\CSS, Framework\Phrase and Framework\Pricing namespace (by @dverkade) + * [#9330](https://github.com/magento/magento2/pull/9330) -- Fixed coding standard violations in the Framework\Data namespace (by @dverkade) + * [#9329](https://github.com/magento/magento2/pull/9329) -- Fixed coding standard violations in the Framework\Stdlib namespace (by @dverkade) + * [#9328](https://github.com/magento/magento2/pull/9328) -- Fixed coding standard violations in the Framework\Config namespace (by @dverkade) + * [#5372](https://github.com/magento/magento2/pull/5372) -- Fix filesystem permission issues (by @BlackIkeEagle) + * [#9129](https://github.com/magento/magento2/pull/9129) -- Product Wizard: Use result type Layout instead of page layout (by @klein0r) + * [#9352](https://github.com/magento/magento2/pull/9352) -- Fixed coding standard violations in the Framework\File namespace (by @dverkade) + * [#9351](https://github.com/magento/magento2/pull/9351) -- Fixed coding standard violations in the Framework\Locale namespace (by @dverkade) + * [#9350](https://github.com/magento/magento2/pull/9350) -- Fixed coding standard violations in the Framework\App namespace (by @dverkade) + * [#9355](https://github.com/magento/magento2/pull/9355) -- Fixed coding standard violations in the Framework\Test namespace (by @dverkade) + * [#9354](https://github.com/magento/magento2/pull/9354) -- Fixed coding standard violations in the Framework\Translate namespace (by @dverkade) + * [#9353](https://github.com/magento/magento2/pull/9353) -- Fixed coding standard violations in the Framework\DB namespace (by @dverkade) + * [#8955](https://github.com/magento/magento2/pull/8955) -- Remove context aggregation validation (see Issue #6114) (by @Vinai) + * [#9343](https://github.com/magento/magento2/pull/9343) -- Add logging to contact us form (by @JamesonNetworks) + * [#9414](https://github.com/magento/magento2/pull/9414) -- Use loadPlayer requirejs mapping (by @ntoombs19) + * [#9400](https://github.com/magento/magento2/pull/9400) -- Fix addIdFilter method (by @adrian-martinez-interactiv4) + * [#9363](https://github.com/magento/magento2/pull/9363) -- Add ability to inject exception code in LocalizedException (by @adragus-inviqa) + * [#9446](https://github.com/magento/magento2/pull/9446) -- Fix data deletion using the multiple delete command (by @Kenboy) + * [#9539](https://github.com/magento/magento2/pull/9539) -- fix for "Class Magento\Framework\Console\CLI not found" in case sensitive scenarios (by @EObukhovsky) + * [#9514](https://github.com/magento/magento2/pull/9514) -- Fix breadcrumbs extra space (by @VincentMarmiesse) + * [#8409](https://github.com/magento/magento2/pull/8409) -- Allow X-Forwarded-For to have multiple values (by @kassner) + * [#9093](https://github.com/magento/magento2/pull/9093) -- JS Static tests added to CI (ESLint + JSCS) (by @Igloczek) + * [#9091](https://github.com/magento/magento2/pull/9091) -- ESLint errors fix (by @Igloczek) + * [#9285](https://github.com/magento/magento2/pull/9285) -- Replace Zend_Log with Psr\Log\LoggerInterface (by @tdgroot) + * [#9380](https://github.com/magento/magento2/pull/9380) -- Removed unnecessary code and namespaces from import validators (by @ccasciotti) + * [#9540](https://github.com/magento/magento2/pull/9540) -- Removed workaround for old Webkit bug in the TinyMCE editor for selec… (by @hostep) + * [#9549](https://github.com/magento/magento2/pull/9549) -- Selects correct stores value option (by @Corefix) + * [#9574](https://github.com/magento/magento2/pull/9574) -- no need to create customer once u got the quote object (by @sivajik34) + * [#9618](https://github.com/magento/magento2/pull/9618) -- Flip the property assignments for _logger and _fetchStrategy in __wakeup (by @cykirsch) + * [#9617](https://github.com/magento/magento2/pull/9617) -- Exclude unnecessarily duplicated Travis CI build jobs (by @Igloczek) + * [#9622](https://github.com/magento/magento2/pull/9622) -- Zend_Wildfire deprecated, Firephp outdated, magento/magento2#9239 and magento/magento2#9241 (by @SolsWebdesign) + * [#9625](https://github.com/magento/magento2/pull/9625) -- Remove unused plugin (by @elzekool) + * [#9637](https://github.com/magento/magento2/pull/9637) -- Change "wan't" to "want" (by @Leland) + * [#7020](https://github.com/magento/magento2/pull/7020) -- Fixes #7006, sales_order_status_label does not support version control (by @ajpevers) + * [#7456](https://github.com/magento/magento2/pull/7456) -- Remove unused entity_id foreign key (by @mattjbarlow) + * [#7755](https://github.com/magento/magento2/pull/7755) -- Remove redundant check and return early (by @AydinHassan) + * [#9657](https://github.com/magento/magento2/pull/9657) -- Fixes Typo (by @riconeitzel) + * [#4903](https://github.com/magento/magento2/pull/4903) -- Fix undefined offset notice when no order states are set (by @adragus-inviqa) + * [#6344](https://github.com/magento/magento2/pull/6344) -- Zend instead of regex in getGetterReturnType (by @flancer64) + * [#9686](https://github.com/magento/magento2/pull/9686) -- Update scripts.js (by @redelschaap) + * [#9701](https://github.com/magento/magento2/pull/9701) -- Add missing payment info template for PDF generation (by @cmuench) + * [#9697](https://github.com/magento/magento2/pull/9697) -- Configure Travis CI to run functional tests (by @okolesnyk) + * [#9711](https://github.com/magento/magento2/pull/9711) -- Cookie Restriction Mode Overlay should not be cached by Varnish #6455 (by @bka) + * [#9713](https://github.com/magento/magento2/pull/9713) -- stringify cookie value to fix Google Analyitcs Tracking and Cookie Overlay #5596 (by @bka) + * [#6503](https://github.com/magento/magento2/pull/6503) -- Remove breadcrumbs for multistore homepage (by @PingusPepan) + * [#7330](https://github.com/magento/magento2/pull/7330) -- Fix Framework\Data\Collection::each() method (by @Vinai) + * [#8484](https://github.com/magento/magento2/pull/8484) -- Fix swatch-renderer.js product id and isProductViewExist (by @mimarcel) + * [#9348](https://github.com/magento/magento2/pull/9348) -- Replace framework's Zend_Session interface usage with SessionHandlerInterface (by @tdgroot) + * [#9654](https://github.com/magento/magento2/pull/9654) -- magento/magento2#7279 bill-to name and ship-to name truncated to 20 chars (by @SolsWebdesign) + * [#9627](https://github.com/magento/magento2/pull/9627) -- Fix coding standard in Magento AdminNotification module (by @dverkade) + * [#9714](https://github.com/magento/magento2/pull/9714) -- Can't delete last item in cart if Minimum Order is Enable #6151 (by @storbahn) + * [#9717](https://github.com/magento/magento2/pull/9717) -- use payment method name to make checkbox of agreements more unique #6207 (by @bka) + * [#9715](https://github.com/magento/magento2/pull/9715) -- #4272: v2.0.4 Credit memos with adjustment fees cannot be fully refunded with a second credit memo (by @mcspronko) + * [#9344](https://github.com/magento/magento2/pull/9344) -- Explace the direct usage of Zend_Json with a call to the Json Help class (by @dmanners) + * [#9475](https://github.com/magento/magento2/pull/9475) -- Update select.js (by @redelschaap) + * [#9600](https://github.com/magento/magento2/pull/9600) -- Do not hardcode product link types (by @kassner) + * [#9712](https://github.com/magento/magento2/pull/9712) -- Customer with unique attribute can't be saved #7844 (by @storbahn) + * [#9723](https://github.com/magento/magento2/pull/9723) -- Patch to allow multiple filter_url_params to function (by @southerncomputer) + * [#9721](https://github.com/magento/magento2/pull/9721) -- [BUGFIX][6244] Fix Issue with code label display in cart checkout. (by @diglin) + * [#9753](https://github.com/magento/magento2/pull/9753) -- Replace Zend_Json in the configurable product block test (by @dmanners) + * [#9777](https://github.com/magento/magento2/pull/9777) -- Fix for #5897: getIdentities relies on uninitialized collection (by @kassner) + * [#9772](https://github.com/magento/magento2/pull/9772) -- Allow for referenceBlock to include template argument (by @jissereitsma) + * [#9797](https://github.com/magento/magento2/pull/9797) -- Adding logo in media folder (by @rafaelstz) + * [#9409](https://github.com/magento/magento2/pull/9409) -- Add a name to the Composite\Fieldset\Options block directive (by @navarr) + * [#9665](https://github.com/magento/magento2/pull/9665) -- Fix for javascript "mixins" when 'urlArgs' is set in requirejs - issue 8221 (by @thelettuce) + * [#9835](https://github.com/magento/magento2/pull/9835) -- Fixes Mage.Cookies poor performance (by @wujashek) + * [#9430](https://github.com/magento/magento2/pull/9430) -- Fix wrong store id filter (by @mimarcel) + * [#9670](https://github.com/magento/magento2/pull/9670) -- Allow injection of Magento\Catalog\Model\View\Asset\ImageFactory (by @rolftimmermans) + * [#9778](https://github.com/magento/magento2/pull/9778) -- new CLI command: Enable Template Hints (by @miguelbalparda) + * [#9820](https://github.com/magento/magento2/pull/9820) -- [oauth] Fixes #9819 (by @EliasKotlyar) + * [#9859](https://github.com/magento/magento2/pull/9859) -- Removed unused $_customerSession property (by @edenreich) + * [#4450](https://github.com/magento/magento2/pull/4450) -- Add ability to use tree-massactions ("sub-menus") on Sales > Orders grid (by @ikk0) + * [#9368](https://github.com/magento/magento2/pull/9368) -- Redis sess: fix path for persistent_identifier & compression_threshold (by @LukeHandle) + * [#9690](https://github.com/magento/magento2/pull/9690) -- Add froogaloop library as a dependency to load-player module (by @ntoombs19) + * [#9813](https://github.com/magento/magento2/pull/9813) -- Use static:: to support late static bindings in Invoice and Creditmemo (by @jokeputs) + * [#9780](https://github.com/magento/magento2/pull/9780) -- Coupon codes not showing in invoice print out #9216 (by @naouibelgacem) + * [#9872](https://github.com/magento/magento2/pull/9872) -- Fixed issue causing static test failure to report success on Travis (by @davidalger) + * [#9890](https://github.com/magento/magento2/pull/9890) -- Improved error logging when trying to save a product (by @woutersamaey) + * [#9892](https://github.com/magento/magento2/pull/9892) -- Added .DS_Store to .gitignore for Mac users (by @woutersamaey) + * [#9873](https://github.com/magento/magento2/pull/9873) -- Fixes layered navigation options being cached using the wrong store id. (by @hostep) + * [#7405](https://github.com/magento/magento2/pull/7405) -- Update Curl.php (by @redelschaap) + * [#7780](https://github.com/magento/magento2/pull/7780) -- setup:di:compile returns exit code 0 if errors are found (by @pivulic) + * [#9157](https://github.com/magento/magento2/pull/9157) -- Return array of blocks as items instead of array of arrays (by @tkotosz) + * [#9810](https://github.com/magento/magento2/pull/9810) -- Fix bug linked product position not updated if product link already exists (by @jalogut) + * [#9824](https://github.com/magento/magento2/pull/9824) -- Email to a Friend feature (by @WaPoNe) + * [#9823](https://github.com/magento/magento2/pull/9823) -- Return array of pages as items instead of array of arrays (by @tkotosz) + * [#9922](https://github.com/magento/magento2/pull/9922) -- Fixes small backwards incompatibility issue created in MAGETWO-69728 (by @hostep) + * [#4891](https://github.com/magento/magento2/pull/4891) -- Remove faulty index subscription (by @ajpevers) + * [#7758](https://github.com/magento/magento2/pull/7758) -- Throw exception when attribute doesn't exitst (by @AydinHassan) + * [#8879](https://github.com/magento/magento2/pull/8879) -- add middle name to checkout address html templates #8878 (by @ajpevers) + * [#9251](https://github.com/magento/magento2/pull/9251) -- Fixed coding standard violations in the Framework\Validator namespace (by @dverkade) + * [#9525](https://github.com/magento/magento2/pull/9525) -- Fixed the Inconsistent Gift Options checkbox labels #9421 (by @vpiyappan) + * [#9905](https://github.com/magento/magento2/pull/9905) -- Fix composer validation (by @barbazul) + * [#9932](https://github.com/magento/magento2/pull/9932) -- Fix typo in comment (by @avoelkl) + * [#9306](https://github.com/magento/magento2/pull/9306) -- Fix PaymentTokenFactory interface to have the "Interface" at the end of the name. (by @dverkade) + * [#9391](https://github.com/magento/magento2/pull/9391) -- Fix depends per group in system.xml (by @osrecio) + * [#9902](https://github.com/magento/magento2/pull/9902) -- Fix static integrity classes tests in Windows (by @barbazul) + * [#9915](https://github.com/magento/magento2/pull/9915) -- suggestion from #9338: add some command/option to the deploy command to refresh the version (by @ajpevers) + * [#9925](https://github.com/magento/magento2/pull/9925) -- Fix #9924, prefill prefix and suffix in checkout shipping address (by @ajpevers) + * [#9941](https://github.com/magento/magento2/pull/9941) -- By default, show times in admin grids in the store timezone. (by @ajpevers) + * [#9943](https://github.com/magento/magento2/pull/9943) -- Cron uses the wrong timestamp method (by @ajpevers) + * [#9964](https://github.com/magento/magento2/pull/9964) -- Add target attribute to Magento_Ui grid (by @thelettuce) + * [#9973](https://github.com/magento/magento2/pull/9973) -- Fixed coding standard violations in the Magento\Wishlist namespace (by @dverkade) + * [#9974](https://github.com/magento/magento2/pull/9974) -- Fixed coding standard violations in the Magento\Backend namespace (by @dverkade) + * [#9975](https://github.com/magento/magento2/pull/9975) -- Fixed coding standard violations in the Magento\Cms namespace (by @dverkade) + * [#9978](https://github.com/magento/magento2/pull/9978) -- Fixed coding standard violations in the Magento\Authorization Magento\Backup Magento\Captcha Magento\CurrencySymbol and Magento\Dhl namespace (by @dverkade) + * [#8965](https://github.com/magento/magento2/pull/8965) -- Reduce calls to SplFileInfo::realpath() in the Magento\Setup\Module\Di\Code\Reader\ClassesScanner class (by @kschroeder) + * [#9996](https://github.com/magento/magento2/pull/9996) -- Ubuntu Trusty 14.04 images update (by @miguelbalparda) + * [#8784](https://github.com/magento/magento2/pull/8784) -- magento/magento2: #8616 (by @cavalier79) + * [#9939](https://github.com/magento/magento2/pull/9939) -- Retrieve taxes from the correct object (by @fooman) + * [#9957](https://github.com/magento/magento2/pull/9957) -- Instantly apply configuration changes in the cron schedule (by @ajpevers) + * [#9994](https://github.com/magento/magento2/pull/9994) -- Fix mini-cart not emptied for logged out users checking out with PayPal Express (by @driskell) + * [#9082](https://github.com/magento/magento2/pull/9082) -- Get sitemap product images from image cache, if available (by @sambolek) + * [#9786](https://github.com/magento/magento2/pull/9786) -- [#7291] Change the default contact form email template to HTML (by @VincentMarmiesse) + * [#9361](https://github.com/magento/magento2/pull/9361) -- Fixed coding standard violations in the Framework\Model namespace (by @dverkade) + * [#9359](https://github.com/magento/magento2/pull/9359) -- Fixed coding standard violations in the Framework\Interception namespace (by @dverkade) + * [#9358](https://github.com/magento/magento2/pull/9358) -- Fixed coding standard violations in the Framework\Code namespace (by @dverkade) + * [#9429](https://github.com/magento/magento2/pull/9429) -- Fix not detecting current store using store code in url using $storeResolver->getCurrentStoreId() (by @mimarcel) + * [#9362](https://github.com/magento/magento2/pull/9362) -- Fixed coding standard violations in the Framework\ObjectManager namespace (by @dverkade) + * [#9970](https://github.com/magento/magento2/pull/9970) -- Added public methods to make Sitemap model plugin friendly (by @7ochem) + * [#7729](https://github.com/magento/magento2/pull/7729) -- Allow USPS Shipping Methods Without ExtraServices (by @jaywilliams) + * [#9314](https://github.com/magento/magento2/pull/9314) -- Support null value for custom attributes. (by @meng-tian) + * [#10033](https://github.com/magento/magento2/pull/10033) -- Fix for file category image uploader (by @Bartlomiejsz) + * [#10047](https://github.com/magento/magento2/pull/10047) -- Include attribute code in error message (by @lazyguru) + * [#10056](https://github.com/magento/magento2/pull/10056) -- Translate password field placeholder in Checkout (by @mimarcel) + * [#7139](https://github.com/magento/magento2/pull/7139) -- Stickyjs improvements (by @vovayatsyuk) + * [#9681](https://github.com/magento/magento2/pull/9681) -- Issue 9680: Use parent name for variations (by @PascalBrouwers) + * [#10031](https://github.com/magento/magento2/pull/10031) -- Allow option disabling for optgroup binding (by @Bart-art) + * [#10060](https://github.com/magento/magento2/pull/10060) -- Adding escapeHtml to Newsletter phtml (by @rafaelstz) + * [#10062](https://github.com/magento/magento2/pull/10062) -- Fix formatting for USPS Carrier (by @ihor-sviziev) + * [#9672](https://github.com/magento/magento2/pull/9672) -- Revert minimum stability to stable, tasks #4359 (by @ktomk) + * [#9986](https://github.com/magento/magento2/pull/9986) -- Improved type hints and declarations for \Magento\Quote\Model\Quote\Address\Total (by @schmengler) + * [#10082](https://github.com/magento/magento2/pull/10082) -- M2 2266 (by @tzyganu) + * [#10086](https://github.com/magento/magento2/pull/10086) -- Fix condition for autoloader function definitions (by @miromichalicka) + * [#9611](https://github.com/magento/magento2/pull/9611) -- Admin Grid Mass action Select / Unselect All issue #9610 (by @minesh0111) + * [#9726](https://github.com/magento/magento2/pull/9726) -- Remove wrong '_setup' replace when getting DB connection (2) (by @jalogut) + * [#9754](https://github.com/magento/magento2/pull/9754) -- Remove zend json from form elements (by @dmanners) + * [#9992](https://github.com/magento/magento2/pull/9992) -- Make page title in layout files translatable (by @ajpevers) + * [#10052](https://github.com/magento/magento2/pull/10052) -- M2 5381 (by @tzyganu) + * [#1563](https://github.com/magento/magento2/pull/1563) -- Convert long form tags with echo to use short-echo tags (by @davidalger) + * [#4147](https://github.com/magento/magento2/pull/4147) -- Add filename paramenter log (by @fcapua-summa) + * [#10043](https://github.com/magento/magento2/pull/10043) -- Fix trailing slash used in url rewrites (by @ihor-sviziev) + * [#10106](https://github.com/magento/magento2/pull/10106) -- Return URL in getThumbnailUrl instead of nothing (by @samgranger) + * [#3889](https://github.com/magento/magento2/pull/3889) -- Add missing dependencies of magento/framework (by @GordonLesti) + * [#10114](https://github.com/magento/magento2/pull/10114) -- Add missing dependencies of magento/framework (by @okorshenko) + * [#7174](https://github.com/magento/magento2/pull/7174) -- Type hint for \DateTimeInterface instead of \DateTime (by @jameshalsall) + * [#9189](https://github.com/magento/magento2/pull/9189) -- Avoid duplicate ltrim function on not complied mode. (by @sivajik34) + * [#10094](https://github.com/magento/magento2/pull/10094) -- Fix for isoneof condition in catalogrule (by @duckchip) + * [#10105](https://github.com/magento/magento2/pull/10105) -- Add referrerPolicy to Vimeo Video iframe to allow domain-restricted videos (by @davefarthing) + * [#10126](https://github.com/magento/magento2/pull/10126) -- Fix width & height mapping during image upload (by @ihor-sviziev) + * [#10140](https://github.com/magento/magento2/pull/10140) -- Update attribute vat_id frontend_label to make it translatable (by @JeroenVanLeusden) + * [#10149](https://github.com/magento/magento2/pull/10149) -- Fix wrong ACL for Developer Section (by @PascalBrouwers) + * [#10151](https://github.com/magento/magento2/pull/10151) -- Fix Widget saving non-XML entities to layout_update (by @tdgroot) + * [#9588](https://github.com/magento/magento2/pull/9588) -- Support controller src_type for head links (by @kassner) + * [#9904](https://github.com/magento/magento2/pull/9904) -- Fixed pointless exception in logs every time a category with image is saved (by @woutersamaey) + * [#10059](https://github.com/magento/magento2/pull/10059) -- Fix fetching quote item by id (by @mladenilic) + 2.1.0 ============= To get detailed information about changes in Magento 2.1.0, please visit [Magento Community Edition (CE) Release Notes](http://devdocs.magento.com/guides/v2.1/release-notes/ReleaseNotes2.1.0CE.html "Magento Community Edition (CE) Release Notes") diff --git a/COPYING.txt b/COPYING.txt index d2cbcd01539dd..040bdd5f3ce72 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -1,4 +1,4 @@ -Copyright © 2013-2017 Magento, Inc. +Copyright © 2013-present Magento, Inc. Each Magento source file included in this distribution is licensed under OSL 3.0 or the Magento Enterprise Edition (MEE) license diff --git a/README.md b/README.md index 9b1aa1b7b3e28..87c98d4bcb437 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@ -[![Build Status](https://travis-ci.org/magento/magento2.svg?branch=develop)](https://travis-ci.org/magento/magento2) +[![Build Status](https://travis-ci.org/magento/magento2.svg?branch=2.2-develop)](https://travis-ci.org/magento/magento2) +[![Open Source Helpers](https://www.codetriage.com/magento/magento2/badges/users.svg)](https://www.codetriage.com/magento/magento2) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/magento/magento2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Crowdin](https://d322cqt584bo4o.cloudfront.net/magento-2/localized.png)](https://crowdin.com/project/magento-2)

Welcome

Welcome to Magento 2 installation! We're glad you chose to install Magento 2, a cutting edge, feature-rich eCommerce solution that gets results. ## Magento system requirements -[Magento system requirements](http://devdocs.magento.com/magento-system-requirements.html) +[Magento system requirements](http://devdocs.magento.com/guides/v2.2/install-gde/system-requirements2.html) ## Install Magento To install Magento, see either: * [Magento DevBox](https://magento.com/tech-resources/download), the easiest way to get started with Magento. -* [Installation guide](http://devdocs.magento.com/guides/v2.0/install-gde/bk-install-guide.html) +* [Installation guide](http://devdocs.magento.com/guides/v2.2/install-gde/bk-install-guide.html)

Contributing to the Magento 2 code base

Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes, optimizations, or just good suggestions. @@ -22,8 +23,8 @@ To learn about issues, click [here][2]. To open an issue, click [here][3]. To suggest documentation improvements, click [here][4]. -[1]: -[2]: +[1]: +[2]: [3]: [4]: @@ -38,8 +39,10 @@ To suggest documentation improvements, click [here][4]. | ![reject](http://devdocs.magento.com/common/images/github_reject.png) | The pull request has been rejected and will not be merged into mainline code. Possible reasons can include but are not limited to: issue has already been fixed in another code contribution, or there is an issue with the code contribution. | | ![bug report](http://devdocs.magento.com/common/images/github_bug.png) | The Magento Team has confirmed that this issue contains the minimum required information to reproduce. | | ![acknowledged](http://devdocs.magento.com/common/images/gitHub_acknowledged.png) | The Magento Team has validated the issue and an internal ticket has been created. | -| ![acknowledged](http://devdocs.magento.com/common/images/github_inProgress.png) | The internal ticket is currently in progress, fix is scheduled to be delivered. | -| ![acknowledged](http://devdocs.magento.com/common/images/github_needsUpdate.png) | The Magento Team needs additional information from the reporter to properly prioritize and process the issue or pull request. | +| ![in progress](http://devdocs.magento.com/common/images/github_inProgress.png) | The internal ticket is currently in progress, fix is scheduled to be delivered. | +| ![needs update](http://devdocs.magento.com/common/images/github_needsUpdate.png) | The Magento Team needs additional information from the reporter to properly prioritize and process the issue or pull request. | + +To learn more about issue gate labels click [here](https://github.com/magento/magento2/wiki/Magento-Issue-Gates)

Reporting security issues

diff --git a/app/.htaccess b/app/.htaccess index 93169e4eb44ff..707c26b075e16 100644 --- a/app/.htaccess +++ b/app/.htaccess @@ -1,2 +1,8 @@ -Order deny,allow -Deny from all + + order allow,deny + deny from all + += 2.4> + Require all denied + + diff --git a/app/bootstrap.php b/app/bootstrap.php index 6701a9f4dd51e..e77c6d432c816 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -14,12 +14,12 @@ if (!defined('PHP_VERSION_ID') || !(PHP_VERSION_ID === 70002 || PHP_VERSION_ID === 70004 || PHP_VERSION_ID >= 70006)) { if (PHP_SAPI == 'cli') { echo 'Magento supports 7.0.2, 7.0.4, and 7.0.6 or later. ' . - 'Please read http://devdocs.magento.com/guides/v1.0/install-gde/system-requirements.html'; + 'Please read http://devdocs.magento.com/guides/v2.2/install-gde/system-requirements.html'; } else { echo <<

Magento supports PHP 7.0.2, 7.0.4, and 7.0.6 or later. Please read - + Magento System Requirements. HTML; @@ -49,12 +49,17 @@ unset($_SERVER['ORIG_PATH_INFO']); } -if (!empty($_SERVER['MAGE_PROFILER']) +if ( + (!empty($_SERVER['MAGE_PROFILER']) || file_exists(BP . '/var/profiler.flag')) && isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false ) { + $profilerFlag = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER']) + ? $_SERVER['MAGE_PROFILER'] + : trim(file_get_contents(BP . '/var/profiler.flag')); + \Magento\Framework\Profiler::applyConfig( - $_SERVER['MAGE_PROFILER'], + $profilerFlag, BP, !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ); diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php index 6c0dfd1db7d16..94c7d955f592b 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/MassRemove.php @@ -39,6 +39,6 @@ public function execute() $this->messageManager->addException($e, __("We couldn't remove the messages because of an error.")); } } - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); + $this->_redirect('adminhtml/*/'); } } diff --git a/app/code/Magento/AdminNotification/composer.json b/app/code/Magento/AdminNotification/composer.json index afb820a2e6c93..59a3845cbd4b7 100644 --- a/app/code/Magento/AdminNotification/composer.json +++ b/app/code/Magento/AdminNotification/composer.json @@ -6,12 +6,12 @@ "magento/module-store": "100.2.*", "magento/module-backend": "100.2.*", "magento/module-media-storage": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-ui": "100.2.*", + "magento/framework": "101.0.*", + "magento/module-ui": "101.0.*", "lib-libxml": "*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/AdminNotification/view/adminhtml/layout/adminhtml_notification_block.xml b/app/code/Magento/AdminNotification/view/adminhtml/layout/adminhtml_notification_block.xml index 7778c1dd5ca98..c68313211c2e6 100644 --- a/app/code/Magento/AdminNotification/view/adminhtml/layout/adminhtml_notification_block.xml +++ b/app/code/Magento/AdminNotification/view/adminhtml/layout/adminhtml_notification_block.xml @@ -20,14 +20,14 @@ 0 - + Severity severity Magento\AdminNotification\Block\Grid\Renderer\Severity - + Date Added date_added @@ -37,14 +37,14 @@ col-date - + Message title Magento\AdminNotification\Block\Grid\Renderer\Notice - + Actions 0 diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php b/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php index 7ddd5e3bb2a36..62a7aefa77550 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php @@ -79,6 +79,11 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product ImportAdvancedPricing::COL_TIER_PRICE_TYPE => '' ]; + /** + * @var string[] + */ + private $websiteCodesMap = []; + /** * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Eav\Model\Config $config @@ -213,6 +218,7 @@ public function export() break; } } + return $writer->getContents(); } @@ -255,70 +261,111 @@ public function filterAttributeCollection(\Magento\Eav\Model\ResourceModel\Entit */ protected function getExportData() { + if ($this->_passTierPrice) { + return []; + } + $exportData = []; try { - $rawData = $this->collectRawData(); - $productIds = array_keys($rawData); - if (isset($productIds)) { - if (!$this->_passTierPrice) { - $exportData = array_merge( - $exportData, - $this->getTierPrices($productIds, ImportAdvancedPricing::TABLE_TIER_PRICE) - ); + $productsByStores = $this->loadCollection(); + if (!empty($productsByStores)) { + $productLinkIds = array_map( + function (array $productData) { + return $productData[Store::DEFAULT_STORE_ID][$this->getProductEntityLinkField()]; + }, + $productsByStores + ); + $tierPricesData = $this->getTierPrices( + $productLinkIds, + ImportAdvancedPricing::TABLE_TIER_PRICE + ); + + $exportData = $this->correctExportData( + $productsByStores, + $tierPricesData + ); + if (!empty($exportData)) { + asort($exportData); } } - if ($exportData) { - $exportData = $this->correctExportData($exportData); - } - if (isset($exportData)) { - asort($exportData); - } } catch (\Exception $e) { $this->_logger->critical($e); } + return $exportData; } /** - * Correct export data. + * @param array $tierPriceData Tier price information. * - * @param array $exportData - * @return array - * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @return array Formatted for export tier price information. */ - protected function correctExportData($exportData) + private function createExportRow(array $tierPriceData): array { - $customExportData = []; - foreach ($exportData as $key => $row) { - $exportRow = $this->templateExportData; - foreach ($exportRow as $keyTemplate => $valueTemplate) { - if (isset($row[$keyTemplate])) { - if (in_array($keyTemplate, $this->_priceWebsite)) { - $exportRow[$keyTemplate] = $this->_getWebsiteCode( - $row[$keyTemplate] - ); - } elseif (in_array($keyTemplate, $this->_priceCustomerGroup)) { - $exportRow[$keyTemplate] = $this->_getCustomerGroupById( - $row[$keyTemplate], - isset($row[ImportAdvancedPricing::VALUE_ALL_GROUPS]) - ? $row[ImportAdvancedPricing::VALUE_ALL_GROUPS] - : null - ); - unset($exportRow[ImportAdvancedPricing::VALUE_ALL_GROUPS]); - } elseif ($keyTemplate === ImportAdvancedPricing::COL_TIER_PRICE) { - $exportRow[$keyTemplate] = $row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE] - ? $row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE] - : $row[ImportAdvancedPricing::COL_TIER_PRICE]; - $exportRow[ImportAdvancedPricing::COL_TIER_PRICE_TYPE] - = $this->tierPriceTypeValue($row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]); - } else { - $exportRow[$keyTemplate] = $row[$keyTemplate]; - } + $exportRow = $this->templateExportData; + foreach (array_keys($exportRow) as $keyTemplate) { + if (array_key_exists($keyTemplate, $tierPriceData)) { + if (in_array($keyTemplate, $this->_priceWebsite)) { + $exportRow[$keyTemplate] = $this->_getWebsiteCode( + $tierPriceData[$keyTemplate] + ); + } elseif (in_array($keyTemplate, $this->_priceCustomerGroup)) { + $exportRow[$keyTemplate] = $this->_getCustomerGroupById( + $tierPriceData[$keyTemplate], + $tierPriceData[ImportAdvancedPricing::VALUE_ALL_GROUPS] + ); + unset($exportRow[ImportAdvancedPricing::VALUE_ALL_GROUPS]); + } elseif ($keyTemplate + === ImportAdvancedPricing::COL_TIER_PRICE + ) { + $exportRow[$keyTemplate] + = $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE] + ? $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE] + : $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE]; + $exportRow[ImportAdvancedPricing::COL_TIER_PRICE_TYPE] + = $this->tierPriceTypeValue($tierPriceData); + } else { + $exportRow[$keyTemplate] = $tierPriceData[$keyTemplate]; } } + } + + return $exportRow; + } - $customExportData[$key] = $exportRow; - unset($exportRow); + /** + * Correct export data. + * + * @param array $productsData + * @param array $tierPricesData + * + * @return array + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + protected function correctExportData( + array $productsData, + array $tierPricesData + ): array { + //Assigning SKUs to tier prices data. + $productLinkIdToSkuMap = []; + foreach ($productsData as $productData) { + $productLinkIdToSkuMap[$productData[Store::DEFAULT_STORE_ID][$this->getProductEntityLinkField()]] + = $productData[Store::DEFAULT_STORE_ID]['sku']; + } + unset($productData); + $linkedTierPricesData = []; + foreach ($tierPricesData as $tierPriceData) { + $sku = $productLinkIdToSkuMap[$tierPriceData['product_link_id']]; + $linkedTierPricesData[] = array_merge( + $tierPriceData, + [ImportAdvancedPricing::COL_SKU => $sku] + ); + } + unset($sku, $tierPriceData); + + $customExportData = []; + foreach ($linkedTierPricesData as $row) { + $customExportData[] = $this->createExportRow($row); } return $customExportData; @@ -327,12 +374,13 @@ protected function correctExportData($exportData) /** * Check type for tier price. * - * @param string $tierPricePercentage + * @param array $tierPriceData + * * @return string */ - private function tierPriceTypeValue($tierPricePercentage) + private function tierPriceTypeValue(array $tierPriceData): string { - return $tierPricePercentage + return $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE] ? ImportAdvancedPricing::TIER_PRICE_TYPE_PERCENT : ImportAdvancedPricing::TIER_PRICE_TYPE_FIXED; } @@ -340,54 +388,52 @@ private function tierPriceTypeValue($tierPricePercentage) /** * Get tier prices. * - * @param array $listSku + * @param string[] $productLinksIds * @param string $table * @return array|bool * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - protected function getTierPrices(array $listSku, $table) + protected function getTierPrices(array $productLinksIds, $table) { + $exportFilter = null; + $price = null; if (isset($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP])) { $exportFilter = $this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP]; } + $productEntityLinkField = $this->getProductEntityLinkField(); + if ($table == ImportAdvancedPricing::TABLE_TIER_PRICE) { $selectFields = [ - ImportAdvancedPricing::COL_SKU => 'cpe.sku', - ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE => 'ap.website_id', - ImportAdvancedPricing::VALUE_ALL_GROUPS => 'ap.all_groups', - ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP => 'ap.customer_group_id', - ImportAdvancedPricing::COL_TIER_PRICE_QTY => 'ap.qty', - ImportAdvancedPricing::COL_TIER_PRICE => 'ap.value', + ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE => 'ap.website_id', + ImportAdvancedPricing::VALUE_ALL_GROUPS => 'ap.all_groups', + ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP => 'ap.customer_group_id', + ImportAdvancedPricing::COL_TIER_PRICE_QTY => 'ap.qty', + ImportAdvancedPricing::COL_TIER_PRICE => 'ap.value', ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE => 'ap.percentage_value', + 'product_link_id' => 'ap.' + .$productEntityLinkField, ]; - if (isset($exportFilter) && !empty($exportFilter)) { - $price = $exportFilter['tier_price']; - } - } - if ($listSku) { - if (isset($exportFilter) && !empty($exportFilter)) { - $date = $exportFilter[\Magento\Catalog\Model\Category::KEY_UPDATED_AT]; - if (isset($date[0]) && !empty($date[0])) { - $updatedAtFrom = $this->_localeDate->date($date[0], null, false)->format('Y-m-d H:i:s'); - } - if (isset($date[1]) && !empty($date[1])) { - $updatedAtTo = $this->_localeDate->date($date[1], null, false)->format('Y-m-d H:i:s'); + if ($exportFilter) { + if (array_key_exists('tier_price', $exportFilter)) { + $price = $exportFilter['tier_price']; } } + } else { + throw new \InvalidArgumentException('Proper table name needed'); + } + + if ($productLinksIds) { try { - $productEntityLinkField = $this->getProductEntityLinkField(); $select = $this->_connection->select() ->from( - ['cpe' => $this->_resource->getTableName('catalog_product_entity')], - $selectFields - ) - ->joinInner( ['ap' => $this->_resource->getTableName($table)], - 'ap.' . $productEntityLinkField . ' = cpe.' . $productEntityLinkField, - [] + $selectFields ) - ->where('cpe.entity_id IN (?)', $listSku); + ->where( + 'ap.'.$productEntityLinkField.' IN (?)', + $productLinksIds + ); if (isset($price[0]) && !empty($price[0])) { $select->where('ap.value >= ?', $price[0]); @@ -398,18 +444,16 @@ protected function getTierPrices(array $listSku, $table) if (isset($price[0]) && !empty($price[0]) || isset($price[1]) && !empty($price[1])) { $select->orWhere('ap.percentage_value IS NOT NULL'); } - if (isset($updatedAtFrom) && !empty($updatedAtFrom)) { - $select->where('cpe.updated_at >= ?', $updatedAtFrom); - } - if (isset($updatedAtTo) && !empty($updatedAtTo)) { - $select->where('cpe.updated_at <= ?', $updatedAtTo); - } + $exportData = $this->_connection->fetchAll($select); } catch (\Exception $e) { return false; } + + return $exportData; + } else { + return false; } - return $exportData; } /** @@ -418,35 +462,46 @@ protected function getTierPrices(array $listSku, $table) * @param int $websiteId * @return string */ - protected function _getWebsiteCode($websiteId) + protected function _getWebsiteCode(int $websiteId): string { - $storeName = ($websiteId == 0) - ? ImportAdvancedPricing::VALUE_ALL_WEBSITES - : $this->_storeManager->getWebsite($websiteId)->getCode(); - $currencyCode = ''; - if ($websiteId == 0) { - $currencyCode = $this->_storeManager->getWebsite($websiteId)->getBaseCurrencyCode(); - } - if ($storeName && $currencyCode) { - return $storeName . ' [' . $currencyCode . ']'; - } else { - return $storeName; + if (!array_key_exists($websiteId, $this->websiteCodesMap)) { + $storeName = ($websiteId == 0) + ? ImportAdvancedPricing::VALUE_ALL_WEBSITES + : $this->_storeManager->getWebsite($websiteId)->getCode(); + $currencyCode = ''; + if ($websiteId == 0) { + $currencyCode = $this->_storeManager->getWebsite($websiteId) + ->getBaseCurrencyCode(); + } + + if ($storeName && $currencyCode) { + $code = $storeName.' ['.$currencyCode.']'; + } else { + $code = $storeName; + } + $this->websiteCodesMap[$websiteId] = $code; } + + return $this->websiteCodesMap[$websiteId]; } /** * Get Customer Group By Id * * @param int $customerGroupId - * @param null $allGroups + * @param int $allGroups * @return string */ - protected function _getCustomerGroupById($customerGroupId, $allGroups = null) - { - if ($allGroups) { + protected function _getCustomerGroupById( + int $customerGroupId, + int $allGroups = 0 + ): string { + if ($allGroups !== 0) { return ImportAdvancedPricing::VALUE_ALL_GROUPS; } else { - return $this->_groupRepository->getById($customerGroupId)->getCode(); + return $this->_groupRepository + ->getById($customerGroupId) + ->getCode(); } } diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php index 23829d3725119..0e8acb37104e6 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php @@ -394,7 +394,7 @@ protected function saveAndReplaceAdvancedPrices() ? $rowData[self::COL_TIER_PRICE] : 0, 'percentage_value' => $rowData[self::COL_TIER_PRICE_TYPE] === self::TIER_PRICE_TYPE_PERCENT ? $rowData[self::COL_TIER_PRICE] : null, - 'website_id' => $this->getWebsiteId($rowData[self::COL_TIER_PRICE_WEBSITE]) + 'website_id' => $this->getWebSiteId($rowData[self::COL_TIER_PRICE_WEBSITE]) ]; } } diff --git a/app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricing/Validator/WebsiteTest.php b/app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricing/Validator/WebsiteTest.php index 5111b4932d7a8..9a380ff75da24 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricing/Validator/WebsiteTest.php +++ b/app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricing/Validator/WebsiteTest.php @@ -27,7 +27,7 @@ class WebsiteTest extends \PHPUnit\Framework\TestCase protected function setUp() { - $this->webSiteModel = $this->getMockBuilder(\Magento\Store\Model\WebSite::class) + $this->webSiteModel = $this->getMockBuilder(\Magento\Store\Model\Website::class) ->setMethods(['getBaseCurrency']) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/AdvancedPricingImportExport/composer.json b/app/code/Magento/AdvancedPricingImportExport/composer.json index 228464ecd6304..79e6e2d368736 100644 --- a/app/code/Magento/AdvancedPricingImportExport/composer.json +++ b/app/code/Magento/AdvancedPricingImportExport/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-catalog": "101.1.*", + "magento/module-catalog": "102.0.*", "magento/module-catalog-inventory": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-import-export": "100.2.*", "magento/module-catalog-import-export": "100.2.*", - "magento/module-customer": "100.2.*", + "magento/module-customer": "101.0.*", "magento/module-store": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Analytics/Api/Data/LinkInterface.php b/app/code/Magento/Analytics/Api/Data/LinkInterface.php new file mode 100644 index 0000000000000..6597dff868b9f --- /dev/null +++ b/app/code/Magento/Analytics/Api/Data/LinkInterface.php @@ -0,0 +1,24 @@ +' . $element->getLabel() . ''; + $html .= '

' . $element->getComment() . '
'; + return $this->decorateRowHtml($element, $html); + } + + /** + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param string $html + * @return string + */ + private function decorateRowHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element, $html) + { + return sprintf( + '
%s
', + $element->getHtmlId(), + $html + ); + } +} diff --git a/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php new file mode 100644 index 0000000000000..34f2b7d53d9be --- /dev/null +++ b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/CollectionTimeLabel.php @@ -0,0 +1,53 @@ +localeResolver = $localeResolver ?: + ObjectManager::getInstance()->get(\Magento\Framework\Locale\ResolverInterface::class); + parent::__construct($context, $data); + } + + /** + * Add current time zone to comment, properly translated according to locale + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @return string + */ + public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + { + $timeZoneCode = $this->_localeDate->getConfigTimezone(); + $locale = $this->localeResolver->getLocale(); + $getLongTimeZoneName = \IntlTimeZone::createTimeZone($timeZoneCode) + ->getDisplayName(false, \IntlTimeZone::DISPLAY_LONG, $locale); + $element->setData( + 'comment', + sprintf("%s (%s)", $getLongTimeZoneName, $timeZoneCode) + ); + return parent::render($element); + } +} diff --git a/app/code/Magento/Analytics/Block/Adminhtml/System/Config/SubscriptionStatusLabel.php b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/SubscriptionStatusLabel.php new file mode 100644 index 0000000000000..c09213c7f009d --- /dev/null +++ b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/SubscriptionStatusLabel.php @@ -0,0 +1,64 @@ +subscriptionStatusProvider = $labelStatusProvider; + } + + /** + * Add Subscription status to comment + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @return string + */ + public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + { + $element->setData( + 'comment', + $this->prepareLabelValue() + ); + return parent::render($element); + } + + /** + * Prepare label for subscription status + * + * @return string + */ + private function prepareLabelValue() + { + return __('Subscription status') . ': ' . __($this->subscriptionStatusProvider->getStatus()); + } +} diff --git a/app/code/Magento/Analytics/Block/Adminhtml/System/Config/Vertical.php b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/Vertical.php new file mode 100644 index 0000000000000..99606e10f99d9 --- /dev/null +++ b/app/code/Magento/Analytics/Block/Adminhtml/System/Config/Vertical.php @@ -0,0 +1,41 @@ +' . $element->getHint() . ''; + $html .= '
' . $element->getComment() . '
'; + return $this->decorateRowHtml($element, $html); + } + + /** + * Decorates row HTML for custom element style + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param string $html + * @return string + */ + private function decorateRowHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element, $html) + { + $rowHtml = sprintf('%s', $html); + $rowHtml .= sprintf( + '%s%s', + $element->getHtmlId(), + $element->getLabelHtml($element->getHtmlId(), "[WEBSITE]"), + $element->getElementHtml() + ); + return $rowHtml; + } +} diff --git a/app/code/Magento/Analytics/Controller/Adminhtml/BIEssentials/SignUp.php b/app/code/Magento/Analytics/Controller/Adminhtml/BIEssentials/SignUp.php new file mode 100644 index 0000000000000..a90a971cf41b4 --- /dev/null +++ b/app/code/Magento/Analytics/Controller/Adminhtml/BIEssentials/SignUp.php @@ -0,0 +1,64 @@ +config = $config; + parent::__construct($context); + } + + /** + * Check admin permissions for this controller + * + * @return boolean + */ + protected function _isAllowed() + { + return $this->_authorization->isAllowed('Magento_Analytics::bi_essentials'); + } + + /** + * Provides link to BI Essentials signup + * + * @return \Magento\Framework\Controller\AbstractResult + */ + public function execute() + { + return $this->resultRedirectFactory->create()->setUrl( + $this->config->getValue($this->urlBIEssentialsConfigPath) + ); + } +} diff --git a/app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php b/app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php new file mode 100644 index 0000000000000..1b0e5c92420de --- /dev/null +++ b/app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php @@ -0,0 +1,75 @@ +reportUrlProvider = $reportUrlProvider; + parent::__construct($context); + } + + /** + * Check admin permissions for this controller. + * + * @return boolean + */ + protected function _isAllowed() + { + return $this->_authorization->isAllowed('Magento_Analytics::analytics_settings'); + } + + /** + * Redirect to resource with reports. + * + * @return Redirect $resultRedirect + */ + public function execute() + { + /** @var Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + try { + $resultRedirect->setUrl($this->reportUrlProvider->getUrl()); + } catch (SubscriptionUpdateException $e) { + $this->getMessageManager()->addNoticeMessage($e->getMessage()); + $resultRedirect->setPath('adminhtml'); + } catch (LocalizedException $e) { + $this->getMessageManager()->addExceptionMessage($e, $e->getMessage()); + $resultRedirect->setPath('adminhtml'); + } catch (\Exception $e) { + $this->getMessageManager()->addExceptionMessage( + $e, + __('Sorry, there has been an error processing your request. Please try again later.') + ); + $resultRedirect->setPath('adminhtml'); + } + + return $resultRedirect; + } +} diff --git a/app/code/Magento/Analytics/Controller/Adminhtml/Subscription/Retry.php b/app/code/Magento/Analytics/Controller/Adminhtml/Subscription/Retry.php new file mode 100644 index 0000000000000..122cf74123cc9 --- /dev/null +++ b/app/code/Magento/Analytics/Controller/Adminhtml/Subscription/Retry.php @@ -0,0 +1,73 @@ +subscriptionHandler = $subscriptionHandler; + parent::__construct($context); + } + + /** + * Check admin permissions for this controller + * + * @return boolean + */ + protected function _isAllowed() + { + return $this->_authorization->isAllowed('Magento_Analytics::analytics_settings'); + } + + /** + * Retry process of subscription. + * + * @return Redirect + */ + public function execute() + { + /** @var Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + try { + $resultRedirect->setPath('adminhtml'); + $this->subscriptionHandler->processEnabled(); + } catch (LocalizedException $e) { + $this->getMessageManager()->addExceptionMessage($e, $e->getMessage()); + } catch (\Exception $e) { + $this->getMessageManager()->addExceptionMessage( + $e, + __('Sorry, there has been an error processing your request. Please try again later.') + ); + } + + return $resultRedirect; + } +} diff --git a/app/code/Magento/Analytics/Cron/CollectData.php b/app/code/Magento/Analytics/Cron/CollectData.php new file mode 100644 index 0000000000000..ff0b3e4f67638 --- /dev/null +++ b/app/code/Magento/Analytics/Cron/CollectData.php @@ -0,0 +1,53 @@ +exportDataHandler = $exportDataHandler; + $this->subscriptionStatus = $subscriptionStatus; + } + + /** + * @return bool + */ + public function execute() + { + if ($this->subscriptionStatus->getStatus() === SubscriptionStatusProvider::ENABLED) { + $this->exportDataHandler->prepareExportData(); + } + + return true; + } +} diff --git a/app/code/Magento/Analytics/Cron/SignUp.php b/app/code/Magento/Analytics/Cron/SignUp.php new file mode 100644 index 0000000000000..c17b9b8c381c3 --- /dev/null +++ b/app/code/Magento/Analytics/Cron/SignUp.php @@ -0,0 +1,101 @@ +connector = $connector; + $this->configWriter = $configWriter; + $this->flagManager = $flagManager; + $this->reinitableConfig = $reinitableConfig; + } + + /** + * Execute scheduled subscription operation + * In case of failure writes message to notifications inbox + * + * @return bool + */ + public function execute() + { + $attemptsCount = $this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); + + if (($attemptsCount === null) || ($attemptsCount <= 0)) { + $this->deleteAnalyticsCronExpr(); + $this->flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); + return false; + } + + $attemptsCount -= 1; + $this->flagManager->saveFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, $attemptsCount); + $signUpResult = $this->connector->execute('signUp'); + if ($signUpResult === false) { + return false; + } + + $this->deleteAnalyticsCronExpr(); + $this->flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); + return true; + } + + /** + * Delete cron schedule setting into config. + * + * Delete cron schedule setting for subscription handler into config and + * re-initialize config cache to avoid auto-generate new schedule items. + * + * @return bool + */ + private function deleteAnalyticsCronExpr() + { + $this->configWriter->delete(SubscriptionHandler::CRON_STRING_PATH); + $this->reinitableConfig->reinit(); + return true; + } +} diff --git a/app/code/Magento/Analytics/Cron/Update.php b/app/code/Magento/Analytics/Cron/Update.php new file mode 100644 index 0000000000000..9062a7bac7551 --- /dev/null +++ b/app/code/Magento/Analytics/Cron/Update.php @@ -0,0 +1,92 @@ +connector = $connector; + $this->configWriter = $configWriter; + $this->reinitableConfig = $reinitableConfig; + $this->flagManager = $flagManager; + $this->analyticsToken = $analyticsToken; + } + + /** + * Execute scheduled update operation + * + * @return bool + */ + public function execute() + { + $result = false; + $attemptsCount = $this->flagManager + ->getFlagData(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE); + + if ($attemptsCount) { + $attemptsCount -= 1; + $result = $this->connector->execute('update'); + } + + if ($result || ($attemptsCount <= 0) || (!$this->analyticsToken->isTokenExist())) { + $this->flagManager + ->deleteFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE); + $this->flagManager->deleteFlag(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE); + $this->configWriter->delete(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH); + $this->reinitableConfig->reinit(); + } + + return $result; + } +} diff --git a/app/code/Magento/Analytics/LICENSE.txt b/app/code/Magento/Analytics/LICENSE.txt new file mode 100644 index 0000000000000..49525fd99da9c --- /dev/null +++ b/app/code/Magento/Analytics/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/Analytics/LICENSE_AFL.txt b/app/code/Magento/Analytics/LICENSE_AFL.txt new file mode 100644 index 0000000000000..f39d641b18a19 --- /dev/null +++ b/app/code/Magento/Analytics/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/Analytics/Model/AnalyticsToken.php b/app/code/Magento/Analytics/Model/AnalyticsToken.php new file mode 100644 index 0000000000000..ccec4d1bbe958 --- /dev/null +++ b/app/code/Magento/Analytics/Model/AnalyticsToken.php @@ -0,0 +1,92 @@ +reinitableConfig = $reinitableConfig; + $this->config = $config; + $this->configWriter = $configWriter; + } + + /** + * Get Magento BI token value. + * + * @return string|null + */ + public function getToken() + { + return $this->config->getValue($this->tokenPath); + } + + /** + * Stores Magento BI token value. + * + * @param string $value + * + * @return bool + */ + public function storeToken($value) + { + $this->configWriter->save($this->tokenPath, $value); + $this->reinitableConfig->reinit(); + + return true; + } + + /** + * Check Magento BI token value exist. + * + * @return bool + */ + public function isTokenExist() + { + return (bool)$this->getToken(); + } +} diff --git a/app/code/Magento/Analytics/Model/Config.php b/app/code/Magento/Analytics/Model/Config.php new file mode 100644 index 0000000000000..ba508187b4b9f --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config.php @@ -0,0 +1,40 @@ +data = $data; + } + + /** + * Get config value by key. + * + * @param string|null $key + * @param string|null $default + * @return array + */ + public function get($key = null, $default = null) + { + return $this->data->get($key, $default); + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Backend/Baseurl/SubscriptionUpdateHandler.php b/app/code/Magento/Analytics/Model/Config/Backend/Baseurl/SubscriptionUpdateHandler.php new file mode 100644 index 0000000000000..6e6f008d49f7e --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Backend/Baseurl/SubscriptionUpdateHandler.php @@ -0,0 +1,107 @@ +analyticsToken = $analyticsToken; + $this->flagManager = $flagManager; + $this->reinitableConfig = $reinitableConfig; + $this->configWriter = $configWriter; + } + + /** + * Activate process of subscription update handling. + * + * @param string $url + * @return bool + */ + public function processUrlUpdate(string $url) + { + if ($this->analyticsToken->isTokenExist()) { + if (!$this->flagManager->getFlagData(self::PREVIOUS_BASE_URL_FLAG_CODE)) { + $this->flagManager->saveFlag(self::PREVIOUS_BASE_URL_FLAG_CODE, $url); + } + + $this->flagManager + ->saveFlag(self::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue); + $this->configWriter->save(self::UPDATE_CRON_STRING_PATH, $this->cronExpression); + $this->reinitableConfig->reinit(); + } + + return true; + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Backend/CollectionTime.php b/app/code/Magento/Analytics/Model/Config/Backend/CollectionTime.php new file mode 100644 index 0000000000000..e26ad01fc74bf --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Backend/CollectionTime.php @@ -0,0 +1,91 @@ +configWriter = $configWriter; + parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); + } + + /** + * {@inheritdoc} + * + * {@inheritdoc}. Set schedule setting for cron. + * + * @return Value + */ + public function afterSave() + { + $result = preg_match('#(?\d{2}),(?\d{2}),(?\d{2})#', $this->getValue(), $time); + + if (!$result) { + throw new LocalizedException(__('Time value has an unsupported format')); + } + + $cronExprArray = [ + $time['min'], # Minute + $time['hour'], # Hour + '*', # Day of the Month + '*', # Month of the Year + '*', # Day of the Week + ]; + + $cronExprString = join(' ', $cronExprArray); + + try { + $this->configWriter->save(self::CRON_SCHEDULE_PATH, $cronExprString); + } catch (\Exception $e) { + $this->_logger->error($e->getMessage()); + throw new LocalizedException(__('Cron settings can\'t be saved')); + } + + return parent::afterSave(); + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Backend/Enabled.php b/app/code/Magento/Analytics/Model/Config/Backend/Enabled.php new file mode 100644 index 0000000000000..ac97f2a843e61 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Backend/Enabled.php @@ -0,0 +1,84 @@ +subscriptionHandler = $subscriptionHandler; + parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); + } + + /** + * Add additional handling after config value was saved. + * + * @return Value + * @throws LocalizedException + */ + public function afterSave() + { + try { + if ($this->isValueChanged()) { + $enabled = $this->getData('value'); + + if ($enabled) { + $this->subscriptionHandler->processEnabled(); + } else { + $this->subscriptionHandler->processDisabled(); + } + } + } catch (\Exception $e) { + $this->_logger->error($e->getMessage()); + throw new LocalizedException(__('There was an error save new configuration value.')); + } + + return parent::afterSave(); + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Backend/Enabled/SubscriptionHandler.php b/app/code/Magento/Analytics/Model/Config/Backend/Enabled/SubscriptionHandler.php new file mode 100644 index 0000000000000..4b125949948c6 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Backend/Enabled/SubscriptionHandler.php @@ -0,0 +1,172 @@ +configWriter = $configWriter; + $this->flagManager = $flagManager; + $this->analyticsToken = $analyticsToken; + $this->reinitableConfig = $reinitableConfig; + } + + /** + * Processing of activation MBI subscription. + * + * Activate process of subscription handling if Analytics token is not received. + * + * @return bool + */ + public function processEnabled() + { + if (!$this->analyticsToken->isTokenExist()) { + $this->setCronSchedule(); + $this->setAttemptsFlag(); + $this->reinitableConfig->reinit(); + } + + return true; + } + + /** + * Set cron schedule setting into config for activation of subscription process. + * + * @return bool + */ + private function setCronSchedule() + { + $this->configWriter->save(self::CRON_STRING_PATH, join(' ', self::CRON_EXPR_ARRAY)); + return true; + } + + /** + * Set flag as reserve counter of attempts subscription operation. + * + * @return bool + */ + private function setAttemptsFlag() + { + return $this->flagManager + ->saveFlag(self::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue); + } + + /** + * Processing of deactivation MBI subscription. + * + * Disable data collection + * and interrupt subscription handling if Analytics token is not received. + * + * @return bool + */ + public function processDisabled() + { + $this->disableCollectionData(); + + if (!$this->analyticsToken->isTokenExist()) { + $this->unsetAttemptsFlag(); + } + + return true; + } + + /** + * Unset flag of attempts subscription operation. + * + * @return bool + */ + private function unsetAttemptsFlag() + { + return $this->flagManager + ->deleteFlag(self::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); + } + + /** + * Unset schedule of collection data cron. + * + * @return bool + */ + private function disableCollectionData() + { + $this->configWriter->delete(CollectionTime::CRON_SCHEDULE_PATH); + + return true; + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Backend/Vertical.php b/app/code/Magento/Analytics/Model/Config/Backend/Vertical.php new file mode 100644 index 0000000000000..1aabbb91ddf87 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Backend/Vertical.php @@ -0,0 +1,32 @@ +getValue())) { + throw new LocalizedException(__('Please select a vertical.')); + } + + return $this; + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Mapper.php b/app/code/Magento/Analytics/Model/Config/Mapper.php new file mode 100644 index 0000000000000..504690b8e4763 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Mapper.php @@ -0,0 +1,66 @@ + [ + * 'name' => 'file_name', + * 'providers' => [ + * 'reportProvider' => [ + * 'name' => 'report_provider_name', + * 'class' => 'Magento\Analytics\ReportXml\ReportProvider', + * 'parameters' =>[ + * 'name' => 'report_name', + * ], + * ], + * 'customProvider' => [ + * 'name' => 'custom_provider_name', + * 'class' => 'Magento\Analytics\Model\CustomProvider', + * ], + * ], + * ] + * ]; + */ + public function execute($configData) + { + if (!isset($configData['config'][0]['file'])) { + return []; + } + + $files = []; + foreach ($configData['config'][0]['file'] as $fileData) { + /** just one set of providers is allowed by xsd */ + $providers = reset($fileData['providers']); + foreach ($providers as $providerType => $providerDataSet) { + /** just one set of provider data is allowed by xsd */ + $providerData = reset($providerDataSet); + /** just one set of parameters is allowed by xsd */ + $providerData['parameters'] = !empty($providerData['parameters']) + ? reset($providerData['parameters']) + : []; + $providerData['parameters'] = array_map( + 'reset', + $providerData['parameters'] + ); + $providers[$providerType] = $providerData; + } + $files[$fileData['name']] = $fileData; + $files[$fileData['name']]['providers'] = $providers; + } + return $files; + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Reader.php b/app/code/Magento/Analytics/Model/Config/Reader.php new file mode 100644 index 0000000000000..8980e31627717 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Reader.php @@ -0,0 +1,52 @@ +mapper = $mapper; + $this->readers = $readers; + } + + /** + * Read configuration scope. + * + * @param string|null $scope + * @return array + */ + public function read($scope = null) + { + $data = []; + foreach ($this->readers as $reader) { + $data = array_merge_recursive($data, $reader->read($scope)); + } + + return $this->mapper->execute($data); + } +} diff --git a/app/code/Magento/Analytics/Model/Config/Source/Vertical.php b/app/code/Magento/Analytics/Model/Config/Source/Vertical.php new file mode 100644 index 0000000000000..c9d9582ea7c7a --- /dev/null +++ b/app/code/Magento/Analytics/Model/Config/Source/Vertical.php @@ -0,0 +1,51 @@ +verticals = $verticals; + } + + /** + * {@inheritdoc} + */ + public function toOptionArray() + { + $result = [ + ['value' => '', 'label' => __('--Please Select--')] + ]; + + foreach ($this->verticals as $vertical) { + $result[] = ['value' => $vertical, 'label' => __($vertical)]; + } + + return $result; + } +} diff --git a/app/code/Magento/Analytics/Model/ConfigInterface.php b/app/code/Magento/Analytics/Model/ConfigInterface.php new file mode 100644 index 0000000000000..caaa2e100c1c7 --- /dev/null +++ b/app/code/Magento/Analytics/Model/ConfigInterface.php @@ -0,0 +1,22 @@ + 'command_class_name'. + * + * The list may be configured in each module via '/etc/di.xml'. + * + * @var string[] + */ + private $commands; + + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @param array $commands + * @param ObjectManagerInterface $objectManager + */ + public function __construct( + array $commands, + ObjectManagerInterface $objectManager + ) { + $this->commands = $commands; + $this->objectManager = $objectManager; + } + + /** + * Executes a command in accordance with the given name. + * + * @param string $commandName + * @return bool + * @throws NotFoundException if the command is not found. + */ + public function execute($commandName) + { + if (!array_key_exists($commandName, $this->commands)) { + throw new NotFoundException(__('Command was not found.')); + } + + /** @var \Magento\Analytics\Model\Connector\CommandInterface $command */ + $command = $this->objectManager->create($this->commands[$commandName]); + + return $command->execute(); + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/CommandInterface.php b/app/code/Magento/Analytics/Model/Connector/CommandInterface.php new file mode 100644 index 0000000000000..7a8774fe3dba9 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/CommandInterface.php @@ -0,0 +1,21 @@ +curlFactory = $curlFactory; + $this->responseFactory = $responseFactory; + $this->converter = $converter; + $this->logger = $logger; + } + + /** + * {@inheritdoc} + */ + public function request($method, $url, array $body = [], array $headers = [], $version = '1.1') + { + $response = new \Zend_Http_Response(0, []); + + try { + $curl = $this->curlFactory->create(); + $headers = $this->applyContentTypeHeaderFromConverter($headers); + + $curl->write($method, $url, $version, $headers, $this->converter->toBody($body)); + + $result = $curl->read(); + + if ($curl->getErrno()) { + $this->logger->critical( + new \Exception( + sprintf( + 'MBI service CURL connection error #%s: %s', + $curl->getErrno(), + $curl->getError() + ) + ) + ); + + return $response; + } + + $response = $this->responseFactory->create($result); + } catch (\Exception $e) { + $this->logger->critical($e); + } + + return $response; + } + + /** + * @param array $headers + * + * @return array + */ + private function applyContentTypeHeaderFromConverter(array $headers) + { + $contentTypeHeaderKey = array_search($this->converter->getContentTypeHeader(), $headers); + if ($contentTypeHeaderKey === false) { + $headers[] = $this->converter->getContentTypeHeader(); + } + + return $headers; + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/Http/ClientInterface.php b/app/code/Magento/Analytics/Model/Connector/Http/ClientInterface.php new file mode 100644 index 0000000000000..a1e1f057684f6 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/Http/ClientInterface.php @@ -0,0 +1,29 @@ +converter = $converter; + $this->responseHandlers = $responseHandlers; + } + + /** + * @param \Zend_Http_Response $response + * + * @return bool|string + */ + public function getResult(\Zend_Http_Response $response) + { + $result = false; + $responseBody = $this->converter->fromBody($response->getBody()); + if (array_key_exists($response->getStatus(), $this->responseHandlers)) { + $result = $this->responseHandlers[$response->getStatus()]->handleResponse($responseBody); + } + + return $result; + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/NotifyDataChangedCommand.php b/app/code/Magento/Analytics/Model/Connector/NotifyDataChangedCommand.php new file mode 100644 index 0000000000000..f1a8ea6460f9d --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/NotifyDataChangedCommand.php @@ -0,0 +1,93 @@ +analyticsToken = $analyticsToken; + $this->httpClient = $httpClient; + $this->config = $config; + $this->responseResolver = $responseResolver; + $this->logger = $logger; + } + + /** + * Notify MBI about that data collection was finished + * + * @return bool + */ + public function execute() + { + $result = false; + if ($this->analyticsToken->isTokenExist()) { + $response = $this->httpClient->request( + ZendClient::POST, + $this->config->getValue($this->notifyDataChangedUrlPath), + [ + "access-token" => $this->analyticsToken->getToken(), + "url" => $this->config->getValue(Store::XML_PATH_SECURE_BASE_URL), + ] + ); + $result = $this->responseResolver->getResult($response); + } + return (bool)$result; + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/OTPRequest.php b/app/code/Magento/Analytics/Model/Connector/OTPRequest.php new file mode 100644 index 0000000000000..dfa283e10d070 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/OTPRequest.php @@ -0,0 +1,115 @@ +analyticsToken = $analyticsToken; + $this->httpClient = $httpClient; + $this->config = $config; + $this->responseResolver = $responseResolver; + $this->logger = $logger; + } + + /** + * Performs obtaining of an OTP from the MBI service. + * + * Returns received OTP or FALSE in case of failure. + * + * @return string|false + */ + public function call() + { + $result = false; + + if ($this->analyticsToken->isTokenExist()) { + $response = $this->httpClient->request( + ZendClient::POST, + $this->config->getValue($this->otpUrlConfigPath), + [ + "access-token" => $this->analyticsToken->getToken(), + "url" => $this->config->getValue(Store::XML_PATH_SECURE_BASE_URL), + ] + ); + + $result = $this->responseResolver->getResult($response); + if (!$result) { + $this->logger->warning( + sprintf( + 'Obtaining of an OTP from the MBI service has been failed: %s', + !empty($response->getBody()) ? $response->getBody() : 'Response body is empty.' + ) + ); + } + } + + return $result; + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/ResponseHandler/OTP.php b/app/code/Magento/Analytics/Model/Connector/ResponseHandler/OTP.php new file mode 100644 index 0000000000000..d9a672e81f43d --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/ResponseHandler/OTP.php @@ -0,0 +1,24 @@ +analyticsToken = $analyticsToken; + $this->subscriptionHandler = $subscriptionHandler; + $this->subscriptionStatusProvider = $subscriptionStatusProvider; + } + + /** + * @inheritdoc + */ + public function handleResponse(array $responseBody) + { + if ($this->subscriptionStatusProvider->getStatus() === SubscriptionStatusProvider::ENABLED) { + $this->analyticsToken->storeToken(null); + $this->subscriptionHandler->processEnabled(); + } + return false; + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/ResponseHandler/SignUp.php b/app/code/Magento/Analytics/Model/Connector/ResponseHandler/SignUp.php new file mode 100644 index 0000000000000..b2261e418abc7 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/ResponseHandler/SignUp.php @@ -0,0 +1,51 @@ +analyticsToken = $analyticsToken; + $this->converter = $converter; + } + + /** + * @inheritdoc + */ + public function handleResponse(array $body) + { + if (isset($body['access-token']) && !empty($body['access-token'])) { + $this->analyticsToken->storeToken($body['access-token']); + return $body['access-token']; + } + + return false; + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/ResponseHandler/Update.php b/app/code/Magento/Analytics/Model/Connector/ResponseHandler/Update.php new file mode 100644 index 0000000000000..73fc575ae2821 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/ResponseHandler/Update.php @@ -0,0 +1,24 @@ +analyticsToken = $analyticsToken; + $this->integrationManager = $integrationManager; + $this->config = $config; + $this->httpClient = $httpClient; + $this->logger = $logger; + $this->responseResolver = $responseResolver; + } + + /** + * Executes signUp command + * + * During this call Magento generates or retrieves access token for the integration user + * In case successful generation Magento activates user and sends access token to MA + * As the response, Magento receives a token to MA + * Magento stores this token in System Configuration + * + * This method returns true in case of success + * + * @return bool + */ + public function execute() + { + $result = false; + $integrationToken = $this->integrationManager->generateToken(); + if ($integrationToken) { + $this->integrationManager->activateIntegration(); + $response = $this->httpClient->request( + ZendClient::POST, + $this->config->getValue($this->signUpUrlPath), + [ + "token" => $integrationToken->getData('token'), + "url" => $this->config->getValue(Store::XML_PATH_SECURE_BASE_URL), + ] + ); + + $result = $this->responseResolver->getResult($response); + if (!$result) { + $this->logger->warning( + sprintf( + 'Subscription for MBI service has been failed. An error occurred during token exchange: %s', + !empty($response->getBody()) ? $response->getBody() : 'Response body is empty.' + ) + ); + } + } + + return (bool)$result; + } +} diff --git a/app/code/Magento/Analytics/Model/Connector/UpdateCommand.php b/app/code/Magento/Analytics/Model/Connector/UpdateCommand.php new file mode 100644 index 0000000000000..8f05f1107e87e --- /dev/null +++ b/app/code/Magento/Analytics/Model/Connector/UpdateCommand.php @@ -0,0 +1,114 @@ +analyticsToken = $analyticsToken; + $this->httpClient = $httpClient; + $this->config = $config; + $this->logger = $logger; + $this->flagManager = $flagManager; + $this->responseResolver = $responseResolver; + } + + /** + * Executes update request to MBI api in case store url was changed + * + * @return bool + */ + public function execute() + { + $result = false; + if ($this->analyticsToken->isTokenExist()) { + $response = $this->httpClient->request( + ZendClient::PUT, + $this->config->getValue($this->updateUrlPath), + [ + "url" => $this->flagManager + ->getFlagData(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE), + "new-url" => $this->config->getValue(Store::XML_PATH_SECURE_BASE_URL), + "access-token" => $this->analyticsToken->getToken(), + ] + ); + $result = $this->responseResolver->getResult($response); + if (!$result) { + $this->logger->warning( + sprintf( + 'Update of the subscription for MBI service has been failed: %s', + !empty($response->getBody()) ? $response->getBody() : 'Response body is empty.' + ) + ); + } + } + + return (bool)$result; + } +} diff --git a/app/code/Magento/Analytics/Model/Cryptographer.php b/app/code/Magento/Analytics/Model/Cryptographer.php new file mode 100644 index 0000000000000..6905eee372ae2 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Cryptographer.php @@ -0,0 +1,130 @@ +analyticsToken = $analyticsToken; + $this->encodedContextFactory = $encodedContextFactory; + } + + /** + * Encrypt input data. + * + * @param string $source + * @return EncodedContext + * @throws LocalizedException + */ + public function encode($source) + { + if (!is_string($source)) { + try { + $source = (string)$source; + } catch (\Exception $e) { + throw new LocalizedException(__('Input data must be string or convertible into string.')); + } + } elseif (!$source) { + throw new LocalizedException(__('Input data must be non-empty string.')); + } + if (!$this->validateCipherMethod($this->cipherMethod)) { + throw new LocalizedException(__('Not valid cipher method.')); + } + $initializationVector = $this->getInitializationVector(); + + $encodedContext = $this->encodedContextFactory->create([ + 'content' => openssl_encrypt( + $source, + $this->cipherMethod, + $this->getKey(), + OPENSSL_RAW_DATA, + $initializationVector + ), + 'initializationVector' => $initializationVector, + ]); + + return $encodedContext; + } + + /** + * Return key for encryption. + * + * @return string + * @throws LocalizedException + */ + private function getKey() + { + $token = $this->analyticsToken->getToken(); + if (!$token) { + throw new LocalizedException(__('Encryption key can\'t be empty.')); + } + return hash('sha256', $token); + } + + /** + * Return established cipher method. + * + * @return string + */ + private function getCipherMethod() + { + return $this->cipherMethod; + } + + /** + * Return each time generated random initialization vector which depends on the cipher method. + * + * @return string + */ + private function getInitializationVector() + { + $ivSize = openssl_cipher_iv_length($this->getCipherMethod()); + return openssl_random_pseudo_bytes($ivSize); + } + + /** + * Check that cipher method is allowed for encryption. + * + * @param string $cipherMethod + * @return bool + */ + private function validateCipherMethod($cipherMethod) + { + $methods = openssl_get_cipher_methods(); + return (false !== array_search($cipherMethod, $methods)); + } +} diff --git a/app/code/Magento/Analytics/Model/EncodedContext.php b/app/code/Magento/Analytics/Model/EncodedContext.php new file mode 100644 index 0000000000000..5fb2d0c15aef7 --- /dev/null +++ b/app/code/Magento/Analytics/Model/EncodedContext.php @@ -0,0 +1,52 @@ +content = $content; + $this->initializationVector = $initializationVector; + } + + /** + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * @return string + */ + public function getInitializationVector() + { + return $this->initializationVector; + } +} diff --git a/app/code/Magento/Analytics/Model/Exception/State/SubscriptionUpdateException.php b/app/code/Magento/Analytics/Model/Exception/State/SubscriptionUpdateException.php new file mode 100644 index 0000000000000..5d127037afea9 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Exception/State/SubscriptionUpdateException.php @@ -0,0 +1,17 @@ +filesystem = $filesystem; + $this->archive = $archive; + $this->reportWriter = $reportWriter; + $this->cryptographer = $cryptographer; + $this->fileRecorder = $fileRecorder; + } + + /** + * @inheritdoc + */ + public function prepareExportData() + { + try { + $tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP); + + $this->prepareDirectory($tmpDirectory, $this->getTmpFilesDirRelativePath()); + $this->reportWriter->write($tmpDirectory, $this->getTmpFilesDirRelativePath()); + + $tmpFilesDirectoryAbsolutePath = $this->validateSource($tmpDirectory, $this->getTmpFilesDirRelativePath()); + $archiveAbsolutePath = $this->prepareFileDirectory($tmpDirectory, $this->getArchiveRelativePath()); + $this->pack( + $tmpFilesDirectoryAbsolutePath, + $archiveAbsolutePath + ); + + $this->validateSource($tmpDirectory, $this->getArchiveRelativePath()); + $this->fileRecorder->recordNewFile( + $this->cryptographer->encode($tmpDirectory->readFile($this->getArchiveRelativePath())) + ); + } finally { + $tmpDirectory->delete($this->getTmpFilesDirRelativePath()); + $tmpDirectory->delete($this->getArchiveRelativePath()); + } + + return true; + } + + /** + * Return relative path to a directory for temporary files with reports data. + * + * @return string + */ + private function getTmpFilesDirRelativePath() + { + return $this->subdirectoryPath . 'tmp/'; + } + + /** + * Return relative path to a directory for an archive. + * + * @return string + */ + private function getArchiveRelativePath() + { + return $this->subdirectoryPath . $this->archiveName; + } + + /** + * Clean up a directory. + * + * @param WriteInterface $directory + * @param string $path + * @return string + */ + private function prepareDirectory(WriteInterface $directory, $path) + { + $directory->delete($path); + + return $directory->getAbsolutePath($path); + } + + /** + * Remove a file and a create parent directory a file. + * + * @param WriteInterface $directory + * @param string $path + * @return string + */ + private function prepareFileDirectory(WriteInterface $directory, $path) + { + $directory->delete($path); + if (dirname($path) !== '.') { + $directory->create(dirname($path)); + } + + return $directory->getAbsolutePath($path); + } + + /** + * Packing data into an archive. + * + * @param string $source + * @param string $destination + * @return bool + */ + private function pack($source, $destination) + { + $this->archive->pack( + $source, + $destination, + is_dir($source) ?: false + ); + + return true; + } + + /** + * Validate that data source exist. + * + * Return absolute path in a validated data source. + * + * @param WriteInterface $directory + * @param string $path + * @return string + * @throws LocalizedException If source is not exist. + */ + private function validateSource(WriteInterface $directory, $path) + { + if (!$directory->isExist($path)) { + throw new LocalizedException(__('Source "%1" is not exist', $directory->getAbsolutePath($path))); + } + + return $directory->getAbsolutePath($path); + } +} diff --git a/app/code/Magento/Analytics/Model/ExportDataHandlerInterface.php b/app/code/Magento/Analytics/Model/ExportDataHandlerInterface.php new file mode 100644 index 0000000000000..65efb33659c89 --- /dev/null +++ b/app/code/Magento/Analytics/Model/ExportDataHandlerInterface.php @@ -0,0 +1,19 @@ +exportDataHandler = $exportDataHandler; + $this->analyticsConnector = $connector; + } + + /** + * {@inheritdoc} + * Execute notification command. + * + * @return bool + */ + public function prepareExportData() + { + $result = $this->exportDataHandler->prepareExportData(); + $this->analyticsConnector->execute('notifyDataChanged'); + return $result; + } +} diff --git a/app/code/Magento/Analytics/Model/FileInfo.php b/app/code/Magento/Analytics/Model/FileInfo.php new file mode 100644 index 0000000000000..19bdaf21b2a20 --- /dev/null +++ b/app/code/Magento/Analytics/Model/FileInfo.php @@ -0,0 +1,52 @@ +path = $path; + $this->initializationVector = $initializationVector; + } + + /** + * @return string + */ + public function getPath() + { + return $this->path; + } + + /** + * @return string + */ + public function getInitializationVector() + { + return $this->initializationVector; + } +} diff --git a/app/code/Magento/Analytics/Model/FileInfoManager.php b/app/code/Magento/Analytics/Model/FileInfoManager.php new file mode 100644 index 0000000000000..e37700e665420 --- /dev/null +++ b/app/code/Magento/Analytics/Model/FileInfoManager.php @@ -0,0 +1,123 @@ +flagManager = $flagManager; + $this->fileInfoFactory = $fileInfoFactory; + } + + /** + * Save FileInfo object. + * + * @param FileInfo $fileInfo + * @return bool + * @throws LocalizedException + */ + public function save(FileInfo $fileInfo) + { + $parameters = []; + $parameters['initializationVector'] = $fileInfo->getInitializationVector(); + $parameters['path'] = $fileInfo->getPath(); + + $emptyParameters = array_diff($parameters, array_filter($parameters)); + if ($emptyParameters) { + throw new LocalizedException( + __('These arguments can\'t be empty "%1"', implode(', ', array_keys($emptyParameters))) + ); + } + + foreach ($this->encodedParameters as $encodedParameter) { + $parameters[$encodedParameter] = $this->encodeValue($parameters[$encodedParameter]); + } + + $this->flagManager->saveFlag($this->flagCode, $parameters); + + return true; + } + + /** + * Load FileInfo object. + * + * @return FileInfo + */ + public function load() + { + $parameters = $this->flagManager->getFlagData($this->flagCode) ?: []; + + $encodedParameters = array_intersect($this->encodedParameters, array_keys($parameters)); + foreach ($encodedParameters as $encodedParameter) { + $parameters[$encodedParameter] = $this->decodeValue($parameters[$encodedParameter]); + } + + $fileInfo = $this->fileInfoFactory->create($parameters); + + return $fileInfo; + } + + /** + * Encode value. + * + * @param string $value + * @return string + */ + private function encodeValue($value) + { + return base64_encode($value); + } + + /** + * Decode value. + * + * @param string $value + * @return string + */ + private function decodeValue($value) + { + return base64_decode($value); + } +} diff --git a/app/code/Magento/Analytics/Model/FileRecorder.php b/app/code/Magento/Analytics/Model/FileRecorder.php new file mode 100644 index 0000000000000..70438a98d56f1 --- /dev/null +++ b/app/code/Magento/Analytics/Model/FileRecorder.php @@ -0,0 +1,136 @@ +fileInfoManager = $fileInfoManager; + $this->fileInfoFactory = $fileInfoFactory; + $this->filesystem = $filesystem; + } + + /** + * Save new encrypted file, register it and remove old registered file. + * + * @param EncodedContext $encodedContext + * @return bool + */ + public function recordNewFile(EncodedContext $encodedContext) + { + $directory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); + + $fileRelativePath = $this->getFileRelativePath(); + $directory->writeFile($fileRelativePath, $encodedContext->getContent()); + + $fileInfo = $this->fileInfoManager->load(); + $this->registerFile($encodedContext, $fileRelativePath); + $this->removeOldFile($fileInfo, $directory); + + return true; + } + + /** + * Return relative path to encoded file. + * + * @return string + */ + private function getFileRelativePath() + { + return $this->fileSubdirectoryPath . hash('sha256', time()) + . '/' . $this->encodedFileName; + } + + /** + * Register encoded file. + * + * @param EncodedContext $encodedContext + * @param string $fileRelativePath + * @return bool + */ + private function registerFile(EncodedContext $encodedContext, $fileRelativePath) + { + $newFileInfo = $this->fileInfoFactory->create( + [ + 'path' => $fileRelativePath, + 'initializationVector' => $encodedContext->getInitializationVector(), + ] + ); + $this->fileInfoManager->save($newFileInfo); + + return true; + } + + /** + * Remove previously registered file. + * + * @param FileInfo $fileInfo + * @param WriteInterface $directory + * @return bool + */ + private function removeOldFile(FileInfo $fileInfo, WriteInterface $directory) + { + if (!$fileInfo->getPath()) { + return true; + } + + $directory->delete($fileInfo->getPath()); + + $directoryName = dirname($fileInfo->getPath()); + if ($directoryName !== '.') { + $directory->delete($directoryName); + } + + return true; + } +} diff --git a/app/code/Magento/Analytics/Model/IntegrationManager.php b/app/code/Magento/Analytics/Model/IntegrationManager.php new file mode 100644 index 0000000000000..61a40a955e026 --- /dev/null +++ b/app/code/Magento/Analytics/Model/IntegrationManager.php @@ -0,0 +1,126 @@ +integrationService = $integrationService; + $this->config = $config; + $this->oauthService = $oauthService; + } + + /** + * Activate predefined integration user + * + * @return bool + * @throws NoSuchEntityException + */ + public function activateIntegration() + { + $integration = $this->integrationService->findByName( + $this->config->getConfigDataValue('analytics/integration_name') + ); + if (!$integration->getId()) { + throw new NoSuchEntityException(__('Cannot find predefined integration user!')); + } + $integrationData = $this->getIntegrationData(Integration::STATUS_ACTIVE); + $integrationData['integration_id'] = $integration->getId(); + $this->integrationService->update($integrationData); + return true; + } + + /** + * This method execute Generate Token command and enable integration + * + * @return bool|\Magento\Integration\Model\Oauth\Token + */ + public function generateToken() + { + $consumerId = $this->generateIntegration()->getConsumerId(); + $accessToken = $this->oauthService->getAccessToken($consumerId); + if (!$accessToken && $this->oauthService->createAccessToken($consumerId, true)) { + $accessToken = $this->oauthService->getAccessToken($consumerId); + } + return $accessToken; + } + + /** + * Returns consumer Id for MA integration user + * + * @return \Magento\Integration\Model\Integration + */ + private function generateIntegration() + { + $integration = $this->integrationService->findByName( + $this->config->getConfigDataValue('analytics/integration_name') + ); + if (!$integration->getId()) { + $integration = $this->integrationService->create($this->getIntegrationData()); + } + return $integration; + } + + /** + * Returns default attributes for MA integration user + * + * @param int $status + * @return array + */ + private function getIntegrationData($status = Integration::STATUS_INACTIVE) + { + $integrationData = [ + 'name' => $this->config->getConfigDataValue('analytics/integration_name'), + 'status' => $status, + 'all_resources' => false, + 'resource' => [ + 'Magento_Analytics::analytics', + 'Magento_Analytics::analytics_api' + ], + ]; + return $integrationData; + } +} diff --git a/app/code/Magento/Analytics/Model/Link.php b/app/code/Magento/Analytics/Model/Link.php new file mode 100644 index 0000000000000..4a40796df4fd0 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Link.php @@ -0,0 +1,54 @@ +url = $url; + $this->initializationVector = $initializationVector; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @return string + */ + public function getInitializationVector() + { + return $this->initializationVector; + } +} diff --git a/app/code/Magento/Analytics/Model/LinkProvider.php b/app/code/Magento/Analytics/Model/LinkProvider.php new file mode 100644 index 0000000000000..2474653f4916c --- /dev/null +++ b/app/code/Magento/Analytics/Model/LinkProvider.php @@ -0,0 +1,87 @@ +linkFactory = $linkFactory; + $this->fileInfoManager = $fileInfoManager; + $this->storeManager = $storeManager; + } + + /** + * Returns base url to file according to store configuration + * + * @param FileInfo $fileInfo + * @return string + */ + private function getBaseUrl(FileInfo $fileInfo) + { + return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . $fileInfo->getPath(); + } + + /** + * Verify is requested file ready + * + * @param FileInfo $fileInfo + * @return bool + */ + private function isFileReady(FileInfo $fileInfo) + { + return $fileInfo->getPath() && $fileInfo->getInitializationVector(); + } + + /** + * @inheritdoc + */ + public function get() + { + $fileInfo = $this->fileInfoManager->load(); + if (!$this->isFileReady($fileInfo)) { + throw new NoSuchEntityException(__('File is not ready yet.')); + } + return $this->linkFactory->create( + [ + 'url' => $this->getBaseUrl($fileInfo), + 'initializationVector' => base64_encode($fileInfo->getInitializationVector()) + ] + ); + } +} diff --git a/app/code/Magento/Analytics/Model/Plugin/BaseUrlConfigPlugin.php b/app/code/Magento/Analytics/Model/Plugin/BaseUrlConfigPlugin.php new file mode 100644 index 0000000000000..174272614fb19 --- /dev/null +++ b/app/code/Magento/Analytics/Model/Plugin/BaseUrlConfigPlugin.php @@ -0,0 +1,61 @@ +subscriptionUpdateHandler = $subscriptionUpdateHandler; + } + + /** + * Add additional handling after config value was saved. + * + * @param Value $subject + * @param Value $result + * @return Value + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterAfterSave( + Value $subject, + Value $result + ) { + if ($this->isPluginApplicable($result)) { + $this->subscriptionUpdateHandler->processUrlUpdate($result->getOldValue()); + } + + return $result; + } + + /** + * @param Value $result + * @return bool + */ + private function isPluginApplicable(Value $result) + { + return $result->isValueChanged() + && ($result->getPath() === Store::XML_PATH_SECURE_BASE_URL) + && ($result->getScope() === ScopeConfigInterface::SCOPE_TYPE_DEFAULT); + } +} diff --git a/app/code/Magento/Analytics/Model/ProviderFactory.php b/app/code/Magento/Analytics/Model/ProviderFactory.php new file mode 100644 index 0000000000000..3a23430fca077 --- /dev/null +++ b/app/code/Magento/Analytics/Model/ProviderFactory.php @@ -0,0 +1,39 @@ +objectManager = $objectManager; + } + + /** + * @param string $providerName + * @return object + */ + public function create($providerName) + { + return $this->objectManager->get($providerName); + } +} diff --git a/app/code/Magento/Analytics/Model/ReportUrlProvider.php b/app/code/Magento/Analytics/Model/ReportUrlProvider.php new file mode 100644 index 0000000000000..e7fdf6f9e8132 --- /dev/null +++ b/app/code/Magento/Analytics/Model/ReportUrlProvider.php @@ -0,0 +1,94 @@ +analyticsToken = $analyticsToken; + $this->otpRequest = $otpRequest; + $this->config = $config; + $this->flagManager = $flagManager; + } + + /** + * Provide URL on resource with reports. + * + * @return string + * @throws SubscriptionUpdateException + */ + public function getUrl() + { + if ($this->flagManager->getFlagData(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE)) { + throw new SubscriptionUpdateException(__( + 'Your Base URL has been changed and your reports are being updated. ' + . 'Advanced Reporting will be available once this change has been processed. Please try again later.' + )); + } + + $url = $this->config->getValue($this->urlReportConfigPath); + if ($this->analyticsToken->isTokenExist()) { + $otp = $this->otpRequest->call(); + if ($otp) { + $query = http_build_query(['otp' => $otp], '', '&'); + $url .= '?' . $query; + } + } + + return $url; + } +} diff --git a/app/code/Magento/Analytics/Model/ReportWriter.php b/app/code/Magento/Analytics/Model/ReportWriter.php new file mode 100644 index 0000000000000..7128658947908 --- /dev/null +++ b/app/code/Magento/Analytics/Model/ReportWriter.php @@ -0,0 +1,101 @@ +config = $config; + $this->reportValidator = $reportValidator; + $this->providerFactory = $providerFactory; + } + + /** + * {@inheritdoc} + */ + public function write(WriteInterface $directory, $path) + { + $errorsList = []; + foreach ($this->config->get() as $file) { + $provider = reset($file['providers']); + if (isset($provider['parameters']['name'])) { + $error = $this->reportValidator->validate($provider['parameters']['name']); + if ($error) { + $errorsList[] = $error; + continue; + } + } + /** @var $providerObject */ + $providerObject = $this->providerFactory->create($provider['class']); + $fileName = $provider['parameters'] ? $provider['parameters']['name'] : $provider['name']; + $fileFullPath = $path . $fileName . '.csv'; + $fileData = $providerObject->getReport(...array_values($provider['parameters'])); + $stream = $directory->openFile($fileFullPath, 'w+'); + $stream->lock(); + $headers = []; + foreach ($fileData as $row) { + if (!$headers) { + $headers = array_keys($row); + $stream->writeCsv($headers); + } + $stream->writeCsv($row); + } + $stream->unlock(); + $stream->close(); + } + if ($errorsList) { + $errorStream = $directory->openFile($path . $this->errorsFileName, 'w+'); + foreach ($errorsList as $error) { + $errorStream->lock(); + $errorStream->writeCsv($error); + $errorStream->unlock(); + } + $errorStream->close(); + } + + return true; + } +} diff --git a/app/code/Magento/Analytics/Model/ReportWriterInterface.php b/app/code/Magento/Analytics/Model/ReportWriterInterface.php new file mode 100644 index 0000000000000..a611095a47ae4 --- /dev/null +++ b/app/code/Magento/Analytics/Model/ReportWriterInterface.php @@ -0,0 +1,28 @@ +moduleManager = $moduleManager; + } + + /** + * Returns module with module status + * + * @return array + */ + public function current() + { + $current = parent::current(); + if (is_array($current) && isset($current['module_name'])) { + $current['status'] = + $this->moduleManager->isEnabled($current['module_name']) == 1 ? 'Enabled' : "Disabled"; + } + return $current; + } +} diff --git a/app/code/Magento/Analytics/Model/StoreConfigurationProvider.php b/app/code/Magento/Analytics/Model/StoreConfigurationProvider.php new file mode 100644 index 0000000000000..0d226a9de7dc2 --- /dev/null +++ b/app/code/Magento/Analytics/Model/StoreConfigurationProvider.php @@ -0,0 +1,102 @@ +scopeConfig = $scopeConfig; + $this->configPaths = $configPaths; + $this->storeManager = $storeManager; + } + + /** + * Generates report using config paths from di.xml + * For each website and store + * @return \IteratorIterator + */ + public function getReport() + { + $configReport = $this->generateReportForScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); + + /** @var WebsiteInterface $website */ + foreach ($this->storeManager->getWebsites() as $website) { + $configReport = array_merge( + $this->generateReportForScope(ScopeInterface::SCOPE_WEBSITES, $website->getId()), + $configReport + ); + } + + /** @var StoreInterface $store */ + foreach ($this->storeManager->getStores() as $store) { + $configReport = array_merge( + $this->generateReportForScope(ScopeInterface::SCOPE_STORES, $store->getId()), + $configReport + ); + } + return new \IteratorIterator(new \ArrayIterator($configReport)); + } + + /** + * Creates report from config for scope type and scope id. + * + * @param string $scope + * @param int $scopeId + * @return array + */ + private function generateReportForScope($scope, $scopeId) + { + $report = []; + foreach ($this->configPaths as $configPath) { + $report[] = [ + "config_path" => $configPath, + "scope" => $scope, + "scope_id" => $scopeId, + "value" => $this->scopeConfig->getValue( + $configPath, + $scope, + $scopeId + ) + ]; + } + return $report; + } +} diff --git a/app/code/Magento/Analytics/Model/SubscriptionStatusProvider.php b/app/code/Magento/Analytics/Model/SubscriptionStatusProvider.php new file mode 100644 index 0000000000000..1dd831a672faa --- /dev/null +++ b/app/code/Magento/Analytics/Model/SubscriptionStatusProvider.php @@ -0,0 +1,120 @@ +scopeConfig = $scopeConfig; + $this->analyticsToken = $analyticsToken; + $this->flagManager = $flagManager; + } + + /** + * Retrieve subscription status to Magento BI Advanced Reporting. + * + * Statuses: + * Enabled - if subscription is enabled and MA token was received; + * Pending - if subscription is enabled and MA token was not received; + * Disabled - if subscription is not enabled. + * Failed - if subscription is enabled and token was not received after attempts ended. + * + * @return string + */ + public function getStatus() + { + $isSubscriptionEnabledInConfig = $this->scopeConfig->getValue('analytics/subscription/enabled'); + if ($isSubscriptionEnabledInConfig) { + return $this->getStatusForEnabledSubscription(); + } + + return $this->getStatusForDisabledSubscription(); + } + + /** + * Retrieve status for subscription that enabled in config. + * + * @return string + */ + public function getStatusForEnabledSubscription() + { + $status = static::ENABLED; + if ($this->flagManager->getFlagData(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE)) { + $status = self::PENDING; + } + + if (!$this->analyticsToken->isTokenExist()) { + $status = static::PENDING; + if ($this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE) === null) { + $status = static::FAILED; + } + } + + return $status; + } + + /** + * Retrieve status for subscription that disabled in config. + * + * @return string + */ + public function getStatusForDisabledSubscription() + { + return static::DISABLED; + } +} diff --git a/app/code/Magento/Analytics/Model/System/Message/NotificationAboutFailedSubscription.php b/app/code/Magento/Analytics/Model/System/Message/NotificationAboutFailedSubscription.php new file mode 100644 index 0000000000000..9aaa2ebb3b56f --- /dev/null +++ b/app/code/Magento/Analytics/Model/System/Message/NotificationAboutFailedSubscription.php @@ -0,0 +1,80 @@ +subscriptionStatusProvider = $subscriptionStatusProvider; + $this->urlBuilder = $urlBuilder; + } + + /** + * @inheritdoc + * + * @codeCoverageIgnore + */ + public function getIdentity() + { + return hash('sha256', 'ANALYTICS_NOTIFICATION'); + } + + /** + * {@inheritdoc} + */ + public function isDisplayed() + { + return $this->subscriptionStatusProvider->getStatus() === SubscriptionStatusProvider::FAILED; + } + + /** + * {@inheritdoc} + */ + public function getText() + { + $messageDetails = ''; + + $messageDetails .= __('Failed to synchronize data to the Magento Business Intelligence service. '); + $messageDetails .= __( + 'Retry Synchronization', + $this->urlBuilder->getUrl('analytics/subscription/retry') + ); + + return $messageDetails; + } + + /** + * @inheritdoc + * + * @codeCoverageIgnore + */ + public function getSeverity() + { + return self::SEVERITY_MAJOR; + } +} diff --git a/app/code/Magento/Analytics/README.md b/app/code/Magento/Analytics/README.md new file mode 100644 index 0000000000000..7ec64abcd9b86 --- /dev/null +++ b/app/code/Magento/Analytics/README.md @@ -0,0 +1,41 @@ +# Magento_Analytics Module + +The Magento_Analytics module integrates your Magento instance with the [Magento Business Intelligence (MBI)](https://magento.com/products/business-intelligence) to use [Advanced Reporting](http://devdocs.magento.com/guides/v2.2/advanced-reporting/modules.html) functionality. + +The module implements the following functionality: + +* enabling subscription to the MBI and automatic re-subscription +* changing the base URL with the same MBI account remained +* declaring the configuration schemas for report data collection +* collecting the Magento instance data as reports for the MBI +* introducing API that provides the collected data +* extending Magento configuration with the module parameters: + * subscription status (enabled/disabled) + * industry (a business area in which the instance website works) + * time of data collection (time of the day when the module collects data) + +## Structure + +Beyond the [usual module file structure](http://devdocs.magento.com/guides/v2.2/architecture/archi_perspectives/components/modules/mod_intro.html) the module contains a directory `ReportXml`. +[Report XML](http://devdocs.magento.com/guides/v2.2/advanced-reporting/report-xml.html) is a markup language used to build reports for Advanced Reporting. +The language declares SQL queries using XML declaration. + +## Subscription Process + +The subscription to the MBI service is enabled during the installation process of the Analytics module. Each administrator will be notified of these new features upon their initial login to the Admin Panel. + +## Analytics Settings + +Configuration settings for the Analytics module can be modified in the Admin Panel on the Stores > Configuration page under the General > Advanced Reporting tab. + +The following options can be adjusted: +* Advanced Reporting Service (Enabled/Disabled) + * Alters the status of the Advanced Reporting subscription +* Time of day to send data (Hour/Minute/Second in the store's time zone) + * Defines when the data collection process for the Advanced Reporting service occurs +* Industry + * Defines the industry of the store in order to create a personalized Advanced Reporting experience + +## Extensibility + +We do not recommend to extend the Magento_Analytics module. It introduces an API that is purposed to transfer the collected data. Note that the API cannot be used for other needs. diff --git a/app/code/Magento/Analytics/ReportXml/Config.php b/app/code/Magento/Analytics/ReportXml/Config.php new file mode 100644 index 0000000000000..f50dcf941bf50 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/Config.php @@ -0,0 +1,43 @@ +data = $data; + } + + /** + * Returns config value by name + * + * @param string $queryName + * @return array + */ + public function get($queryName) + { + return $this->data->get($queryName); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/Config/Converter/Xml.php b/app/code/Magento/Analytics/ReportXml/Config/Converter/Xml.php new file mode 100644 index 0000000000000..9e0b20a6ad414 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/Config/Converter/Xml.php @@ -0,0 +1,61 @@ +hasAttributes()) { + $attrs = $source->attributes; + foreach ($attrs as $attr) { + $result[$attr->name] = $attr->value; + } + } + if ($source->hasChildNodes()) { + $children = $source->childNodes; + if ($children->length == 1) { + $child = $children->item(0); + if ($child->nodeType == XML_TEXT_NODE) { + $result['_value'] = $child->nodeValue; + return count($result) == 1 ? $result['_value'] : $result; + } + } + foreach ($children as $child) { + if ($child instanceof \DOMCharacterData) { + continue; + } + $result[$child->nodeName][] = $this->convertNode($child); + } + } + return $result; + } + + /** + * Converts XML document into corresponding array. + * + * @param \DOMDocument $source + * @return array + */ + public function convert($source) + { + return $this->convertNode($source); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/Config/Mapper.php b/app/code/Magento/Analytics/ReportXml/Config/Mapper.php new file mode 100644 index 0000000000000..4dda8f3c733a6 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/Config/Mapper.php @@ -0,0 +1,37 @@ +readers = $readers; + $this->mapper = $mapper; + } + + /** + * Reads configuration according to the given scope. + * + * @param string|null $scope + * @return array + */ + public function read($scope = null) + { + $data = []; + foreach ($this->readers as $reader) { + $data = array_merge_recursive($data, $reader->read($scope)); + } + return $this->mapper->execute($data); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/ConfigInterface.php b/app/code/Magento/Analytics/ReportXml/ConfigInterface.php new file mode 100644 index 0000000000000..ec03ddf429c06 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/ConfigInterface.php @@ -0,0 +1,23 @@ +resourceConnection = $resourceConnection; + $this->objectManager = $objectManager; + } + + /** + * Creates one-time connection for export + * + * @param string $connectionName + * @return AdapterInterface + */ + public function getConnection($connectionName) + { + $connection = $this->resourceConnection->getConnection($connectionName); + $connectionClassName = get_class($connection); + $configData = $connection->getConfig(); + $configData['use_buffered_query'] = false; + unset($configData['persistent']); + return $this->objectManager->create( + $connectionClassName, + [ + 'config' => $configData + ] + ); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/Assembler/AssemblerInterface.php b/app/code/Magento/Analytics/ReportXml/DB/Assembler/AssemblerInterface.php new file mode 100644 index 0000000000000..083b4843c185a --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/Assembler/AssemblerInterface.php @@ -0,0 +1,27 @@ +conditionResolver = $conditionResolver; + $this->nameResolver = $nameResolver; + } + + /** + * Assembles WHERE conditions + * + * @param SelectBuilder $selectBuilder + * @param array $queryConfig + * @return SelectBuilder + */ + public function assemble(SelectBuilder $selectBuilder, $queryConfig) + { + if (!isset($queryConfig['source']['filter'])) { + return $selectBuilder; + } + $filters = $this->conditionResolver->getFilter( + $selectBuilder, + $queryConfig['source']['filter'], + $this->nameResolver->getAlias($queryConfig['source']) + ); + $selectBuilder->setFilters(array_merge_recursive($selectBuilder->getFilters(), [$filters])); + return $selectBuilder; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/Assembler/FromAssembler.php b/app/code/Magento/Analytics/ReportXml/DB/Assembler/FromAssembler.php new file mode 100644 index 0000000000000..811119ace221b --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/Assembler/FromAssembler.php @@ -0,0 +1,69 @@ +nameResolver = $nameResolver; + $this->columnsResolver = $columnsResolver; + $this->resourceConnection = $resourceConnection; + } + + /** + * Assembles FROM condition + * + * @param SelectBuilder $selectBuilder + * @param array $queryConfig + * @return SelectBuilder + */ + public function assemble(SelectBuilder $selectBuilder, $queryConfig) + { + $selectBuilder->setFrom( + [ + $this->nameResolver->getAlias($queryConfig['source']) => + $this->resourceConnection + ->getTableName($this->nameResolver->getName($queryConfig['source'])), + ] + ); + $columns = $this->columnsResolver->getColumns($selectBuilder, $queryConfig['source']); + $selectBuilder->setColumns(array_merge($selectBuilder->getColumns(), $columns)); + return $selectBuilder; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/Assembler/JoinAssembler.php b/app/code/Magento/Analytics/ReportXml/DB/Assembler/JoinAssembler.php new file mode 100644 index 0000000000000..f3c6540a25171 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/Assembler/JoinAssembler.php @@ -0,0 +1,113 @@ +conditionResolver = $conditionResolver; + $this->nameResolver = $nameResolver; + $this->columnsResolver = $columnsResolver; + $this->resourceConnection = $resourceConnection; + } + + /** + * Assembles JOIN conditions + * + * @param SelectBuilder $selectBuilder + * @param array $queryConfig + * @return SelectBuilder + */ + public function assemble(SelectBuilder $selectBuilder, $queryConfig) + { + if (!isset($queryConfig['source']['link-source'])) { + return $selectBuilder; + } + $joins = []; + $filters = $selectBuilder->getFilters(); + + $sourceAlias = $this->nameResolver->getAlias($queryConfig['source']); + + foreach ($queryConfig['source']['link-source'] as $join) { + $joinAlias = $this->nameResolver->getAlias($join); + + $joins[$joinAlias] = [ + 'link-type' => isset($join['link-type']) ? $join['link-type'] : 'left', + 'table' => [ + $joinAlias => $this->resourceConnection + ->getTableName($this->nameResolver->getName($join)), + ], + 'condition' => $this->conditionResolver->getFilter( + $selectBuilder, + $join['using'], + $joinAlias, + $sourceAlias + ) + ]; + if (isset($join['filter'])) { + $filters = array_merge( + $filters, + [ + $this->conditionResolver->getFilter( + $selectBuilder, + $join['filter'], + $joinAlias, + $sourceAlias + ) + ] + ); + } + $columns = $this->columnsResolver->getColumns($selectBuilder, isset($join['attribute']) ? $join : []); + $selectBuilder->setColumns(array_merge($selectBuilder->getColumns(), $columns)); + } + $selectBuilder->setFilters($filters); + $selectBuilder->setJoins(array_merge($selectBuilder->getJoins(), $joins)); + return $selectBuilder; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/ColumnsResolver.php b/app/code/Magento/Analytics/ReportXml/DB/ColumnsResolver.php new file mode 100644 index 0000000000000..e6474d4c5dc6d --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/ColumnsResolver.php @@ -0,0 +1,100 @@ +nameResolver = $nameResolver; + $this->resourceConnection = $resourceConnection; + } + + /** + * Returns connection + * + * @return \Magento\Framework\DB\Adapter\AdapterInterface + */ + private function getConnection() + { + if (!$this->connection) { + $this->connection = $this->resourceConnection->getConnection(); + } + return $this->connection; + } + + /** + * Set columns list to SelectBuilder + * + * @param SelectBuilder $selectBuilder + * @param array $entityConfig + * @return array + */ + public function getColumns(SelectBuilder $selectBuilder, $entityConfig) + { + if (!isset($entityConfig['attribute'])) { + return []; + } + $group = []; + $columns = $selectBuilder->getColumns(); + foreach ($entityConfig['attribute'] as $attributeData) { + $columnAlias = $this->nameResolver->getAlias($attributeData); + $tableAlias = $this->nameResolver->getAlias($entityConfig); + $columnName = $this->nameResolver->getName($attributeData); + if (isset($attributeData['function'])) { + $prefix = ''; + if (isset($attributeData['distinct']) && $attributeData['distinct'] == true) { + $prefix = ' DISTINCT '; + } + $expression = new ColumnValueExpression( + strtoupper($attributeData['function']) . '(' . $prefix + . $this->getConnection()->quoteIdentifier($tableAlias . '.' . $columnName) + . ')' + ); + } else { + $expression = $tableAlias . '.' . $columnName; + } + $columns[$columnAlias] = $expression; + if (isset($attributeData['group'])) { + $group[$columnAlias] = $expression; + } + } + $selectBuilder->setGroup(array_merge($selectBuilder->getGroup(), $group)); + return $columns; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/ConditionResolver.php b/app/code/Magento/Analytics/ReportXml/DB/ConditionResolver.php new file mode 100644 index 0000000000000..773b96959e794 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/ConditionResolver.php @@ -0,0 +1,166 @@ + '%1$s = %2$s', + 'neq' => '%1$s != %2$s', + 'like' => '%1$s LIKE %2$s', + 'nlike' => '%1$s NOT LIKE %2$s', + 'in' => '%1$s IN(%2$s)', + 'nin' => '%1$s NOT IN(%2$s)', + 'notnull' => '%1$s IS NOT NULL', + 'null' => '%1$s IS NULL', + 'gt' => '%1$s > %2$s', + 'lt' => '%1$s < %2$s', + 'gteq' => '%1$s >= %2$s', + 'lteq' => '%1$s <= %2$s', + 'finset' => 'FIND_IN_SET(%2$s, %1$s)' + ]; + + /** + * @var \Magento\Framework\DB\Adapter\AdapterInterface + */ + private $connection; + + /** + * @var ResourceConnection + */ + private $resourceConnection; + + /** + * ConditionResolver constructor. + * @param ResourceConnection $resourceConnection + */ + public function __construct( + ResourceConnection $resourceConnection + ) { + $this->resourceConnection = $resourceConnection; + } + + /** + * Returns connection + * + * @return \Magento\Framework\DB\Adapter\AdapterInterface + */ + private function getConnection() + { + if (!$this->connection) { + $this->connection = $this->resourceConnection->getConnection(); + } + return $this->connection; + } + + /** + * Returns value for condition + * + * @param string $condition + * @param string $referencedEntity + * @return mixed|null|string|\Zend_Db_Expr + */ + private function getValue($condition, $referencedEntity) + { + $value = null; + $argument = isset($condition['_value']) ? $condition['_value'] : null; + if (!isset($condition['type'])) { + $condition['type'] = 'value'; + } + + switch ($condition['type']) { + case "value": + $value = $this->getConnection()->quote($argument); + break; + case "variable": + $value = new Expression($argument); + break; + case "identifier": + $value = $this->getConnection()->quoteIdentifier( + $referencedEntity ? $referencedEntity . '.' . $argument : $argument + ); + break; + } + return $value; + } + + /** + * Returns condition for WHERE + * + * @param SelectBuilder $selectBuilder + * @param string $tableName + * @param array $condition + * @param null|string $referencedEntity + * @return string + */ + private function getCondition(SelectBuilder $selectBuilder, $tableName, $condition, $referencedEntity = null) + { + $columns = $selectBuilder->getColumns(); + if (isset($columns[$condition['attribute']]) + && $columns[$condition['attribute']] instanceof Expression + ) { + $expression = $columns[$condition['attribute']]; + } else { + $expression = $this->getConnection()->quoteIdentifier($tableName . '.' . $condition['attribute']); + } + return sprintf( + $this->conditionMap[$condition['operator']], + $expression, + $this->getValue($condition, $referencedEntity) + ); + } + + /** + * Build WHERE condition + * + * @param SelectBuilder $selectBuilder + * @param array $filterConfig + * @param string $aliasName + * @param null|string $referencedAlias + * @return array + */ + public function getFilter(SelectBuilder $selectBuilder, $filterConfig, $aliasName, $referencedAlias = null) + { + $filtersParts = []; + foreach ($filterConfig as $filter) { + $glue = $filter['glue']; + $parts = []; + foreach ($filter['condition'] as $condition) { + if (isset($condition['type']) && $condition['type'] == 'variable') { + $selectBuilder->setParams(array_merge($selectBuilder->getParams(), [$condition['_value']])); + } + $parts[] = $this->getCondition( + $selectBuilder, + $aliasName, + $condition, + $referencedAlias + ); + } + if (isset($filter['filter'])) { + $parts[] = '(' . $this->getFilter( + $selectBuilder, + $filter['filter'], + $aliasName, + $referencedAlias + ) . ')'; + } + $filtersParts[] = '(' . implode(' ' . strtoupper($glue) . ' ', $parts) . ')'; + } + return implode(' OR ', $filtersParts); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/NameResolver.php b/app/code/Magento/Analytics/ReportXml/DB/NameResolver.php new file mode 100644 index 0000000000000..c9543002eb272 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/NameResolver.php @@ -0,0 +1,40 @@ +getName($elementConfig); + if (isset($elementConfig['alias'])) { + $alias = $elementConfig['alias']; + } + return $alias; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/ReportValidator.php b/app/code/Magento/Analytics/ReportXml/DB/ReportValidator.php new file mode 100644 index 0000000000000..21a641f0a71c7 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/ReportValidator.php @@ -0,0 +1,64 @@ +connectionFactory = $connectionFactory; + $this->queryFactory = $queryFactory; + } + + /** + * Tries to do query for provided report with limit 0 and return error information if it failed + * + * @param string $name + * @param SearchCriteriaInterface $criteria + * @return array + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function validate($name, SearchCriteriaInterface $criteria = null) + { + $query = $this->queryFactory->create($name); + $connection = $this->connectionFactory->getConnection($query->getConnectionName()); + $query->getSelect()->limit(0); + try { + $connection->query($query->getSelect()); + } catch (\Zend_Db_Statement_Exception $e) { + return [$name, $e->getMessage()]; + } + + return []; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/SelectBuilder.php b/app/code/Magento/Analytics/ReportXml/DB/SelectBuilder.php new file mode 100644 index 0000000000000..4e5a1940773b1 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/SelectBuilder.php @@ -0,0 +1,289 @@ +resourceConnection = $resourceConnection; + } + + /** + * Get join condition + * + * @return array + */ + public function getJoins() + { + return $this->joins; + } + + /** + * Set joins conditions + * + * @param array $joins + * @return void + */ + public function setJoins($joins) + { + $this->joins = $joins; + } + + /** + * Get connection name + * + * @return string + */ + public function getConnectionName() + { + return $this->connectionName; + } + + /** + * Set connection name + * + * @param string $connectionName + * @return void + */ + public function setConnectionName($connectionName) + { + $this->connectionName = $connectionName; + } + + /** + * Get columns + * + * @return array + */ + public function getColumns() + { + return $this->columns; + } + + /** + * Set columns + * + * @param array $columns + * @return void + */ + public function setColumns($columns) + { + $this->columns = $columns; + } + + /** + * Get filters + * + * @return array + */ + public function getFilters() + { + return $this->filters; + } + + /** + * Set filters + * + * @param array $filters + * @return void + */ + public function setFilters($filters) + { + $this->filters = $filters; + } + + /** + * Get from condition + * + * @return array + */ + public function getFrom() + { + return $this->from; + } + + /** + * Set from condition + * + * @param array $from + * @return void + */ + public function setFrom($from) + { + $this->from = $from; + } + + /** + * Process JOIN conditions + * + * @param Select $select + * @param array $joinConfig + * @return Select + */ + private function processJoin(Select $select, $joinConfig) + { + switch ($joinConfig['link-type']) { + case 'left': + $select->joinLeft($joinConfig['table'], $joinConfig['condition'], []); + break; + case 'inner': + $select->joinInner($joinConfig['table'], $joinConfig['condition'], []); + break; + case 'right': + $select->joinRight($joinConfig['table'], $joinConfig['condition'], []); + break; + } + return $select; + } + + /** + * Creates Select object + * + * @return Select + */ + public function create() + { + $connection = $this->resourceConnection->getConnection($this->getConnectionName()); + $select = $connection->select(); + $select->from($this->getFrom(), []); + $select->columns($this->getColumns()); + foreach ($this->getFilters() as $filter) { + $select->where($filter); + } + foreach ($this->getJoins() as $joinConfig) { + $select = $this->processJoin($select, $joinConfig); + } + if (!empty($this->getGroup())) { + $select->group(implode(', ', $this->getGroup())); + } + return $select; + } + + /** + * Returns group + * + * @return array + */ + public function getGroup() + { + return $this->group; + } + + /** + * Set group + * + * @param array $group + * @return void + */ + public function setGroup($group) + { + $this->group = $group; + } + + /** + * Get parameters + * + * @return array + */ + public function getParams() + { + return $this->params; + } + + /** + * Set parameters + * + * @param array $params + * @return void + */ + public function setParams($params) + { + $this->params = $params; + } + + /** + * Get having condition + * + * @return array + */ + public function getHaving() + { + return $this->having; + } + + /** + * Set having condition + * + * @param array $having + * @return void + */ + public function setHaving($having) + { + $this->having = $having; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/DB/SelectBuilderFactory.php b/app/code/Magento/Analytics/ReportXml/DB/SelectBuilderFactory.php new file mode 100644 index 0000000000000..1d88d4618efc5 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/DB/SelectBuilderFactory.php @@ -0,0 +1,43 @@ +objectManager = $objectManager; + } + + /** + * Create class instance with specified parameters + * + * @param array $data + * @return SelectBuilder + */ + public function create(array $data = []) + { + return $this->objectManager->create(SelectBuilder::class, $data); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/IteratorFactory.php b/app/code/Magento/Analytics/ReportXml/IteratorFactory.php new file mode 100644 index 0000000000000..a196cef8b66dc --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/IteratorFactory.php @@ -0,0 +1,61 @@ +objectManager = $objectManager; + $this->defaultIteratorName = $defaultIteratorName; + } + + /** + * Creates instance of the result iterator with the query result as an input + * Result iterator can be changed through report configuration + * + * < ... + * + * Uses IteratorIterator by default + * + * @param \Traversable $result + * @param string|null $iteratorName + * @return \IteratorIterator + */ + public function create(\Traversable $result, $iteratorName = null) + { + return $this->objectManager->create( + $iteratorName ?: $this->defaultIteratorName, + [ + 'iterator' => $result + ] + ); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/Query.php b/app/code/Magento/Analytics/ReportXml/Query.php new file mode 100644 index 0000000000000..46ec2fb494183 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/Query.php @@ -0,0 +1,96 @@ +select = $select; + $this->connectionName = $connectionName; + $this->selectHydrator = $selectHydrator; + $this->config = $config; + } + + /** + * @return Select + */ + public function getSelect() + { + return $this->select; + } + + /** + * @return string + */ + public function getConnectionName() + { + return $this->connectionName; + } + + /** + * @return array + */ + public function getConfig() + { + return $this->config; + } + + /** + * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + public function jsonSerialize() + { + return [ + 'connectionName' => $this->getConnectionName(), + 'select_parts' => $this->selectHydrator->extract($this->getSelect()), + 'config' => $this->getConfig() + ]; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/QueryFactory.php b/app/code/Magento/Analytics/ReportXml/QueryFactory.php new file mode 100644 index 0000000000000..8ed7e767b28b3 --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/QueryFactory.php @@ -0,0 +1,142 @@ +config = $config; + $this->selectBuilderFactory = $selectBuilderFactory; + $this->assemblers = $assemblers; + $this->queryCache = $queryCache; + $this->objectManager = $objectManager; + $this->selectHydrator = $selectHydrator; + } + + /** + * Returns query connection name according to configuration + * + * @param string $queryConfig + * @return string + */ + private function getQueryConnectionName($queryConfig) + { + $connectionName = 'default'; + if (isset($queryConfig['connection'])) { + $connectionName = $queryConfig['connection']; + } + return $connectionName; + } + + /** + * Create query according to configuration settings + * + * @param string $queryName + * @return Query + */ + private function constructQuery($queryName) + { + $queryConfig = $this->config->get($queryName); + $selectBuilder = $this->selectBuilderFactory->create(); + $selectBuilder->setConnectionName($this->getQueryConnectionName($queryConfig)); + foreach ($this->assemblers as $assembler) { + $selectBuilder = $assembler->assemble($selectBuilder, $queryConfig); + } + $select = $selectBuilder->create(); + return $this->objectManager->create( + Query::class, + [ + 'select' => $select, + 'selectHydrator' => $this->selectHydrator, + 'connectionName' => $selectBuilder->getConnectionName(), + 'config' => $queryConfig + ] + ); + } + + /** + * Creates query by name + * + * @param string $queryName + * @return Query + */ + public function create($queryName) + { + $cached = $this->queryCache->load($queryName); + if ($cached) { + $queryData = json_decode($cached, true); + return $this->objectManager->create( + Query::class, + [ + 'select' => $this->selectHydrator->recreate($queryData['select_parts']), + 'selectHydrator' => $this->selectHydrator, + 'connectionName' => $queryData['connectionName'], + 'config' => $queryData['config'] + ] + ); + } + $query = $this->constructQuery($queryName); + $this->queryCache->save(json_encode($query), $queryName); + return $query; + } +} diff --git a/app/code/Magento/Analytics/ReportXml/ReportProvider.php b/app/code/Magento/Analytics/ReportXml/ReportProvider.php new file mode 100644 index 0000000000000..3ebe5941108bc --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/ReportProvider.php @@ -0,0 +1,76 @@ +queryFactory = $queryFactory; + $this->connectionFactory = $connectionFactory; + $this->iteratorFactory = $iteratorFactory; + } + + /** + * Returns custom iterator name for report + * Null for default + * + * @param Query $query + * @return string|null + */ + private function getIteratorName(Query $query) + { + $config = $query->getConfig(); + return isset($config['iterator']) ? $config['iterator'] : null; + } + + /** + * Returns report data by name and criteria + * + * @param string $name + * @return \IteratorIterator + */ + public function getReport($name) + { + $query = $this->queryFactory->create($name); + $connection = $this->connectionFactory->getConnection($query->getConnectionName()); + $statement = $connection->query($query->getSelect()); + return $this->iteratorFactory->create($statement, $this->getIteratorName($query)); + } +} diff --git a/app/code/Magento/Analytics/ReportXml/SelectHydrator.php b/app/code/Magento/Analytics/ReportXml/SelectHydrator.php new file mode 100644 index 0000000000000..02cde2fd0598d --- /dev/null +++ b/app/code/Magento/Analytics/ReportXml/SelectHydrator.php @@ -0,0 +1,143 @@ +resourceConnection = $resourceConnection; + $this->objectManager = $objectManager; + $this->selectParts = $selectParts; + } + + /** + * @return array + */ + private function getSelectParts() + { + return array_merge($this->predefinedSelectParts, $this->selectParts); + } + + /** + * Extracts Select metadata parts + * + * @param Select $select + * @return array + * @throws \Zend_Db_Select_Exception + */ + public function extract(Select $select) + { + $parts = []; + foreach ($this->getSelectParts() as $partName) { + $parts[$partName] = $select->getPart($partName); + } + return $parts; + } + + /** + * @param array $selectParts + * @return Select + */ + public function recreate(array $selectParts) + { + $select = $this->resourceConnection->getConnection()->select(); + + $select = $this->processColumns($select, $selectParts); + + foreach ($selectParts as $partName => $partValue) { + $select->setPart($partName, $partValue); + } + + return $select; + } + + /** + * Process COLUMNS part values and add this part into select. + * + * If each column contains information about select expression + * an object with the type of this expression going to be created and assigned to this column. + * + * @param Select $select + * @param array $selectParts + * @return Select + */ + private function processColumns(Select $select, array &$selectParts) + { + if (!empty($selectParts[Select::COLUMNS]) && is_array($selectParts[Select::COLUMNS])) { + $part = []; + + foreach ($selectParts[Select::COLUMNS] as $columnEntry) { + list($correlationName, $column, $alias) = $columnEntry; + if (is_array($column) && !empty($column['class'])) { + $expression = $this->objectManager->create( + $column['class'], + isset($column['arguments']) ? $column['arguments'] : [] + ); + $part[] = [$correlationName, $expression, $alias]; + } else { + $part[] = $columnEntry; + } + } + + $select->setPart(Select::COLUMNS, $part); + unset($selectParts[Select::COLUMNS]); + } + + return $select; + } +} diff --git a/app/code/Magento/Analytics/Setup/InstallData.php b/app/code/Magento/Analytics/Setup/InstallData.php new file mode 100644 index 0000000000000..aaa619bbb0caa --- /dev/null +++ b/app/code/Magento/Analytics/Setup/InstallData.php @@ -0,0 +1,53 @@ +getConnection()->insertMultiple( + $setup->getTable('core_config_data'), + [ + [ + 'scope' => 'default', + 'scope_id' => 0, + 'path' => 'analytics/subscription/enabled', + 'value' => 1 + ], + [ + 'scope' => 'default', + 'scope_id' => 0, + 'path' => SubscriptionHandler::CRON_STRING_PATH, + 'value' => join(' ', SubscriptionHandler::CRON_EXPR_ARRAY) + ] + ] + ); + + $setup->getConnection()->insert( + $setup->getTable('flag'), + [ + 'flag_code' => SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, + 'state' => 0, + 'flag_data' => 24, + ] + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/AdditionalCommentTest.php b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/AdditionalCommentTest.php new file mode 100644 index 0000000000000..cbf06264096ac --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/AdditionalCommentTest.php @@ -0,0 +1,77 @@ +abstractElementMock = $this->getMockBuilder(AbstractElement::class) + ->setMethods(['getComment', 'getLabel']) + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->getMock(); + $this->formMock = $this->getMockBuilder(Form::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new ObjectManager($this); + $this->additionalComment = $objectManager->getObject( + AdditionalComment::class, + [ + 'context' => $this->contextMock + ] + ); + } + + public function testRender() + { + $this->abstractElementMock->setForm($this->formMock); + $this->abstractElementMock->expects($this->any()) + ->method('getComment') + ->willReturn('New comment'); + $this->abstractElementMock->expects($this->any()) + ->method('getLabel') + ->willReturn('Comment label'); + $html = $this->additionalComment->render($this->abstractElementMock); + $this->assertRegexp( + "/New comment/", + $html + ); + $this->assertRegexp( + "/Comment label/", + $html + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php new file mode 100644 index 0000000000000..a652cf6b3d548 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/CollectionTimeLabelTest.php @@ -0,0 +1,81 @@ +abstractElementMock = $this->getMockBuilder(AbstractElement::class) + ->setMethods(['getComment']) + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock = $this->getMockBuilder(Context::class) + ->setMethods(['getLocaleDate']) + ->disableOriginalConstructor() + ->getMock(); + $this->formMock = $this->getMockBuilder(Form::class) + ->disableOriginalConstructor() + ->getMock(); + $this->timeZoneMock = $this->getMockBuilder(TimezoneInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock->expects($this->any()) + ->method('getLocaleDate') + ->willReturn($this->timeZoneMock); + + $objectManager = new ObjectManager($this); + $this->collectionTimeLabel = $objectManager->getObject( + CollectionTimeLabel::class, + [ + 'context' => $this->contextMock + ] + ); + } + + public function testRender() + { + $timeZone = "America/New_York"; + $this->abstractElementMock->setForm($this->formMock); + $this->timeZoneMock->expects($this->once()) + ->method('getConfigTimezone') + ->willReturn($timeZone); + $this->abstractElementMock->expects($this->any()) + ->method('getComment') + ->willReturn('Eastern Standard Time (America/New_York)'); + $this->assertRegexp( + "/Eastern Standard Time \(America\/New_York\)/", + $this->collectionTimeLabel->render($this->abstractElementMock) + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/SubscriptionStatusLabelTest.php b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/SubscriptionStatusLabelTest.php new file mode 100644 index 0000000000000..09e753e4ac8aa --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/SubscriptionStatusLabelTest.php @@ -0,0 +1,85 @@ +subscriptionStatusProviderMock = $this->getMockBuilder(SubscriptionStatusProvider::class) + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->getMock(); + $this->abstractElementMock = $this->getMockBuilder(AbstractElement::class) + ->setMethods(['getComment']) + ->disableOriginalConstructor() + ->getMock(); + $this->formMock = $this->getMockBuilder(Form::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new ObjectManager($this); + $this->subscriptionStatusLabel = $objectManager->getObject( + SubscriptionStatusLabel::class, + [ + 'context' => $this->contextMock, + 'subscriptionStatusProvider' => $this->subscriptionStatusProviderMock + ] + ); + } + + public function testRender() + { + $this->abstractElementMock->setForm($this->formMock); + $this->subscriptionStatusProviderMock->expects($this->once()) + ->method('getStatus') + ->willReturn('Enabled'); + $this->abstractElementMock->expects($this->any()) + ->method('getComment') + ->willReturn('Subscription status: Enabled'); + $this->assertRegexp( + "/Subscription status: Enabled/", + $this->subscriptionStatusLabel->render($this->abstractElementMock) + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/VerticalTest.php b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/VerticalTest.php new file mode 100644 index 0000000000000..abce48c36c86a --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Block/Adminhtml/System/Config/VerticalTest.php @@ -0,0 +1,77 @@ +abstractElementMock = $this->getMockBuilder(AbstractElement::class) + ->setMethods(['getComment', 'getLabel', 'getHint']) + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->getMock(); + $this->formMock = $this->getMockBuilder(Form::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new ObjectManager($this); + $this->vertical = $objectManager->getObject( + Vertical::class, + [ + 'context' => $this->contextMock + ] + ); + } + + public function testRender() + { + $this->abstractElementMock->setForm($this->formMock); + $this->abstractElementMock->expects($this->any()) + ->method('getComment') + ->willReturn('New comment'); + $this->abstractElementMock->expects($this->any()) + ->method('getHint') + ->willReturn('New hint'); + $html = $this->vertical->render($this->abstractElementMock); + $this->assertRegexp( + "/New comment/", + $html + ); + $this->assertRegExp( + "/New hint/", + $html + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/BIEssentials/SignUpTest.php b/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/BIEssentials/SignUpTest.php new file mode 100644 index 0000000000000..6f613cdc4d639 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/BIEssentials/SignUpTest.php @@ -0,0 +1,84 @@ +configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder(RedirectFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->redirectMock = $this->getMockBuilder(Redirect::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->signUpController = $this->objectManagerHelper->getObject( + SignUp::class, + [ + 'config' => $this->configMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock + ] + ); + } + + /** + * @return void + */ + public function testExecute() + { + $urlBIEssentialsConfigPath = 'analytics/url/bi_essentials'; + $this->configMock->expects($this->once()) + ->method('getValue') + ->with($urlBIEssentialsConfigPath) + ->willReturn('value'); + $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->redirectMock); + $this->redirectMock->expects($this->once())->method('setUrl')->with('value')->willReturnSelf(); + $this->assertEquals($this->redirectMock, $this->signUpController->execute()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/Reports/ShowTest.php b/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/Reports/ShowTest.php new file mode 100644 index 0000000000000..4f54ce5059965 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/Reports/ShowTest.php @@ -0,0 +1,185 @@ +reportUrlProviderMock = $this->getMockBuilder(ReportUrlProvider::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->redirectMock = $this->getMockBuilder(Redirect::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->showController = $this->objectManagerHelper->getObject( + Show::class, + [ + 'reportUrlProvider' => $this->reportUrlProviderMock, + 'resultFactory' => $this->resultFactoryMock, + 'messageManager' => $this->messageManagerMock, + ] + ); + } + + /** + * @return void + */ + public function testExecute() + { + $otpUrl = 'http://example.com?otp=15vbjcfdvd15645'; + + $this->resultFactoryMock + ->expects($this->once()) + ->method('create') + ->with(ResultFactory::TYPE_REDIRECT) + ->willReturn($this->redirectMock); + $this->reportUrlProviderMock + ->expects($this->once()) + ->method('getUrl') + ->with() + ->willReturn($otpUrl); + $this->redirectMock + ->expects($this->once()) + ->method('setUrl') + ->with($otpUrl) + ->willReturnSelf(); + $this->assertSame($this->redirectMock, $this->showController->execute()); + } + + /** + * @dataProvider executeWithExceptionDataProvider + * + * @param \Exception $exception + */ + public function testExecuteWithException(\Exception $exception) + { + + $this->resultFactoryMock + ->expects($this->once()) + ->method('create') + ->with(ResultFactory::TYPE_REDIRECT) + ->willReturn($this->redirectMock); + $this->reportUrlProviderMock + ->expects($this->once()) + ->method('getUrl') + ->with() + ->willThrowException($exception); + if ($exception instanceof LocalizedException) { + $message = $exception->getMessage(); + } else { + $message = __('Sorry, there has been an error processing your request. Please try again later.'); + } + $this->messageManagerMock + ->expects($this->once()) + ->method('addExceptionMessage') + ->with($exception, $message) + ->willReturnSelf(); + $this->redirectMock + ->expects($this->once()) + ->method('setPath') + ->with('adminhtml') + ->willReturnSelf(); + $this->assertSame($this->redirectMock, $this->showController->execute()); + } + + /** + * @return array + */ + public function executeWithExceptionDataProvider() + { + return [ + 'ExecuteWithLocalizedException' => [new LocalizedException(__('TestMessage'))], + 'ExecuteWithException' => [new \Exception('TestMessage')], + ]; + } + + /** + * @return void + */ + public function testExecuteWithSubscriptionUpdateException() + { + $exception = new SubscriptionUpdateException(__('TestMessage')); + $this->resultFactoryMock + ->expects($this->once()) + ->method('create') + ->with(ResultFactory::TYPE_REDIRECT) + ->willReturn($this->redirectMock); + $this->reportUrlProviderMock + ->expects($this->once()) + ->method('getUrl') + ->with() + ->willThrowException($exception); + $this->messageManagerMock + ->expects($this->once()) + ->method('addNoticeMessage') + ->with($exception->getMessage()) + ->willReturnSelf(); + $this->redirectMock + ->expects($this->once()) + ->method('setPath') + ->with('adminhtml') + ->willReturnSelf(); + $this->assertSame($this->redirectMock, $this->showController->execute()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/Subscription/RetryTest.php b/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/Subscription/RetryTest.php new file mode 100644 index 0000000000000..17c485a8df230 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Controller/Adminhtml/Subscription/RetryTest.php @@ -0,0 +1,159 @@ +resultFactoryMock = $this->getMockBuilder(ResultFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->resultRedirectMock = $this->getMockBuilder(Redirect::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->subscriptionHandlerMock = $this->getMockBuilder(SubscriptionHandler::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->retryController = $this->objectManagerHelper->getObject( + Retry::class, + [ + 'resultFactory' => $this->resultFactoryMock, + 'subscriptionHandler' => $this->subscriptionHandlerMock, + 'messageManager' => $this->messageManagerMock, + ] + ); + } + + /** + * @return void + */ + public function testExecute() + { + $this->resultFactoryMock + ->expects($this->once()) + ->method('create') + ->with(ResultFactory::TYPE_REDIRECT) + ->willReturn($this->resultRedirectMock); + $this->resultRedirectMock + ->expects($this->once()) + ->method('setPath') + ->with('adminhtml') + ->willReturnSelf(); + $this->subscriptionHandlerMock + ->expects($this->once()) + ->method('processEnabled') + ->with() + ->willReturn(true); + $this->assertSame( + $this->resultRedirectMock, + $this->retryController->execute() + ); + } + + /** + * @dataProvider executeExceptionsDataProvider + * + * @param \Exception $exception + * @param Phrase $message + */ + public function testExecuteWithException(\Exception $exception, Phrase $message) + { + $this->resultFactoryMock + ->expects($this->once()) + ->method('create') + ->with(ResultFactory::TYPE_REDIRECT) + ->willReturn($this->resultRedirectMock); + $this->resultRedirectMock + ->expects($this->once()) + ->method('setPath') + ->with('adminhtml') + ->willReturnSelf(); + $this->subscriptionHandlerMock + ->expects($this->once()) + ->method('processEnabled') + ->with() + ->willThrowException($exception); + $this->messageManagerMock + ->expects($this->once()) + ->method('addExceptionMessage') + ->with($exception, $message); + + $this->assertSame( + $this->resultRedirectMock, + $this->retryController->execute() + ); + } + + /** + * @return array + */ + public function executeExceptionsDataProvider() + { + return [ + [new LocalizedException(__('TestMessage')), __('TestMessage')], + [ + new \Exception('TestMessage'), + __('Sorry, there has been an error processing your request. Please try again later.') + ], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Cron/CollectDataTest.php b/app/code/Magento/Analytics/Test/Unit/Cron/CollectDataTest.php new file mode 100644 index 0000000000000..81c57d79033c8 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Cron/CollectDataTest.php @@ -0,0 +1,91 @@ +exportDataHandlerMock = $this->getMockBuilder(ExportDataHandlerInterface::class) + ->getMockForAbstractClass(); + + $this->subscriptionStatusMock = $this->getMockBuilder(SubscriptionStatusProvider::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->collectData = $this->objectManagerHelper->getObject( + CollectData::class, + [ + 'exportDataHandler' => $this->exportDataHandlerMock, + 'subscriptionStatus' => $this->subscriptionStatusMock, + ] + ); + } + + /** + * @param string $status + * @return void + * @dataProvider executeDataProvider + */ + public function testExecute($status) + { + $this->subscriptionStatusMock + ->expects($this->once()) + ->method('getStatus') + ->with() + ->willReturn($status); + $this->exportDataHandlerMock + ->expects(($status === SubscriptionStatusProvider::ENABLED) ? $this->once() : $this->never()) + ->method('prepareExportData') + ->with(); + + $this->assertTrue($this->collectData->execute()); + } + + /** + * @return array + */ + public function executeDataProvider() + { + return [ + 'Subscription is enabled' => [SubscriptionStatusProvider::ENABLED], + 'Subscription is disabled' => [SubscriptionStatusProvider::DISABLED], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Cron/SignUpTest.php b/app/code/Magento/Analytics/Test/Unit/Cron/SignUpTest.php new file mode 100644 index 0000000000000..959a11f9e1058 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Cron/SignUpTest.php @@ -0,0 +1,133 @@ +connectorMock = $this->getMockBuilder(Connector::class) + ->disableOriginalConstructor() + ->getMock(); + $this->configWriterMock = $this->getMockBuilder(WriterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->reinitableConfigMock = $this->getMockBuilder(ReinitableConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->signUp = new SignUp( + $this->connectorMock, + $this->configWriterMock, + $this->flagManagerMock, + $this->reinitableConfigMock + ); + } + + public function testExecute() + { + $attemptsCount = 10; + + $this->flagManagerMock->expects($this->once()) + ->method('getFlagData') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE) + ->willReturn($attemptsCount); + + $attemptsCount -= 1; + $this->flagManagerMock->expects($this->once()) + ->method('saveFlag') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, $attemptsCount); + $this->connectorMock->expects($this->once()) + ->method('execute') + ->with('signUp') + ->willReturn(true); + $this->addDeleteAnalyticsCronExprAsserts(); + $this->flagManagerMock->expects($this->once()) + ->method('deleteFlag') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); + $this->assertTrue($this->signUp->execute()); + } + + public function testExecuteFlagNotExist() + { + $this->flagManagerMock->expects($this->once()) + ->method('getFlagData') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE) + ->willReturn(null); + $this->addDeleteAnalyticsCronExprAsserts(); + $this->assertFalse($this->signUp->execute()); + } + + public function testExecuteZeroAttempts() + { + $attemptsCount = 0; + $this->flagManagerMock->expects($this->once()) + ->method('getFlagData') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE) + ->willReturn($attemptsCount); + $this->addDeleteAnalyticsCronExprAsserts(); + $this->flagManagerMock->expects($this->once()) + ->method('deleteFlag') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE); + $this->assertFalse($this->signUp->execute()); + } + + /** + * Add assertions for method deleteAnalyticsCronExpr. + * + * @return void + */ + private function addDeleteAnalyticsCronExprAsserts() + { + $this->configWriterMock + ->expects($this->once()) + ->method('delete') + ->with(SubscriptionHandler::CRON_STRING_PATH) + ->willReturn(true); + $this->reinitableConfigMock + ->expects($this->once()) + ->method('reinit') + ->willReturnSelf(); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php b/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php new file mode 100644 index 0000000000000..ede53d8783a7a --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php @@ -0,0 +1,214 @@ +connectorMock = $this->getMockBuilder(Connector::class) + ->disableOriginalConstructor() + ->getMock(); + $this->configWriterMock = $this->getMockBuilder(WriterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->reinitableConfigMock = $this->getMockBuilder(ReinitableConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->update = new Update( + $this->connectorMock, + $this->configWriterMock, + $this->reinitableConfigMock, + $this->flagManagerMock, + $this->analyticsTokenMock + ); + } + + /** + * @return void + */ + public function testExecuteWithoutToken() + { + $this->flagManagerMock + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE) + ->willReturn(10); + $this->connectorMock + ->expects($this->once()) + ->method('execute') + ->with('update') + ->willReturn(false); + $this->analyticsTokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->willReturn(false); + $this->addFinalOutputAsserts(); + $this->assertFalse($this->update->execute()); + } + + /** + * @param bool $isExecuted + */ + private function addFinalOutputAsserts(bool $isExecuted = true) + { + $this->flagManagerMock + ->expects($this->exactly(2 * $isExecuted)) + ->method('deleteFlag') + ->withConsecutive( + [SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE], + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE] + ); + $this->configWriterMock + ->expects($this->exactly((int)$isExecuted)) + ->method('delete') + ->with(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH); + $this->reinitableConfigMock + ->expects($this->exactly((int)$isExecuted)) + ->method('reinit') + ->with(); + } + + /** + * @param $counterData + * @return void + * @dataProvider executeWithEmptyReverseCounterDataProvider + */ + public function testExecuteWithEmptyReverseCounter($counterData) + { + $this->flagManagerMock + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE) + ->willReturn($counterData); + $this->connectorMock + ->expects($this->never()) + ->method('execute') + ->with('update') + ->willReturn(false); + $this->analyticsTokenMock + ->method('isTokenExist') + ->willReturn(true); + $this->addFinalOutputAsserts(); + $this->assertFalse($this->update->execute()); + } + + /** + * Provides empty states of the reverse counter. + * + * @return array + */ + public function executeWithEmptyReverseCounterDataProvider() + { + return [ + [null], + [0] + ]; + } + + /** + * @param int $reverseCount + * @param bool $commandResult + * @param bool $finalConditionsIsExpected + * @param bool $functionResult + * @return void + * @dataProvider executeRegularScenarioDataProvider + */ + public function testExecuteRegularScenario( + int $reverseCount, + bool $commandResult, + bool $finalConditionsIsExpected, + bool $functionResult + ) { + $this->flagManagerMock + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE) + ->willReturn($reverseCount); + $this->connectorMock + ->expects($this->once()) + ->method('execute') + ->with('update') + ->willReturn($commandResult); + $this->analyticsTokenMock + ->method('isTokenExist') + ->willReturn(true); + $this->addFinalOutputAsserts($finalConditionsIsExpected); + $this->assertSame($functionResult, $this->update->execute()); + } + + /** + * @return array + */ + public function executeRegularScenarioDataProvider() + { + return [ + 'The last attempt with command execution result False' => [ + 'Reverse count' => 1, + 'Command result' => false, + 'Executed final output conditions' => true, + 'Function result' => false, + ], + 'Not the last attempt with command execution result False' => [ + 'Reverse count' => 10, + 'Command result' => false, + 'Executed final output conditions' => false, + 'Function result' => false, + ], + 'Command execution result True' => [ + 'Reverse count' => 10, + 'Command result' => true, + 'Executed final output conditions' => true, + 'Function result' => true, + ], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/AnalyticsTokenTest.php b/app/code/Magento/Analytics/Test/Unit/Model/AnalyticsTokenTest.php new file mode 100644 index 0000000000000..57315543bc32d --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/AnalyticsTokenTest.php @@ -0,0 +1,129 @@ +reinitableConfigMock = $this->getMockBuilder(ReinitableConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configWriterMock = $this->getMockBuilder(WriterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->tokenModel = $this->objectManagerHelper->getObject( + AnalyticsToken::class, + [ + 'reinitableConfig' => $this->reinitableConfigMock, + 'config' => $this->configMock, + 'configWriter' => $this->configWriterMock, + 'tokenPath' => $this->tokenPath, + ] + ); + } + + /** + * @return void + */ + public function testStoreToken() + { + $value = 'jjjj0000'; + + $this->configWriterMock + ->expects($this->once()) + ->method('save') + ->with($this->tokenPath, $value); + + $this->reinitableConfigMock + ->expects($this->once()) + ->method('reinit') + ->willReturnSelf(); + + $this->assertTrue($this->tokenModel->storeToken($value)); + } + + /** + * @return void + */ + public function testGetToken() + { + $value = 'jjjj0000'; + + $this->configMock + ->expects($this->once()) + ->method('getValue') + ->with($this->tokenPath) + ->willReturn($value); + + $this->assertSame($value, $this->tokenModel->getToken()); + } + + /** + * @return void + */ + public function testIsTokenExist() + { + $this->assertFalse($this->tokenModel->isTokenExist()); + + $this->configMock + ->expects($this->once()) + ->method('getValue') + ->with($this->tokenPath) + ->willReturn('0000'); + $this->assertTrue($this->tokenModel->isTokenExist()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/Baseurl/SubscriptionUpdateHandlerTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/Baseurl/SubscriptionUpdateHandlerTest.php new file mode 100644 index 0000000000000..f5f721c038c57 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/Baseurl/SubscriptionUpdateHandlerTest.php @@ -0,0 +1,178 @@ +reinitableConfigMock = $this->getMockBuilder(ReinitableConfigInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configWriterMock = $this->getMockBuilder(WriterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->subscriptionUpdateHandler = $this->objectManagerHelper->getObject( + SubscriptionUpdateHandler::class, + [ + 'reinitableConfig' => $this->reinitableConfigMock, + 'analyticsToken' => $this->analyticsTokenMock, + 'flagManager' => $this->flagManagerMock, + 'configWriter' => $this->configWriterMock, + ] + ); + } + + /** + * @return void + */ + public function testTokenDoesNotExist() + { + $this->analyticsTokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->with() + ->willReturn(false); + $this->flagManagerMock + ->expects($this->never()) + ->method('saveFlag'); + $this->configWriterMock + ->expects($this->never()) + ->method('save'); + $this->assertTrue($this->subscriptionUpdateHandler->processUrlUpdate('http://store.com')); + } + + /** + * @return void + */ + public function testTokenAndPreviousBaseUrlExist() + { + $url = 'https://store.com'; + $this->analyticsTokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->with() + ->willReturn(true); + $this->flagManagerMock + ->expects($this->once()) + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE) + ->willReturn(true); + $this->flagManagerMock + ->expects($this->once()) + ->method('saveFlag') + ->withConsecutive( + [SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue], + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, $url] + ); + $this->configWriterMock + ->expects($this->once()) + ->method('save') + ->with(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH, $this->cronExpression); + $this->reinitableConfigMock + ->expects($this->once()) + ->method('reinit') + ->with(); + $this->assertTrue($this->subscriptionUpdateHandler->processUrlUpdate($url)); + } + + /** + * @return void + */ + public function testTokenExistAndWithoutPreviousBaseUrl() + { + $url = 'https://store.com'; + $this->analyticsTokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->with() + ->willReturn(true); + $this->flagManagerMock + ->expects($this->once()) + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE) + ->willReturn(false); + $this->flagManagerMock + ->expects($this->exactly(2)) + ->method('saveFlag') + ->withConsecutive( + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, $url], + [SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue] + ); + $this->configWriterMock + ->expects($this->once()) + ->method('save') + ->with(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH, $this->cronExpression); + $this->reinitableConfigMock + ->expects($this->once()) + ->method('reinit') + ->with(); + $this->assertTrue($this->subscriptionUpdateHandler->processUrlUpdate($url)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/CollectionTimeTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/CollectionTimeTest.php new file mode 100644 index 0000000000000..071b96111ac8b --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/CollectionTimeTest.php @@ -0,0 +1,111 @@ +configWriterMock = $this->getMockBuilder(WriterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->collectionTime = $this->objectManagerHelper->getObject( + CollectionTime::class, + [ + 'configWriter' => $this->configWriterMock, + '_logger' => $this->loggerMock, + ] + ); + } + + /** + * @return void + */ + public function testAfterSave() + { + $this->collectionTime->setData('value', '05,04,03'); + + $this->configWriterMock + ->expects($this->once()) + ->method('save') + ->with(CollectionTime::CRON_SCHEDULE_PATH, join(' ', ['04', '05', '*', '*', '*'])); + + $this->assertInstanceOf( + Value::class, + $this->collectionTime->afterSave() + ); + } + + /** + * @return void + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testAfterSaveWrongValue() + { + $this->collectionTime->setData('value', '00,01'); + $this->collectionTime->afterSave(); + } + + /** + * @return void + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testAfterSaveWithLocalizedException() + { + $exception = new \Exception('Test message'); + $this->collectionTime->setData('value', '05,04,03'); + + $this->configWriterMock + ->expects($this->once()) + ->method('save') + ->with(CollectionTime::CRON_SCHEDULE_PATH, join(' ', ['04', '05', '*', '*', '*'])) + ->willThrowException($exception); + $this->loggerMock + ->expects($this->once()) + ->method('error') + ->with($exception->getMessage()); + $this->collectionTime->afterSave(); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/Enabled/SubscriptionHandlerTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/Enabled/SubscriptionHandlerTest.php new file mode 100644 index 0000000000000..82aa4dc72dfe0 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/Enabled/SubscriptionHandlerTest.php @@ -0,0 +1,152 @@ +flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configWriterMock = $this->getMockBuilder(WriterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->tokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->subscriptionHandler = $this->objectManagerHelper->getObject( + SubscriptionHandler::class, + [ + 'flagManager' => $this->flagManagerMock, + 'configWriter' => $this->configWriterMock, + 'attemptsInitValue' => $this->attemptsInitValue, + 'analyticsToken' => $this->tokenMock, + ] + ); + } + + public function testProcessEnabledTokenExist() + { + $this->tokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->willReturn(true); + $this->configWriterMock + ->expects($this->never()) + ->method('save'); + $this->flagManagerMock + ->expects($this->never()) + ->method('saveFlag'); + $this->assertTrue( + $this->subscriptionHandler->processEnabled() + ); + } + + public function testProcessEnabledTokenDoesNotExist() + { + $this->tokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->willReturn(false); + $this->configWriterMock + ->expects($this->once()) + ->method('save') + ->with(SubscriptionHandler::CRON_STRING_PATH, "0 * * * *"); + $this->flagManagerMock + ->expects($this->once()) + ->method('saveFlag') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, $this->attemptsInitValue) + ->willReturn(true); + $this->assertTrue( + $this->subscriptionHandler->processEnabled() + ); + } + + public function testProcessDisabledTokenDoesNotExist() + { + $this->configWriterMock + ->expects($this->once()) + ->method('delete') + ->with(CollectionTime::CRON_SCHEDULE_PATH); + $this->tokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->willReturn(false); + $this->flagManagerMock + ->expects($this->once()) + ->method('deleteFlag') + ->with(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE) + ->willReturn(true); + $this->assertTrue( + $this->subscriptionHandler->processDisabled() + ); + } + + public function testProcessDisabledTokenExists() + { + $this->configWriterMock + ->expects($this->once()) + ->method('delete') + ->with(CollectionTime::CRON_SCHEDULE_PATH); + $this->tokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->willReturn(true); + $this->flagManagerMock + ->expects($this->never()) + ->method('deleteFlag'); + $this->assertTrue( + $this->subscriptionHandler->processDisabled() + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/EnabledTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/EnabledTest.php new file mode 100644 index 0000000000000..eea3193258bc6 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/EnabledTest.php @@ -0,0 +1,184 @@ +subscriptionHandlerMock = $this->getMockBuilder(SubscriptionHandler::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->enabledModel = $this->objectManagerHelper->getObject( + Enabled::class, + [ + 'subscriptionHandler' => $this->subscriptionHandlerMock, + '_logger' => $this->loggerMock, + 'config' => $this->configMock, + ] + ); + } + + /** + * @return void + */ + public function testAfterSaveSuccessEnabled() + { + $this->enabledModel->setData('value', $this->valueEnabled); + + $this->configMock + ->expects($this->any()) + ->method('getValue') + ->willReturn(!$this->valueEnabled); + + $this->subscriptionHandlerMock + ->expects($this->once()) + ->method('processEnabled') + ->with() + ->willReturn(true); + + $this->assertInstanceOf( + Value::class, + $this->enabledModel->afterSave() + ); + } + + /** + * @return void + */ + public function testAfterSaveSuccessDisabled() + { + $this->enabledModel->setData('value', $this->valueDisabled); + + $this->configMock + ->expects($this->any()) + ->method('getValue') + ->willReturn(!$this->valueDisabled); + + $this->subscriptionHandlerMock + ->expects($this->once()) + ->method('processDisabled') + ->with() + ->willReturn(true); + + $this->assertInstanceOf( + Value::class, + $this->enabledModel->afterSave() + ); + } + + /** + * @return void + */ + public function testAfterSaveSuccessValueNotChanged() + { + $this->enabledModel->setData('value', null); + + $this->configMock + ->expects($this->any()) + ->method('getValue') + ->willReturn(null); + + $this->subscriptionHandlerMock + ->expects($this->never()) + ->method('processEnabled') + ->with() + ->willReturn(true); + $this->subscriptionHandlerMock + ->expects($this->never()) + ->method('processDisabled') + ->with() + ->willReturn(true); + + $this->assertInstanceOf( + Value::class, + $this->enabledModel->afterSave() + ); + } + + /** + * @return void + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testExecuteAfterSaveFailedWithLocalizedException() + { + $exception = new \Exception('Message'); + $this->enabledModel->setData('value', $this->valueEnabled); + + $this->subscriptionHandlerMock + ->expects($this->once()) + ->method('processEnabled') + ->with() + ->willThrowException($exception); + + $this->loggerMock + ->expects($this->once()) + ->method('error') + ->with($exception->getMessage()); + + $this->enabledModel->afterSave(); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/VerticalTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/VerticalTest.php new file mode 100644 index 0000000000000..6fe7d0aa93998 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/Backend/VerticalTest.php @@ -0,0 +1,59 @@ +objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\Model\Config\Backend\Vertical::class + ); + } + + /** + * @return void + */ + public function testBeforeSaveSuccess() + { + $this->subject->setValue('Apps and Games'); + + $this->assertInstanceOf( + \Magento\Analytics\Model\Config\Backend\Vertical::class, + $this->subject->beforeSave() + ); + } + + /** + * @return void + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testBeforeSaveFailedWithLocalizedException() + { + $this->subject->setValue(''); + + $this->subject->beforeSave(); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/MapperTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/MapperTest.php new file mode 100644 index 0000000000000..0b7f4870dbac8 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/MapperTest.php @@ -0,0 +1,142 @@ +objectManagerHelper = new ObjectManagerHelper($this); + + $this->mapper = $this->objectManagerHelper->getObject(Mapper::class); + } + + /** + * @param array $configData + * @param array $resultData + * @return void + * + * @dataProvider executingDataProvider + */ + public function testExecution($configData, $resultData) + { + $this->assertSame($resultData, $this->mapper->execute($configData)); + } + + /** + * @return array + */ + public function executingDataProvider() + { + return [ + 'wrongConfig' => [ + ['config' => ['files']], + [] + ], + 'validConfigWithFileNodes' => [ + [ + 'config' => [ + 0 => [ + 'file' => [ + 0 => [ + 'name' => 'fileName', + 'providers' => [[]] + ] + ] + ] + ] + ], + [ + 'fileName' => [ + 'name' => 'fileName', + 'providers' => [] + ] + ], + ], + 'validConfigWithProvidersNode' => [ + [ + 'config' => [ + 0 => [ + 'file' => [ + 0 => [ + 'name' => 'fileName', + 'providers' => [ + 0 => [ + 'reportProvider' => [0 => []] + ] + ] + ] + ] + ] + ] + ], + [ + 'fileName' => [ + 'name' => 'fileName', + 'providers' => [ + 'reportProvider' => ['parameters' => []] + ] + ] + ], + ], + 'validConfigWithParametersNode' => [ + [ + 'config' => [ + 0 => [ + 'file' => [ + 0 => [ + 'name' => 'fileName', + 'providers' => [ + 0 => [ + 'reportProvider' => [ + 0 => [ + 'parameters' => [ + 0 => ['name' => ['reportName']] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ], + [ + 'fileName' => [ + 'name' => 'fileName', + 'providers' => [ + 'reportProvider' => [ + 'parameters' => [ + 'name' => 'reportName' + ] + ] + ] + ] + ], + ], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/ReaderTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/ReaderTest.php new file mode 100644 index 0000000000000..6aa9c7ef3106c --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/ReaderTest.php @@ -0,0 +1,108 @@ +mapperMock = $this->getMockBuilder(Mapper::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->readerXmlMock = $this->getMockBuilder(ReaderInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->readerDbMock = $this->getMockBuilder(ReaderInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->reader = $this->objectManagerHelper->getObject( + Reader::class, + [ + 'mapper' => $this->mapperMock, + 'readers' => [ + $this->readerXmlMock, + $this->readerDbMock, + ], + ] + ); + } + + /** + * @return void + */ + public function testRead() + { + $scope = 'store'; + $xmlReaderResult = [ + 'config' => ['node1' => ['node2' => 'node4']] + ]; + $dbReaderResult = [ + 'config' => ['node1' => ['node2' => 'node3']] + ]; + $mapperResult = ['node2' => ['node3', 'node4']]; + + $this->readerXmlMock + ->expects($this->once()) + ->method('read') + ->with($scope) + ->willReturn($xmlReaderResult); + + $this->readerDbMock + ->expects($this->once()) + ->method('read') + ->with($scope) + ->willReturn($dbReaderResult); + + $this->mapperMock + ->expects($this->once()) + ->method('execute') + ->with(array_merge_recursive($xmlReaderResult, $dbReaderResult)) + ->willReturn($mapperResult); + + $this->assertSame($mapperResult, $this->reader->read($scope)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Config/Source/VerticalTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Config/Source/VerticalTest.php new file mode 100644 index 0000000000000..c13205d34f25b --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Config/Source/VerticalTest.php @@ -0,0 +1,60 @@ +objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\Model\Config\Source\Vertical::class, + [ + 'verticals' => [ + 'Apps and Games', + 'Athletic/Sporting Goods', + 'Art and Design' + ] + ] + ); + } + + /** + * @return void + */ + public function testToOptionArray() + { + $expectedOptionsArray = [ + ['value' => '', 'label' => __('--Please Select--')], + ['value' => 'Apps and Games', 'label' => __('Apps and Games')], + ['value' => 'Athletic/Sporting Goods', 'label' => __('Athletic/Sporting Goods')], + ['value' => 'Art and Design', 'label' => __('Art and Design')] + ]; + + $this->assertEquals( + $expectedOptionsArray, + $this->subject->toOptionArray() + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/ConfigTest.php b/app/code/Magento/Analytics/Test/Unit/Model/ConfigTest.php new file mode 100644 index 0000000000000..8739219ebdf09 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/ConfigTest.php @@ -0,0 +1,68 @@ +dataInterfaceMock = $this->getMockBuilder(DataInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->config = $this->objectManagerHelper->getObject( + Config::class, + [ + 'data' => $this->dataInterfaceMock, + ] + ); + } + + /** + * @return void + */ + public function testGet() + { + $key = 'configKey'; + $defaultValue = 'mock'; + $configValue = 'emptyString'; + + $this->dataInterfaceMock + ->expects($this->once()) + ->method('get') + ->with($key, $defaultValue) + ->willReturn($configValue); + + $this->assertSame($configValue, $this->config->get($key, $defaultValue)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/Client/CurlTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/Client/CurlTest.php new file mode 100644 index 0000000000000..f8f3919b2489e --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/Client/CurlTest.php @@ -0,0 +1,218 @@ +curlMock = $this->getMockBuilder( + \Magento\Framework\HTTP\Adapter\Curl::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->loggerMock = $this->getMockBuilder( + \Psr\Log\LoggerInterface::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->curlFactoryMock = $this->getMockBuilder(CurlFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $this->curlFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->curlMock); + + $this->responseFactoryMock = $this->getMockBuilder( + \Magento\Analytics\Model\Connector\Http\ResponseFactory::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->converterMock = $this->createJsonConverter(); + + $this->objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\Model\Connector\Http\Client\Curl::class, + [ + 'curlFactory' => $this->curlFactoryMock, + 'responseFactory' => $this->responseFactoryMock, + 'converter' => $this->converterMock, + 'logger' => $this->loggerMock, + ] + ); + } + + /** + * Returns test parameters for request. + * + * @return array + */ + public function getTestData() + { + return [ + [ + 'data' => [ + 'version' => '1.1', + 'body'=> ['name' => 'value'], + 'url' => 'http://www.mystore.com', + 'headers' => [JsonConverter::CONTENT_TYPE_HEADER], + 'method' => \Magento\Framework\HTTP\ZendClient::POST, + ] + ] + ]; + } + + /** + * @return void + * @dataProvider getTestData + */ + public function testRequestSuccess(array $data) + { + $responseString = 'This is response.'; + $response = new \Zend_Http_Response(201, [], $responseString); + $this->curlMock->expects($this->once()) + ->method('write') + ->with( + $data['method'], + $data['url'], + $data['version'], + $data['headers'], + json_encode($data['body']) + ); + $this->curlMock->expects($this->once()) + ->method('read') + ->willReturn($responseString); + $this->curlMock->expects($this->any()) + ->method('getErrno') + ->willReturn(0); + + $this->responseFactoryMock->expects($this->any()) + ->method('create') + ->with($responseString) + ->willReturn($response); + + $this->assertEquals( + $response, + $this->subject->request( + $data['method'], + $data['url'], + $data['body'], + $data['headers'], + $data['version'] + ) + ); + } + + /** + * @return void + * @dataProvider getTestData + */ + public function testRequestError(array $data) + { + $response = new \Zend_Http_Response(0, []); + $this->curlMock->expects($this->once()) + ->method('write') + ->with( + $data['method'], + $data['url'], + $data['version'], + $data['headers'], + json_encode($data['body']) + ); + $this->curlMock->expects($this->once()) + ->method('read'); + $this->curlMock->expects($this->atLeastOnce()) + ->method('getErrno') + ->willReturn(1); + $this->curlMock->expects($this->atLeastOnce()) + ->method('getError') + ->willReturn('CURL error.'); + + $this->loggerMock->expects($this->once()) + ->method('critical') + ->with( + new \Exception( + 'MBI service CURL connection error #1: CURL error.' + ) + ); + + $this->assertEquals( + $response, + $this->subject->request( + $data['method'], + $data['url'], + $data['body'], + $data['headers'], + $data['version'] + ) + ); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function createJsonConverter() + { + $converterMock = $this->getMockBuilder(ConverterInterface::class) + ->getMockForAbstractClass(); + $converterMock->expects($this->any())->method('toBody')->willReturnCallback(function ($value) { + return json_encode($value); + }); + $converterMock->expects($this->any()) + ->method('getContentTypeHeader') + ->willReturn(JsonConverter::CONTENT_TYPE_HEADER); + return $converterMock; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/JsonConverterTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/JsonConverterTest.php new file mode 100644 index 0000000000000..60a19f3d5079e --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/JsonConverterTest.php @@ -0,0 +1,34 @@ +assertEquals(JsonConverter::CONTENT_TYPE_HEADER, $converter->getContentTypeHeader()); + } + + public function testConvertBody() + { + $body = '{"token": "secret-token"}'; + $converter = new JsonConverter(); + $this->assertEquals(json_decode($body, 1), $converter->fromBody($body)); + } + + public function testConvertData() + { + $data = ["token" => "secret-token"]; + $converter = new JsonConverter(); + $this->assertEquals(json_encode($data), $converter->toBody($data)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/ResponseResolverTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/ResponseResolverTest.php new file mode 100644 index 0000000000000..7c3c484843285 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/Http/ResponseResolverTest.php @@ -0,0 +1,39 @@ + 'testValue']; + $response = new \Zend_Http_Response(201, [], json_encode($expectedBody)); + $responseHandlerMock = $this->getMockBuilder(ResponseHandlerInterface::class) + ->getMockForAbstractClass(); + $responseHandlerMock->expects($this->once()) + ->method('handleResponse') + ->with($expectedBody) + ->willReturn(true); + $notFoundResponseHandlerMock = $this->getMockBuilder(ResponseHandlerInterface::class) + ->getMockForAbstractClass(); + $notFoundResponseHandlerMock->expects($this->never())->method('handleResponse'); + $responseResolver = new ResponseResolver( + new JsonConverter(), + [ + 201 => $responseHandlerMock, + 404 => $notFoundResponseHandlerMock, + ] + ); + $this->assertTrue($responseResolver->getResult($response)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/NotifyDataChangedCommandTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/NotifyDataChangedCommandTest.php new file mode 100644 index 0000000000000..cee3877631c2e --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/NotifyDataChangedCommandTest.php @@ -0,0 +1,107 @@ +analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->httpClientMock = $this->getMockBuilder(ClientInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $successHandler = $this->getMockBuilder(\Magento\Analytics\Model\Connector\Http\ResponseHandlerInterface::class) + ->getMockForAbstractClass(); + $successHandler->method('handleResponse') + ->willReturn(true); + + $this->notifyDataChangedCommand = new NotifyDataChangedCommand( + $this->analyticsTokenMock, + $this->httpClientMock, + $this->configMock, + new ResponseResolver(new JsonConverter(), [201 => $successHandler]), + $this->loggerMock + ); + } + + public function testExecuteSuccess() + { + $configVal = "Config val"; + $token = "Secret token!"; + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(true); + $this->configMock->expects($this->any()) + ->method('getValue') + ->willReturn($configVal); + $this->analyticsTokenMock->expects($this->once()) + ->method('getToken') + ->willReturn($token); + $this->httpClientMock->expects($this->once()) + ->method('request') + ->with( + ZendClient::POST, + $configVal, + ['access-token' => $token, 'url' => $configVal] + )->willReturn(new \Zend_Http_Response(201, [])); + $this->assertTrue($this->notifyDataChangedCommand->execute()); + } + + public function testExecuteWithoutToken() + { + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(false); + $this->httpClientMock->expects($this->never()) + ->method('request'); + $this->assertFalse($this->notifyDataChangedCommand->execute()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/OTPRequestTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/OTPRequestTest.php new file mode 100644 index 0000000000000..8a3f4efb15cf4 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/OTPRequestTest.php @@ -0,0 +1,187 @@ +loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->httpClientMock = $this->getMockBuilder(ClientInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->responseResolverMock = $this->getMockBuilder(ResponseResolver::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->subject = new OTPRequest( + $this->analyticsTokenMock, + $this->httpClientMock, + $this->configMock, + $this->responseResolverMock, + $this->loggerMock + ); + } + + /** + * Returns test parameters for request. + * + * @return array + */ + private function getTestData() + { + return [ + 'otp' => 'thisisotp', + 'url' => 'http://www.mystore.com', + 'access-token' => 'thisisaccesstoken', + 'method' => \Magento\Framework\HTTP\ZendClient::POST, + 'body'=> ['access-token' => 'thisisaccesstoken','url' => 'http://www.mystore.com'], + ]; + } + + /** + * @return void + */ + public function testCallSuccess() + { + $data = $this->getTestData(); + + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(true); + $this->analyticsTokenMock->expects($this->once()) + ->method('getToken') + ->willReturn($data['access-token']); + + $this->configMock->expects($this->any()) + ->method('getValue') + ->willReturn($data['url']); + + $this->httpClientMock->expects($this->once()) + ->method('request') + ->with( + $data['method'], + $data['url'], + $data['body'] + ) + ->willReturn(new \Zend_Http_Response(201, [])); + $this->responseResolverMock->expects($this->once()) + ->method('getResult') + ->willReturn($data['otp']); + + $this->assertEquals( + $data['otp'], + $this->subject->call() + ); + } + + /** + * @return void + */ + public function testCallNoAccessToken() + { + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(false); + + $this->httpClientMock->expects($this->never()) + ->method('request'); + + $this->assertFalse($this->subject->call()); + } + + /** + * @return void + */ + public function testCallNoOtp() + { + $data = $this->getTestData(); + + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(true); + $this->analyticsTokenMock->expects($this->once()) + ->method('getToken') + ->willReturn($data['access-token']); + + $this->configMock->expects($this->any()) + ->method('getValue') + ->willReturn($data['url']); + + $this->httpClientMock->expects($this->once()) + ->method('request') + ->with( + $data['method'], + $data['url'], + $data['body'] + ) + ->willReturn(new \Zend_Http_Response(0, [])); + + $this->responseResolverMock->expects($this->once()) + ->method('getResult') + ->willReturn(false); + + $this->loggerMock->expects($this->once()) + ->method('warning'); + + $this->assertFalse($this->subject->call()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/OTPTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/OTPTest.php new file mode 100644 index 0000000000000..0ff36cca5db2d --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/OTPTest.php @@ -0,0 +1,22 @@ +assertFalse($OTPHandler->handleResponse([])); + $expectedOtp = 123; + $this->assertEquals($expectedOtp, $OTPHandler->handleResponse(['otp' => $expectedOtp])); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/ReSignUpTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/ReSignUpTest.php new file mode 100644 index 0000000000000..707003149bcfd --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/ReSignUpTest.php @@ -0,0 +1,36 @@ +getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + $analyticsToken->expects($this->once()) + ->method('storeToken') + ->with(null); + $subscriptionHandler = $this->getMockBuilder(SubscriptionHandler::class) + ->disableOriginalConstructor() + ->getMock(); + $subscriptionStatusProvider = $this->getMockBuilder(SubscriptionStatusProvider::class) + ->disableOriginalConstructor() + ->getMock(); + $subscriptionStatusProvider->method('getStatus')->willReturn(SubscriptionStatusProvider::ENABLED); + $reSignUpHandler = new ReSignUp($analyticsToken, $subscriptionHandler, $subscriptionStatusProvider); + $this->assertFalse($reSignUpHandler->handleResponse([])); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/SignUpTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/SignUpTest.php new file mode 100644 index 0000000000000..81711cfc56950 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/SignUpTest.php @@ -0,0 +1,30 @@ +getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + $analyticsToken->expects($this->once()) + ->method('storeToken') + ->with($accessToken); + $signUpHandler = new SignUp($analyticsToken, new JsonConverter()); + $this->assertFalse($signUpHandler->handleResponse([])); + $this->assertEquals($accessToken, $signUpHandler->handleResponse(['access-token' => $accessToken])); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/UpdateTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/UpdateTest.php new file mode 100644 index 0000000000000..7779357e8bea7 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/ResponseHandler/UpdateTest.php @@ -0,0 +1,20 @@ +assertTrue($updateHandler->handleResponse([])); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/SignUpCommandTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/SignUpCommandTest.php new file mode 100644 index 0000000000000..5593496a957b7 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/SignUpCommandTest.php @@ -0,0 +1,174 @@ +analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + $this->integrationManagerMock = $this->getMockBuilder(IntegrationManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->integrationToken = $this->getMockBuilder(IntegrationToken::class) + ->disableOriginalConstructor() + ->getMock(); + $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->httpClientMock = $this->getMockBuilder(ClientInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->responseResolverMock = $this->getMockBuilder(ResponseResolver::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->signUpCommand = new SignUpCommand( + $this->analyticsTokenMock, + $this->integrationManagerMock, + $this->configMock, + $this->httpClientMock, + $this->loggerMock, + $this->responseResolverMock + ); + } + + public function testExecuteSuccess() + { + $this->integrationManagerMock->expects($this->once()) + ->method('generateToken') + ->willReturn($this->integrationToken); + $this->integrationManagerMock->expects($this->once()) + ->method('activateIntegration') + ->willReturn(true); + $data = $this->getTestData(); + + $this->configMock->expects($this->any()) + ->method('getValue') + ->willReturn($data['url']); + $this->integrationToken->expects($this->any()) + ->method('getData') + ->with('token') + ->willReturn($data['integration-token']); + $httpResponse = new \Zend_Http_Response(201, [], '{"access-token": "' . $data['access-token'] . '"}'); + $this->httpClientMock->expects($this->once()) + ->method('request') + ->with( + $data['method'], + $data['url'], + $data['body'] + ) + ->willReturn($httpResponse); + $this->responseResolverMock->expects($this->any()) + ->method('getResult') + ->with($httpResponse) + ->willReturn(true); + $this->assertTrue($this->signUpCommand->execute()); + } + + public function testExecuteFailureCannotGenerateToken() + { + $this->integrationManagerMock->expects($this->once()) + ->method('generateToken') + ->willReturn(false); + $this->integrationManagerMock->expects($this->never()) + ->method('activateIntegration'); + $this->assertFalse($this->signUpCommand->execute()); + } + + public function testExecuteFailureResponseIsEmpty() + { + $this->integrationManagerMock->expects($this->once()) + ->method('generateToken') + ->willReturn($this->integrationToken); + $this->integrationManagerMock->expects($this->once()) + ->method('activateIntegration') + ->willReturn(true); + $httpResponse = new \Zend_Http_Response(0, []); + $this->httpClientMock->expects($this->once()) + ->method('request') + ->willReturn($httpResponse); + $this->responseResolverMock->expects($this->any()) + ->method('getResult') + ->willReturn(false); + $this->assertFalse($this->signUpCommand->execute()); + } + + /** + * Returns test parameters for request. + * + * @return array + */ + private function getTestData() + { + return [ + 'url' => 'http://www.mystore.com', + 'access-token' => 'thisisaccesstoken', + 'integration-token' => 'thisisintegrationtoken', + 'headers' => [JsonConverter::CONTENT_TYPE_HEADER], + 'method' => \Magento\Framework\HTTP\ZendClient::POST, + 'body'=> ['token' => 'thisisintegrationtoken','url' => 'http://www.mystore.com'], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Connector/UpdateCommandTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Connector/UpdateCommandTest.php new file mode 100644 index 0000000000000..47253a13530e5 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Connector/UpdateCommandTest.php @@ -0,0 +1,143 @@ +analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->httpClientMock = $this->getMockBuilder(ClientInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->responseResolverMock = $this->getMockBuilder(ResponseResolver::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->updateCommand = new UpdateCommand( + $this->analyticsTokenMock, + $this->httpClientMock, + $this->configMock, + $this->loggerMock, + $this->flagManagerMock, + $this->responseResolverMock + ); + } + + public function testExecuteSuccess() + { + $url = "old.localhost.com"; + $configVal = "Config val"; + $token = "Secret token!"; + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(true); + + $this->configMock->expects($this->any()) + ->method('getValue') + ->willReturn($configVal); + + $this->flagManagerMock->expects($this->once()) + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE) + ->willReturn($url); + + $this->analyticsTokenMock->expects($this->once()) + ->method('getToken') + ->willReturn($token); + + $this->httpClientMock->expects($this->once()) + ->method('request') + ->with( + ZendClient::PUT, + $configVal, + [ + 'url' => $url, + 'new-url' => $configVal, + 'access-token' => $token + ] + )->willReturn(new \Zend_Http_Response(200, [])); + + $this->responseResolverMock->expects($this->once()) + ->method('getResult') + ->willReturn(true); + + $this->assertTrue($this->updateCommand->execute()); + } + + public function testExecuteWithoutToken() + { + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(false); + + $this->assertFalse($this->updateCommand->execute()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/ConnectorTest.php b/app/code/Magento/Analytics/Test/Unit/Model/ConnectorTest.php new file mode 100644 index 0000000000000..4414b81cbc183 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/ConnectorTest.php @@ -0,0 +1,70 @@ +objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->signUpCommandMock = $this->getMockBuilder(SignUpCommand::class) + ->disableOriginalConstructor() + ->getMock(); + $this->commands = ['signUp' => SignUpCommand::class]; + $this->connector = new Connector($this->commands, $this->objectManagerMock); + } + + public function testExecute() + { + $commandName = 'signUp'; + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with($this->commands[$commandName]) + ->willReturn($this->signUpCommandMock); + $this->signUpCommandMock->expects($this->once()) + ->method('execute') + ->willReturn(true); + $this->assertTrue($this->connector->execute($commandName)); + } + + /** + * @expectedException \Magento\Framework\Exception\NotFoundException + */ + public function testExecuteCommandNotFound() + { + $commandName = 'register'; + $this->connector->execute($commandName); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/CryptographerTest.php b/app/code/Magento/Analytics/Test/Unit/Model/CryptographerTest.php new file mode 100644 index 0000000000000..a896c309b4007 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/CryptographerTest.php @@ -0,0 +1,226 @@ +analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->encodedContextFactoryMock = $this->getMockBuilder(EncodedContextFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + + $this->encodedContextMock = $this->getMockBuilder(EncodedContext::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->key = ''; + $this->source = ''; + $this->initializationVectors = []; + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->cryptographer = $this->objectManagerHelper->getObject( + Cryptographer::class, + [ + 'analyticsToken' => $this->analyticsTokenMock, + 'encodedContextFactory' => $this->encodedContextFactoryMock, + 'cipherMethod' => $this->cipherMethod, + ] + ); + } + + /** + * @return void + */ + public function testEncode() + { + $token = 'some-token-value'; + $this->source = 'Some text'; + $this->key = hash('sha256', $token); + + $checkEncodedContext = function ($parameters) { + $emptyRequiredParameters = + array_diff(['content', 'initializationVector'], array_keys(array_filter($parameters))); + if ($emptyRequiredParameters) { + return false; + } + + $encryptedData = openssl_encrypt( + $this->source, + $this->cipherMethod, + $this->key, + OPENSSL_RAW_DATA, + $parameters['initializationVector'] + ); + + return ($encryptedData === $parameters['content']); + }; + + $this->analyticsTokenMock + ->expects($this->once()) + ->method('getToken') + ->with() + ->willReturn($token); + + $this->encodedContextFactoryMock + ->expects($this->once()) + ->method('create') + ->with($this->callback($checkEncodedContext)) + ->willReturn($this->encodedContextMock); + + $this->assertSame($this->encodedContextMock, $this->cryptographer->encode($this->source)); + } + + /** + * @return void + */ + public function testEncodeUniqueInitializationVector() + { + $this->source = 'Some text'; + $token = 'some-token-value'; + + $registerInitializationVector = function ($parameters) { + if (empty($parameters['initializationVector'])) { + return false; + } + + $this->initializationVectors[] = $parameters['initializationVector']; + + return true; + }; + + $this->analyticsTokenMock + ->expects($this->exactly(2)) + ->method('getToken') + ->with() + ->willReturn($token); + + $this->encodedContextFactoryMock + ->expects($this->exactly(2)) + ->method('create') + ->with($this->callback($registerInitializationVector)) + ->willReturn($this->encodedContextMock); + + $this->assertSame($this->encodedContextMock, $this->cryptographer->encode($this->source)); + $this->assertSame($this->encodedContextMock, $this->cryptographer->encode($this->source)); + $this->assertCount(2, array_unique($this->initializationVectors)); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @dataProvider encodeNotValidSourceDataProvider + */ + public function testEncodeNotValidSource($source) + { + $this->cryptographer->encode($source); + } + + /** + * @return array + */ + public function encodeNotValidSourceDataProvider() + { + return [ + 'Array' => [[]], + 'Empty string' => [''], + ]; + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testEncodeNotValidCipherMethod() + { + $source = 'Some string'; + $cryptographer = $this->objectManagerHelper->getObject( + Cryptographer::class, + [ + 'cipherMethod' => 'Wrong-method', + ] + ); + + $cryptographer->encode($source); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testEncodeTokenNotValid() + { + $source = 'Some string'; + + $this->analyticsTokenMock + ->expects($this->once()) + ->method('getToken') + ->with() + ->willReturn(null); + + $this->cryptographer->encode($source); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/EncodedContextTest.php b/app/code/Magento/Analytics/Test/Unit/Model/EncodedContextTest.php new file mode 100644 index 0000000000000..a1a7c54510681 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/EncodedContextTest.php @@ -0,0 +1,61 @@ +objectManagerHelper = new ObjectManagerHelper($this); + } + + /** + * @param string $content + * @param string|null $initializationVector + * @return void + * @dataProvider constructDataProvider + */ + public function testConstruct($content, $initializationVector) + { + $constructorArguments = [ + 'content' => $content, + 'initializationVector' => $initializationVector, + ]; + /** @var EncodedContext $encodedContext */ + $encodedContext = $this->objectManagerHelper->getObject( + EncodedContext::class, + array_filter($constructorArguments) + ); + + $this->assertSame($content, $encodedContext->getContent()); + $this->assertSame($initializationVector ?: '', $encodedContext->getInitializationVector()); + } + + /** + * @return array + */ + public function constructDataProvider() + { + return [ + 'Without Initialization Vector' => ['content text', null], + 'With Initialization Vector' => ['content text', 'c51sd3c4sd68c5sd'], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/ExportDataHandlerNotificationTest.php b/app/code/Magento/Analytics/Test/Unit/Model/ExportDataHandlerNotificationTest.php new file mode 100644 index 0000000000000..1582c241bf45d --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/ExportDataHandlerNotificationTest.php @@ -0,0 +1,74 @@ +objectManagerHelper = new ObjectManagerHelper($this); + } + + /** + * @return void + */ + public function testThatNotifyExecuted() + { + $expectedResult = true; + $notifyCommandName = 'notifyDataChanged'; + $exportDataHandlerMockObject = $this->createExportDataHandlerMock(); + $analyticsConnectorMockObject = $this->createAnalyticsConnectorMock(); + /** + * @var $exportDataHandlerNotification ExportDataHandlerNotification + */ + $exportDataHandlerNotification = $this->objectManagerHelper->getObject( + ExportDataHandlerNotification::class, + [ + 'exportDataHandler' => $exportDataHandlerMockObject, + 'connector' => $analyticsConnectorMockObject, + ] + ); + $exportDataHandlerMockObject->expects($this->once()) + ->method('prepareExportData') + ->willReturn($expectedResult); + $analyticsConnectorMockObject->expects($this->once()) + ->method('execute') + ->with($notifyCommandName); + $this->assertEquals($expectedResult, $exportDataHandlerNotification->prepareExportData()); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function createExportDataHandlerMock() + { + return $this->getMockBuilder(ExportDataHandler::class)->disableOriginalConstructor()->getMock(); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function createAnalyticsConnectorMock() + { + return $this->getMockBuilder(Connector::class)->disableOriginalConstructor()->getMock(); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/ExportDataHandlerTest.php b/app/code/Magento/Analytics/Test/Unit/Model/ExportDataHandlerTest.php new file mode 100644 index 0000000000000..6ffb61d088567 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/ExportDataHandlerTest.php @@ -0,0 +1,270 @@ +filesystemMock = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->archiveMock = $this->getMockBuilder(Archive::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->reportWriterMock = $this->getMockBuilder(ReportWriterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->cryptographerMock = $this->getMockBuilder(Cryptographer::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->fileRecorderMock = $this->getMockBuilder(FileRecorder::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->directoryMock = $this->getMockBuilder(WriteInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->encodedContextMock = $this->getMockBuilder(EncodedContext::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->exportDataHandler = $this->objectManagerHelper->getObject( + ExportDataHandler::class, + [ + 'filesystem' => $this->filesystemMock, + 'archive' => $this->archiveMock, + 'reportWriter' => $this->reportWriterMock, + 'cryptographer' => $this->cryptographerMock, + 'fileRecorder' => $this->fileRecorderMock, + 'subdirectoryPath' => $this->subdirectoryPath, + 'archiveName' => $this->archiveName, + ] + ); + } + + /** + * @param bool $isArchiveSourceDirectory + * @dataProvider prepareExportDataDataProvider + */ + public function testPrepareExportData($isArchiveSourceDirectory) + { + $tmpFilesDirectoryPath = $this->subdirectoryPath . 'tmp/'; + $archiveRelativePath = $this->subdirectoryPath . $this->archiveName; + + $archiveSource = $isArchiveSourceDirectory ? (__DIR__) : '/tmp/' . $tmpFilesDirectoryPath; + $archiveAbsolutePath = '/tmp/' . $archiveRelativePath; + + $this->filesystemMock + ->expects($this->once()) + ->method('getDirectoryWrite') + ->with(DirectoryList::SYS_TMP) + ->willReturn($this->directoryMock); + $this->directoryMock + ->expects($this->exactly(4)) + ->method('delete') + ->withConsecutive( + [$tmpFilesDirectoryPath], + [$archiveRelativePath] + ); + + $this->directoryMock + ->expects($this->exactly(4)) + ->method('getAbsolutePath') + ->withConsecutive( + [$tmpFilesDirectoryPath], + [$tmpFilesDirectoryPath], + [$archiveRelativePath], + [$archiveRelativePath] + ) + ->willReturnOnConsecutiveCalls( + $archiveSource, + $archiveSource, + $archiveAbsolutePath, + $archiveAbsolutePath + ); + + $this->reportWriterMock + ->expects($this->once()) + ->method('write') + ->with($this->directoryMock, $tmpFilesDirectoryPath); + + $this->directoryMock + ->expects($this->exactly(2)) + ->method('isExist') + ->withConsecutive( + [$tmpFilesDirectoryPath], + [$archiveRelativePath] + ) + ->willReturnOnConsecutiveCalls( + true, + true + ); + + $this->directoryMock + ->expects($this->once()) + ->method('create') + ->with(dirname($archiveRelativePath)); + + $this->archiveMock + ->expects($this->once()) + ->method('pack') + ->with( + $archiveSource, + $archiveAbsolutePath, + $isArchiveSourceDirectory ? true : false + ); + + $fileContent = 'Some text'; + $this->directoryMock + ->expects($this->once()) + ->method('readFile') + ->with($archiveRelativePath) + ->willReturn($fileContent); + + $this->cryptographerMock + ->expects($this->once()) + ->method('encode') + ->with($fileContent) + ->willReturn($this->encodedContextMock); + + $this->fileRecorderMock + ->expects($this->once()) + ->method('recordNewFile') + ->with($this->encodedContextMock); + + $this->assertTrue($this->exportDataHandler->prepareExportData()); + } + + /** + * @return array + */ + public function prepareExportDataDataProvider() + { + return [ + 'Data source for archive is directory' => [true], + 'Data source for archive doesn\'t directory' => [false], + ]; + } + + /** + * @return void + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testPrepareExportDataWithLocalizedException() + { + $tmpFilesDirectoryPath = $this->subdirectoryPath . 'tmp/'; + $archivePath = $this->subdirectoryPath . $this->archiveName; + + $this->filesystemMock + ->expects($this->once()) + ->method('getDirectoryWrite') + ->with(DirectoryList::SYS_TMP) + ->willReturn($this->directoryMock); + $this->reportWriterMock + ->expects($this->once()) + ->method('write') + ->with($this->directoryMock, $tmpFilesDirectoryPath); + $this->directoryMock + ->expects($this->exactly(3)) + ->method('delete') + ->withConsecutive( + [$tmpFilesDirectoryPath], + [$tmpFilesDirectoryPath], + [$archivePath] + ); + $this->directoryMock + ->expects($this->exactly(2)) + ->method('getAbsolutePath') + ->with($tmpFilesDirectoryPath); + $this->directoryMock + ->expects($this->once()) + ->method('isExist') + ->with($tmpFilesDirectoryPath) + ->willReturn(false); + + $this->assertNull($this->exportDataHandler->prepareExportData()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/FileInfoManagerTest.php b/app/code/Magento/Analytics/Test/Unit/Model/FileInfoManagerTest.php new file mode 100644 index 0000000000000..da5f6af3ca4e1 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/FileInfoManagerTest.php @@ -0,0 +1,194 @@ +flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->fileInfoFactoryMock = $this->getMockBuilder(FileInfoFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + + $this->fileInfoMock = $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->fileInfoManager = $this->objectManagerHelper->getObject( + FileInfoManager::class, + [ + 'flagManager' => $this->flagManagerMock, + 'fileInfoFactory' => $this->fileInfoFactoryMock, + 'flagCode' => $this->flagCode, + 'encodedParameters' => $this->encodedParameters, + ] + ); + } + + /** + * @return void + */ + public function testSave() + { + $path = 'path/to/file'; + $initializationVector = openssl_random_pseudo_bytes(16); + $parameters = [ + 'path' => $path, + 'initializationVector' => $initializationVector, + ]; + + $this->fileInfoMock + ->expects($this->once()) + ->method('getPath') + ->with() + ->willReturn($path); + $this->fileInfoMock + ->expects($this->once()) + ->method('getInitializationVector') + ->with() + ->willReturn($initializationVector); + + foreach ($this->encodedParameters as $encodedParameter) { + $parameters[$encodedParameter] = base64_encode($parameters[$encodedParameter]); + } + $this->flagManagerMock + ->expects($this->once()) + ->method('saveFlag') + ->with($this->flagCode, $parameters); + + $this->assertTrue($this->fileInfoManager->save($this->fileInfoMock)); + } + + /** + * @param string|null $path + * @param string|null $initializationVector + * @dataProvider saveWithLocalizedExceptionDataProvider + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testSaveWithLocalizedException($path, $initializationVector) + { + $this->fileInfoMock + ->expects($this->once()) + ->method('getPath') + ->with() + ->willReturn($path); + $this->fileInfoMock + ->expects($this->once()) + ->method('getInitializationVector') + ->with() + ->willReturn($initializationVector); + + $this->fileInfoManager->save($this->fileInfoMock); + } + + /** + * @return array + */ + public function saveWithLocalizedExceptionDataProvider() + { + return [ + 'Empty FileInfo' => [null, null], + 'FileInfo without IV' => ['path/to/file', null], + ]; + } + + /** + * @dataProvider loadDataProvider + * @param array|null $parameters + */ + public function testLoad($parameters) + { + $this->flagManagerMock + ->expects($this->once()) + ->method('getFlagData') + ->with($this->flagCode) + ->willReturn($parameters); + + $processedParameters = $parameters ?: []; + $encodedParameters = array_intersect($this->encodedParameters, array_keys($processedParameters)); + foreach ($encodedParameters as $encodedParameter) { + $processedParameters[$encodedParameter] = base64_decode($processedParameters[$encodedParameter]); + } + + $this->fileInfoFactoryMock + ->expects($this->once()) + ->method('create') + ->with($processedParameters) + ->willReturn($this->fileInfoMock); + + $this->assertSame($this->fileInfoMock, $this->fileInfoManager->load()); + } + + /** + * @return array + */ + public function loadDataProvider() + { + return [ + 'Empty flag data' => [null], + 'Correct flag data' => [[ + 'path' => 'path/to/file', + 'initializationVector' => 'xUJjl54MVke+FvMFSBpRSA==', + ]], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/FileInfoTest.php b/app/code/Magento/Analytics/Test/Unit/Model/FileInfoTest.php new file mode 100644 index 0000000000000..43ce833f1f03f --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/FileInfoTest.php @@ -0,0 +1,62 @@ +objectManagerHelper = new ObjectManagerHelper($this); + } + + /** + * @param string|null $path + * @param string|null $initializationVector + * @return void + * @dataProvider constructDataProvider + */ + public function testConstruct($path, $initializationVector) + { + $constructorArguments = [ + 'path' => $path, + 'initializationVector' => $initializationVector, + ]; + /** @var FileInfo $fileInfo */ + $fileInfo = $this->objectManagerHelper->getObject( + FileInfo::class, + array_filter($constructorArguments) + ); + + $this->assertSame($path ?: '', $fileInfo->getPath()); + $this->assertSame($initializationVector ?: '', $fileInfo->getInitializationVector()); + } + + /** + * @return array + */ + public function constructDataProvider() + { + return [ + 'Degenerate object' => [null, null], + 'Without Initialization Vector' => ['content text', null], + 'With Initialization Vector' => ['content text', 'c51sd3c4sd68c5sd'], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/FileRecorderTest.php b/app/code/Magento/Analytics/Test/Unit/Model/FileRecorderTest.php new file mode 100644 index 0000000000000..3c9520bdd995b --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/FileRecorderTest.php @@ -0,0 +1,209 @@ +fileInfoManagerMock = $this->getMockBuilder(FileInfoManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->fileInfoFactoryMock = $this->getMockBuilder(FileInfoFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + + $this->filesystemMock = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->fileInfoMock = $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->directoryMock = $this->getMockBuilder(WriteInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->encodedContextMock = $this->getMockBuilder(EncodedContext::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->fileRecorder = $this->objectManagerHelper->getObject( + FileRecorder::class, + [ + 'fileInfoManager' => $this->fileInfoManagerMock, + 'fileInfoFactory' => $this->fileInfoFactoryMock, + 'filesystem' => $this->filesystemMock, + 'fileSubdirectoryPath' => $this->fileSubdirectoryPath, + 'encodedFileName' => $this->encodedFileName, + ] + ); + } + + /** + * @param string $pathToExistingFile + * @dataProvider recordNewFileDataProvider + */ + public function testRecordNewFile($pathToExistingFile) + { + $content = openssl_random_pseudo_bytes(200); + + $this->filesystemMock + ->expects($this->once()) + ->method('getDirectoryWrite') + ->with(DirectoryList::MEDIA) + ->willReturn($this->directoryMock); + + $this->encodedContextMock + ->expects($this->once()) + ->method('getContent') + ->with() + ->willReturn($content); + + $hashLength = 64; + $fileRelativePathPattern = '#' . preg_quote($this->fileSubdirectoryPath, '#') + . '.{' . $hashLength . '}/' . preg_quote($this->encodedFileName, '#') . '#'; + $this->directoryMock + ->expects($this->once()) + ->method('writeFile') + ->with($this->matchesRegularExpression($fileRelativePathPattern), $content) + ->willReturn($this->directoryMock); + + $this->fileInfoManagerMock + ->expects($this->once()) + ->method('load') + ->with() + ->willReturn($this->fileInfoMock); + + $this->encodedContextMock + ->expects($this->once()) + ->method('getInitializationVector') + ->with() + ->willReturn('init_vector***'); + + /** register file */ + $this->fileInfoFactoryMock + ->expects($this->once()) + ->method('create') + ->with($this->callback( + function ($parameters) { + return !empty($parameters['path']) && ('init_vector***' === $parameters['initializationVector']); + } + )) + ->willReturn($this->fileInfoMock); + $this->fileInfoManagerMock + ->expects($this->once()) + ->method('save') + ->with($this->fileInfoMock); + + /** remove old file */ + $this->fileInfoMock + ->expects($this->exactly($pathToExistingFile ? 3 : 1)) + ->method('getPath') + ->with() + ->willReturn($pathToExistingFile); + $directoryName = dirname($pathToExistingFile); + if ($directoryName === '.') { + $this->directoryMock + ->expects($this->once()) + ->method('delete') + ->with($pathToExistingFile); + } elseif ($directoryName) { + $this->directoryMock + ->expects($this->exactly(2)) + ->method('delete') + ->withConsecutive( + [$pathToExistingFile], + [$directoryName] + ); + } + + $this->assertTrue($this->fileRecorder->recordNewFile($this->encodedContextMock)); + } + + /** + * @return array + */ + public function recordNewFileDataProvider() + { + return [ + 'File doesn\'t exist' => [''], + 'Existing file into subdirectory' => ['dir_name/file.txt'], + 'Existing file doesn\'t into subdirectory' => ['file.txt'], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/IntegrationManagerTest.php b/app/code/Magento/Analytics/Test/Unit/Model/IntegrationManagerTest.php new file mode 100644 index 0000000000000..3076a22c85be4 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/IntegrationManagerTest.php @@ -0,0 +1,228 @@ +integrationServiceMock = $this->getMockBuilder(IntegrationServiceInterface::class) + ->getMock(); + $this->configMock = $this->getMockBuilder(Config::class) + ->disableOriginalConstructor() + ->getMock(); + $this->oauthServiceMock = $this->getMockBuilder(OauthServiceInterface::class) + ->getMock(); + $this->integrationMock = $this->getMockBuilder(Integration::class) + ->disableOriginalConstructor() + ->setMethods([ + 'getId', + 'getConsumerId' + ]) + ->getMock(); + $this->integrationManager = $objectManagerHelper->getObject( + IntegrationManager::class, + [ + 'integrationService' => $this->integrationServiceMock, + 'oauthService' => $this->oauthServiceMock, + 'config' => $this->configMock + ] + ); + } + + /** + * @param string $status + * + * @return array + */ + private function getIntegrationUserData($status) + { + return [ + 'name' => 'ma-integration-user', + 'status' => $status, + 'all_resources' => false, + 'resource' => [ + 'Magento_Analytics::analytics', + 'Magento_Analytics::analytics_api' + ], + ]; + } + + /** + * @return void + */ + public function testActivateIntegrationSuccess() + { + $this->integrationServiceMock->expects($this->once()) + ->method('findByName') + ->with('ma-integration-user') + ->willReturn($this->integrationMock); + $this->integrationMock->expects($this->exactly(2)) + ->method('getId') + ->willReturn(100500); + $integrationData = $this->getIntegrationUserData(Integration::STATUS_ACTIVE); + $integrationData['integration_id'] = 100500; + $this->configMock->expects($this->exactly(2)) + ->method('getConfigDataValue') + ->with('analytics/integration_name', null, null) + ->willReturn('ma-integration-user'); + $this->integrationServiceMock->expects($this->once()) + ->method('update') + ->with($integrationData); + $this->assertTrue($this->integrationManager->activateIntegration()); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + */ + public function testActivateIntegrationFailureNoSuchEntity() + { + $this->integrationServiceMock->expects($this->once()) + ->method('findByName') + ->with('ma-integration-user') + ->willReturn($this->integrationMock); + $this->integrationMock->expects($this->once()) + ->method('getId') + ->willReturn(null); + $this->configMock->expects($this->once()) + ->method('getConfigDataValue') + ->with('analytics/integration_name', null, null) + ->willReturn('ma-integration-user'); + $this->integrationServiceMock->expects($this->never()) + ->method('update'); + $this->integrationManager->activateIntegration(); + } + + /** + * @dataProvider integrationIdDataProvider + * + * @param int|null $integrationId If null integration is absent. + * @return void + */ + public function testGetTokenNewIntegration($integrationId) + { + $this->configMock->expects($this->atLeastOnce()) + ->method('getConfigDataValue') + ->with('analytics/integration_name', null, null) + ->willReturn('ma-integration-user'); + $this->integrationServiceMock->expects($this->once()) + ->method('findByName') + ->with('ma-integration-user') + ->willReturn($this->integrationMock); + $this->integrationMock->expects($this->once()) + ->method('getConsumerId') + ->willReturn(100500); + $this->integrationMock->expects($this->once()) + ->method('getId') + ->willReturn($integrationId); + if (!$integrationId) { + $this->integrationServiceMock + ->expects($this->once()) + ->method('create') + ->with($this->getIntegrationUserData(Integration::STATUS_INACTIVE)) + ->willReturn($this->integrationMock); + } + $this->oauthServiceMock->expects($this->at(0)) + ->method('getAccessToken') + ->with(100500) + ->willReturn(false); + $this->oauthServiceMock->expects($this->at(2)) + ->method('getAccessToken') + ->with(100500) + ->willReturn('IntegrationToken'); + $this->oauthServiceMock->expects($this->once()) + ->method('createAccessToken') + ->with(100500, true) + ->willReturn(true); + $this->assertEquals('IntegrationToken', $this->integrationManager->generateToken()); + } + + /** + * @dataProvider integrationIdDataProvider + * + * @param int|null $integrationId If null integration is absent. + * @return void + */ + public function testGetTokenExistingIntegration($integrationId) + { + $this->configMock->expects($this->atLeastOnce()) + ->method('getConfigDataValue') + ->with('analytics/integration_name', null, null) + ->willReturn('ma-integration-user'); + $this->integrationServiceMock->expects($this->once()) + ->method('findByName') + ->with('ma-integration-user') + ->willReturn($this->integrationMock); + $this->integrationMock->expects($this->once()) + ->method('getConsumerId') + ->willReturn(100500); + $this->integrationMock->expects($this->once()) + ->method('getId') + ->willReturn($integrationId); + if (!$integrationId) { + $this->integrationServiceMock + ->expects($this->once()) + ->method('create') + ->with($this->getIntegrationUserData(Integration::STATUS_INACTIVE)) + ->willReturn($this->integrationMock); + } + $this->oauthServiceMock->expects($this->once()) + ->method('getAccessToken') + ->with(100500) + ->willReturn('IntegrationToken'); + $this->oauthServiceMock->expects($this->never()) + ->method('createAccessToken'); + $this->assertEquals('IntegrationToken', $this->integrationManager->generateToken()); + } + + /** + * @return array + */ + public function integrationIdDataProvider() + { + return [ + [1], + [null], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/LinkProviderTest.php b/app/code/Magento/Analytics/Test/Unit/Model/LinkProviderTest.php new file mode 100644 index 0000000000000..c7aa2219d1eee --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/LinkProviderTest.php @@ -0,0 +1,166 @@ +linkInterfaceFactoryMock = $this->getMockBuilder(LinkInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->fileInfoManagerMock = $this->getMockBuilder(FileInfoManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->storeManagerInterfaceMock = $this->getMockBuilder(StoreManagerInterface::class) + ->getMockForAbstractClass(); + $this->linkInterfaceMock = $this->getMockBuilder(LinkInterface::class) + ->getMockForAbstractClass(); + $this->fileInfoMock = $this->getMockBuilder(FileInfo::class) + ->disableOriginalConstructor() + ->getMock(); + $this->storeMock = $this->getMockBuilder(Store::class) + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->linkProvider = $this->objectManagerHelper->getObject( + LinkProvider::class, + [ + 'linkFactory' => $this->linkInterfaceFactoryMock, + 'fileInfoManager' => $this->fileInfoManagerMock, + 'storeManager' => $this->storeManagerInterfaceMock + ] + ); + } + + public function testGet() + { + $baseUrl = 'http://magento.local/pub/media/'; + $fileInfoPath = 'analytics/data.tgz'; + $fileInitializationVector = 'er312esq23eqq'; + $this->fileInfoManagerMock->expects($this->once()) + ->method('load') + ->willReturn($this->fileInfoMock); + $this->linkInterfaceFactoryMock->expects($this->once()) + ->method('create') + ->with( + [ + 'initializationVector' => base64_encode($fileInitializationVector), + 'url' => $baseUrl . $fileInfoPath + ] + ) + ->willReturn($this->linkInterfaceMock); + $this->storeManagerInterfaceMock->expects($this->once()) + ->method('getStore')->willReturn($this->storeMock); + $this->storeMock->expects($this->once()) + ->method('getBaseUrl') + ->with( + UrlInterface::URL_TYPE_MEDIA + ) + ->willReturn($baseUrl); + $this->fileInfoMock->expects($this->atLeastOnce()) + ->method('getPath') + ->willReturn($fileInfoPath); + $this->fileInfoMock->expects($this->atLeastOnce()) + ->method('getInitializationVector') + ->willReturn($fileInitializationVector); + $this->assertEquals($this->linkInterfaceMock, $this->linkProvider->get()); + } + + /** + * @param string|null $fileInfoPath + * @param string|null $fileInitializationVector + * + * @dataProvider fileNotReadyDataProvider + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage File is not ready yet. + */ + public function testFileNotReady($fileInfoPath, $fileInitializationVector) + { + $this->fileInfoManagerMock->expects($this->once()) + ->method('load') + ->willReturn($this->fileInfoMock); + $this->fileInfoMock->expects($this->once()) + ->method('getPath') + ->willReturn($fileInfoPath); + $this->fileInfoMock->expects($this->any()) + ->method('getInitializationVector') + ->willReturn($fileInitializationVector); + $this->linkProvider->get(); + } + + /** + * @return array + */ + public function fileNotReadyDataProvider() + { + return [ + [null, 'initVector'], + ['path', null], + ['', 'initVector'], + ['path', ''], + ['', ''], + [null, null] + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/Plugin/BaseUrlConfigPluginTest.php b/app/code/Magento/Analytics/Test/Unit/Model/Plugin/BaseUrlConfigPluginTest.php new file mode 100644 index 0000000000000..a89e06562383b --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/Plugin/BaseUrlConfigPluginTest.php @@ -0,0 +1,147 @@ +subscriptionUpdateHandlerMock = $this->getMockBuilder(SubscriptionUpdateHandler::class) + ->disableOriginalConstructor() + ->getMock(); + $this->configValueMock = $this->getMockBuilder(Value::class) + ->disableOriginalConstructor() + ->setMethods(['isValueChanged', 'getPath', 'getScope', 'getOldValue']) + ->getMock(); + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->plugin = $this->objectManagerHelper->getObject( + BaseUrlConfigPlugin::class, + [ + 'subscriptionUpdateHandler' => $this->subscriptionUpdateHandlerMock, + ] + ); + } + + /** + * @param array $configValueData + * @return void + * @dataProvider afterSavePluginIsNotApplicableDataProvider + */ + public function testAfterSavePluginIsNotApplicable( + array $configValueData + ) { + $this->configValueMock + ->method('isValueChanged') + ->willReturn($configValueData['isValueChanged']); + $this->configValueMock + ->method('getPath') + ->willReturn($configValueData['path']); + $this->configValueMock + ->method('getScope') + ->willReturn($configValueData['scope']); + $this->subscriptionUpdateHandlerMock + ->expects($this->never()) + ->method('processUrlUpdate'); + + $this->assertEquals( + $this->configValueMock, + $this->plugin->afterAfterSave($this->configValueMock, $this->configValueMock) + ); + } + + /** + * @return array + */ + public function afterSavePluginIsNotApplicableDataProvider() + { + return [ + 'Value has not been changed' => [ + 'Config Value Data' => [ + 'isValueChanged' => false, + 'path' => Store::XML_PATH_SECURE_BASE_URL, + 'scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT + ], + ], + 'Unsecure URL has been changed' => [ + 'Config Value Data' => [ + 'isValueChanged' => true, + 'path' => Store::XML_PATH_UNSECURE_BASE_URL, + 'scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT + ], + ], + 'Secure URL has been changed not in the Default scope' => [ + 'Config Value Data' => [ + 'isValueChanged' => true, + 'path' => Store::XML_PATH_SECURE_BASE_URL, + 'scope' => ScopeInterface::SCOPE_STORES + ], + ], + ]; + } + + /** + * @return void + */ + public function testAfterSavePluginIsApplicable() + { + $this->configValueMock + ->method('isValueChanged') + ->willReturn(true); + $this->configValueMock + ->method('getPath') + ->willReturn(Store::XML_PATH_SECURE_BASE_URL); + $this->configValueMock + ->method('getScope') + ->willReturn(ScopeConfigInterface::SCOPE_TYPE_DEFAULT); + $this->configValueMock + ->method('getOldValue') + ->willReturn('http://store.com'); + $this->subscriptionUpdateHandlerMock + ->expects($this->once()) + ->method('processUrlUpdate') + ->with('http://store.com'); + + $this->assertEquals( + $this->configValueMock, + $this->plugin->afterAfterSave($this->configValueMock, $this->configValueMock) + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/ReportUrlProviderTest.php b/app/code/Magento/Analytics/Test/Unit/Model/ReportUrlProviderTest.php new file mode 100644 index 0000000000000..0607a977e5b68 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/ReportUrlProviderTest.php @@ -0,0 +1,149 @@ +configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->otpRequestMock = $this->getMockBuilder(OTPRequest::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->reportUrlProvider = $this->objectManagerHelper->getObject( + ReportUrlProvider::class, + [ + 'config' => $this->configMock, + 'analyticsToken' => $this->analyticsTokenMock, + 'otpRequest' => $this->otpRequestMock, + 'flagManager' => $this->flagManagerMock, + 'urlReportConfigPath' => $this->urlReportConfigPath, + ] + ); + } + + /** + * @param bool $isTokenExist + * @param string|null $otp If null OTP was not received. + * + * @dataProvider getUrlDataProvider + */ + public function testGetUrl($isTokenExist, $otp) + { + $reportUrl = 'https://example.com/report'; + $url = ''; + + $this->configMock + ->expects($this->once()) + ->method('getValue') + ->with($this->urlReportConfigPath) + ->willReturn($reportUrl); + $this->analyticsTokenMock + ->expects($this->once()) + ->method('isTokenExist') + ->with() + ->willReturn($isTokenExist); + $this->otpRequestMock + ->expects($isTokenExist ? $this->once() : $this->never()) + ->method('call') + ->with() + ->willReturn($otp); + if ($isTokenExist && $otp) { + $url = $reportUrl . '?' . http_build_query(['otp' => $otp], '', '&'); + } + $this->assertSame($url ?: $reportUrl, $this->reportUrlProvider->getUrl()); + } + + /** + * @return array + */ + public function getUrlDataProvider() + { + return [ + 'TokenDoesNotExist' => [false, null], + 'TokenExistAndOtpEmpty' => [true, null], + 'TokenExistAndOtpValid' => [true, '249e6b658877bde2a77bc4ab'], + ]; + } + + /** + * @return void + */ + public function testGetUrlWhenSubscriptionUpdateRunning() + { + $this->flagManagerMock + ->expects($this->once()) + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE) + ->willReturn('http://store.com'); + $this->expectException(SubscriptionUpdateException::class); + $this->reportUrlProvider->getUrl(); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/ReportWriterTest.php b/app/code/Magento/Analytics/Test/Unit/Model/ReportWriterTest.php new file mode 100644 index 0000000000000..d9b030b84d639 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/ReportWriterTest.php @@ -0,0 +1,213 @@ +configInterfaceMock = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass(); + $this->reportValidatorMock = $this->getMockBuilder(ReportValidator::class) + ->disableOriginalConstructor()->getMock(); + $this->providerFactoryMock = $this->getMockBuilder(ProviderFactory::class) + ->disableOriginalConstructor()->getMock(); + $this->reportProviderMock = $this->getMockBuilder(ReportProvider::class) + ->disableOriginalConstructor()->getMock(); + $this->directoryMock = $this->getMockBuilder(WriteInterface::class)->getMockForAbstractClass(); + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->reportWriter = $this->objectManagerHelper->getObject( + ReportWriter::class, + [ + 'config' => $this->configInterfaceMock, + 'reportValidator' => $this->reportValidatorMock, + 'providerFactory' => $this->providerFactoryMock + ] + ); + } + + /** + * @param array $configData + * @return void + * + * @dataProvider configDataProvider + */ + public function testWrite(array $configData) + { + $errors = []; + $fileData = [ + ['number' => 1, 'type' => 'Shoes Usual'] + ]; + $this->configInterfaceMock + ->expects($this->once()) + ->method('get') + ->with() + ->willReturn([$configData]); + $this->providerFactoryMock + ->expects($this->once()) + ->method('create') + ->with($this->providerClass) + ->willReturn($this->reportProviderMock); + $parameterName = isset(reset($configData)[0]['parameters']['name']) + ? reset($configData)[0]['parameters']['name'] + : ''; + $this->reportProviderMock->expects($this->once()) + ->method('getReport') + ->with($parameterName ?: null) + ->willReturn($fileData); + $errorStreamMock = $this->getMockBuilder( + \Magento\Framework\Filesystem\File\WriteInterface::class + )->getMockForAbstractClass(); + $errorStreamMock + ->expects($this->once()) + ->method('lock') + ->with(); + $errorStreamMock + ->expects($this->exactly(2)) + ->method('writeCsv') + ->withConsecutive( + [array_keys($fileData[0])], + [$fileData[0]] + ); + $errorStreamMock->expects($this->once())->method('unlock'); + $errorStreamMock->expects($this->once())->method('close'); + if ($parameterName) { + $this->reportValidatorMock + ->expects($this->once()) + ->method('validate') + ->with($parameterName) + ->willReturn($errors); + } + $this->directoryMock + ->expects($this->once()) + ->method('openFile') + ->with( + $this->stringContains('/var/tmp' . $parameterName ?: $this->reportName), + 'w+' + )->willReturn($errorStreamMock); + $this->assertTrue($this->reportWriter->write($this->directoryMock, '/var/tmp')); + } + + /** + * @param array $configData + * @return void + * + * @dataProvider configDataProvider + */ + public function testWriteErrorFile($configData) + { + $errors = ['orders', 'SQL Error: test']; + $this->configInterfaceMock->expects($this->once())->method('get')->willReturn([$configData]); + $errorStreamMock = $this->getMockBuilder( + \Magento\Framework\Filesystem\File\WriteInterface::class + )->getMockForAbstractClass(); + $errorStreamMock->expects($this->once())->method('lock'); + $errorStreamMock->expects($this->once())->method('writeCsv')->with($errors); + $errorStreamMock->expects($this->once())->method('unlock'); + $errorStreamMock->expects($this->once())->method('close'); + $this->reportValidatorMock->expects($this->once())->method('validate')->willReturn($errors); + $this->directoryMock->expects($this->once())->method('openFile')->with('/var/tmp' . 'errors.csv', 'w+') + ->willReturn($errorStreamMock); + $this->assertTrue($this->reportWriter->write($this->directoryMock, '/var/tmp')); + } + + /** + * @return void + */ + public function testWriteEmptyReports() + { + $this->configInterfaceMock->expects($this->once())->method('get')->willReturn([]); + $this->reportValidatorMock->expects($this->never())->method('validate'); + $this->directoryMock->expects($this->never())->method('openFile'); + $this->assertTrue($this->reportWriter->write($this->directoryMock, '/var/tmp')); + } + + /** + * @return array + */ + public function configDataProvider() + { + return [ + 'reportProvider' => [ + [ + 'providers' => [ + [ + 'name' => $this->providerName, + 'class' => $this->providerClass, + 'parameters' => [ + 'name' => $this->reportName + ], + ] + ] + ] + ], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/ReportXml/ModuleIteratorTest.php b/app/code/Magento/Analytics/Test/Unit/Model/ReportXml/ModuleIteratorTest.php new file mode 100644 index 0000000000000..f314d77f32b41 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/ReportXml/ModuleIteratorTest.php @@ -0,0 +1,50 @@ +moduleManagerMock = $this->getMockBuilder(ModuleManager::class) + ->disableOriginalConstructor() + ->getMock(); + $objectManagerHelper = new ObjectManagerHelper($this); + $this->moduleIterator = $objectManagerHelper->getObject( + ModuleIterator::class, + [ + 'moduleManager' => $this->moduleManagerMock, + 'iterator' => new \ArrayIterator([0 => ['module_name' => 'Coco_Module']]) + ] + ); + } + + public function testCurrent() + { + $this->moduleManagerMock->expects($this->once()) + ->method('isEnabled') + ->with('Coco_Module') + ->willReturn(true); + foreach ($this->moduleIterator as $item) { + $this->assertEquals(['module_name' => 'Coco_Module', 'status' => 'Enabled'], $item); + } + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/StoreConfigurationProviderTest.php b/app/code/Magento/Analytics/Test/Unit/Model/StoreConfigurationProviderTest.php new file mode 100644 index 0000000000000..cc46d175543ad --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/StoreConfigurationProviderTest.php @@ -0,0 +1,123 @@ +scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->websiteMock = $this->getMockBuilder(WebsiteInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->storeMock = $this->getMockBuilder(StoreInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->configPaths = [ + 'web/unsecure/base_url', + 'currency/options/base', + 'general/locale/timezone' + ]; + + $this->storeConfigurationProvider = new StoreConfigurationProvider( + $this->scopeConfigMock, + $this->storeManagerMock, + $this->configPaths + ); + } + + public function testGetReport() + { + $map = [ + ['web/unsecure/base_url', 'default', 0, '127.0.0.1'], + ['currency/options/base', 'default', 0, 'USD'], + ['general/locale/timezone', 'default', 0, 'America/Dawson'], + ['web/unsecure/base_url', 'websites', 1, '127.0.0.2'], + ['currency/options/base', 'websites', 1, 'USD'], + ['general/locale/timezone', 'websites', 1, 'America/Belem'], + ['web/unsecure/base_url', 'stores', 2, '127.0.0.3'], + ['currency/options/base', 'stores', 2, 'USD'], + ['general/locale/timezone', 'stores', 2, 'America/Phoenix'], + ]; + + $this->scopeConfigMock + ->method('getValue') + ->will($this->returnValueMap($map)); + + $this->storeManagerMock->expects($this->once()) + ->method('getWebsites') + ->willReturn([$this->websiteMock]); + + $this->storeManagerMock->expects($this->once()) + ->method('getStores') + ->willReturn([$this->storeMock]); + + $this->websiteMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $this->storeMock->expects($this->once()) + ->method('getId') + ->willReturn(2); + $result = iterator_to_array($this->storeConfigurationProvider->getReport()); + $resultValues = []; + foreach ($result as $item) { + $resultValues[] = array_values($item); + } + array_multisort($resultValues); + array_multisort($map); + $this->assertEquals($resultValues, $map); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/SubscriptionStatusProviderTest.php b/app/code/Magento/Analytics/Test/Unit/Model/SubscriptionStatusProviderTest.php new file mode 100644 index 0000000000000..d6b041ce03178 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/SubscriptionStatusProviderTest.php @@ -0,0 +1,196 @@ +scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->getMockForAbstractClass(); + + $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->flagManagerMock = $this->getMockBuilder(FlagManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->statusProvider = $this->objectManagerHelper->getObject( + SubscriptionStatusProvider::class, + [ + 'scopeConfig' => $this->scopeConfigMock, + 'analyticsToken' => $this->analyticsTokenMock, + 'flagManager' => $this->flagManagerMock, + ] + ); + } + + /** + * @param array $flagManagerData + * @dataProvider getStatusShouldBeFailedDataProvider + */ + public function testGetStatusShouldBeFailed(array $flagManagerData) + { + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(false); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with('analytics/subscription/enabled') + ->willReturn(true); + + $this->expectFlagManagerReturn($flagManagerData); + $this->assertEquals(SubscriptionStatusProvider::FAILED, $this->statusProvider->getStatus()); + } + + /** + * @return array + */ + public function getStatusShouldBeFailedDataProvider() + { + return [ + 'Subscription update doesn\'t active' => [ + 'Flag Manager data mapping' => [ + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, null], + [SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, null] + ], + ], + 'Subscription update is active' => [ + 'Flag Manager data mapping' => [ + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, 'http://store.com'], + [SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, null] + ], + ], + ]; + } + + /** + * @param array $flagManagerData + * @param bool $isTokenExist + * @dataProvider getStatusShouldBePendingDataProvider + */ + public function testGetStatusShouldBePending(array $flagManagerData, bool $isTokenExist) + { + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn($isTokenExist); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with('analytics/subscription/enabled') + ->willReturn(true); + + $this->expectFlagManagerReturn($flagManagerData); + $this->assertEquals(SubscriptionStatusProvider::PENDING, $this->statusProvider->getStatus()); + } + + /** + * @return array + */ + public function getStatusShouldBePendingDataProvider() + { + return [ + 'Subscription update doesn\'t active and the token does not exist' => [ + 'Flag Manager data mapping' => [ + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, null], + [SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, 45] + ], + 'isTokenExist' => false, + ], + 'Subscription update is active and the token does not exist' => [ + 'Flag Manager data mapping' => [ + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, 'http://store.com'], + [SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, 45] + ], + 'isTokenExist' => false, + ], + 'Subscription update is active and token exist' => [ + 'Flag Manager data mapping' => [ + [SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE, 'http://store.com'], + [SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, null] + ], + 'isTokenExist' => true, + ], + ]; + } + + public function testGetStatusShouldBeEnabled() + { + $this->flagManagerMock + ->method('getFlagData') + ->with(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE) + ->willReturn(null); + $this->analyticsTokenMock->expects($this->once()) + ->method('isTokenExist') + ->willReturn(true); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with('analytics/subscription/enabled') + ->willReturn(true); + $this->assertEquals(SubscriptionStatusProvider::ENABLED, $this->statusProvider->getStatus()); + } + + public function testGetStatusShouldBeDisabled() + { + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with('analytics/subscription/enabled') + ->willReturn(false); + $this->assertEquals(SubscriptionStatusProvider::DISABLED, $this->statusProvider->getStatus()); + } + + /** + * @param array $mapping + */ + private function expectFlagManagerReturn(array $mapping) + { + $this->flagManagerMock + ->method('getFlagData') + ->willReturnMap($mapping); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/Model/System/Message/NotificationAboutFailedSubscriptionTest.php b/app/code/Magento/Analytics/Test/Unit/Model/System/Message/NotificationAboutFailedSubscriptionTest.php new file mode 100644 index 0000000000000..ad1d87488d751 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/Model/System/Message/NotificationAboutFailedSubscriptionTest.php @@ -0,0 +1,106 @@ +subscriptionStatusMock = $this->getMockBuilder(SubscriptionStatusProvider::class) + ->disableOriginalConstructor() + ->getMock(); + $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class) + ->getMockForAbstractClass(); + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->notification = $this->objectManagerHelper->getObject( + NotificationAboutFailedSubscription::class, + [ + 'subscriptionStatusProvider' => $this->subscriptionStatusMock, + 'urlBuilder' => $this->urlBuilderMock + ] + ); + } + + public function testIsDisplayedWhenMessageShouldBeDisplayed() + { + $this->subscriptionStatusMock->expects($this->once()) + ->method('getStatus') + ->willReturn( + SubscriptionStatusProvider::FAILED + ); + $this->assertTrue($this->notification->isDisplayed()); + } + + /** + * @dataProvider notDisplayedNotificationStatuses + * + * @param $status + */ + public function testIsDisplayedWhenMessageShouldNotBeDisplayed($status) + { + $this->subscriptionStatusMock->expects($this->once()) + ->method('getStatus') + ->willReturn($status); + $this->assertFalse($this->notification->isDisplayed()); + } + + public function testGetTextShouldBuildMessage() + { + $retryUrl = 'http://magento.dev/retryUrl'; + $this->urlBuilderMock->expects($this->once()) + ->method('getUrl') + ->with('analytics/subscription/retry') + ->willReturn($retryUrl); + $messageDetails = 'Failed to synchronize data to the Magento Business Intelligence service. '; + $messageDetails .= sprintf('Retry Synchronization', $retryUrl); + $this->assertEquals($messageDetails, $this->notification->getText()); + } + + /** + * Provide statuses according to which message should not be displayed. + * + * @return array + */ + public function notDisplayedNotificationStatuses() + { + return [ + [SubscriptionStatusProvider::PENDING], + [SubscriptionStatusProvider::DISABLED], + [SubscriptionStatusProvider::ENABLED], + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/Converter/XmlTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/Converter/XmlTest.php new file mode 100644 index 0000000000000..3f1ed9a5cf4c0 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/Converter/XmlTest.php @@ -0,0 +1,121 @@ +objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\ReportXml\Config\Converter\Xml::class + ); + } + + /** + * @return void + */ + public function testConvertNoElements() + { + $this->assertEmpty( + $this->subject->convert(new \DOMDocument()) + ); + } + + /** + * @return void + */ + public function testConvert() + { + $dom = new \DOMDocument(); + + $expectedArray = [ + 'config' => [ + [ + 'noNamespaceSchemaLocation' => 'urn:magento:module:Magento_Analytics:etc/reports.xsd', + 'report' => [ + [ + 'name' => 'test_report_1', + 'connection' => 'sales', + 'source' => [ + [ + 'name' => 'sales_order', + 'alias' => 'orders', + 'attribute' => [ + [ + 'name' => 'entity_id', + 'alias' => 'identifier', + ] + ], + 'filter' => [ + [ + 'glue' => 'and', + 'condition' => [ + [ + 'attribute' => 'entity_id', + 'operator' => 'gt', + '_value' => '10' + ] + ] + ] + ] + ] + ] + ], + [ + 'name' => 'test_report_2', + 'connection' => 'default', + 'source' => [ + [ + 'name' => 'customer_entity', + 'alias' => 'customers', + 'attribute' => [ + [ + 'name' => 'email' + ] + ], + 'filter' => [ + [ + 'glue' => 'and', + 'condition' => [ + [ + 'attribute' => 'dob', + 'operator' => 'null' + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ]; + + $dom->loadXML(file_get_contents(__DIR__ . '/../_files/valid_reports.xml')); + + $this->assertEquals($expectedArray, $this->subject->convert($dom)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/MapperTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/MapperTest.php new file mode 100644 index 0000000000000..85343b6b301d6 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/MapperTest.php @@ -0,0 +1,47 @@ +mapper = new Mapper(); + } + + public function testExecute() + { + $configData['config'][0]['report'] = [ + [ + 'source' => ['product'], + 'name' => 'Product', + ] + ]; + $expectedResult = [ + 'Product' => [ + 'source' => 'product', + 'name' => 'Product', + ] + ]; + $this->assertEquals($this->mapper->execute($configData), $expectedResult); + } + + public function testExecuteWithoutReports() + { + $configData = []; + $this->assertEquals($this->mapper->execute($configData), []); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/_files/valid_reports.xml b/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/_files/valid_reports.xml new file mode 100644 index 0000000000000..e04ee96163797 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/Config/_files/valid_reports.xml @@ -0,0 +1,25 @@ + + + + + + + + 10 + + + + + + + + + + + + diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/ConfigTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/ConfigTest.php new file mode 100644 index 0000000000000..cbc9aa129d874 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/ConfigTest.php @@ -0,0 +1,64 @@ +dataMock = $this->getMockBuilder(DataInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->config = $this->objectManagerHelper->getObject( + Config::class, + [ + 'data' => $this->dataMock, + ] + ); + } + + public function testGet() + { + $queryName = 'query string'; + $queryResult = [ 'query' => 1 ]; + + $this->dataMock + ->expects($this->once()) + ->method('get') + ->with($queryName) + ->willReturn($queryResult); + + $this->assertSame($queryResult, $this->config->get($queryName)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/ConnectionFactoryTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/ConnectionFactoryTest.php new file mode 100644 index 0000000000000..1e4ae9142c13d --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/ConnectionFactoryTest.php @@ -0,0 +1,106 @@ +resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionMock = $this->getMockBuilder(MysqlPdoAdapter::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionNewMock = $this->getMockBuilder(MysqlPdoAdapter::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->connectionFactory = $this->objectManagerHelper->getObject( + ConnectionFactory::class, + [ + 'resourceConnection' => $this->resourceConnectionMock, + 'objectManager' => $this->objectManagerMock, + ] + ); + } + + public function testGetConnection() + { + $connectionName = 'read'; + + $this->resourceConnectionMock + ->expects($this->once()) + ->method('getConnection') + ->with($connectionName) + ->willReturn($this->connectionMock); + + $this->connectionMock + ->expects($this->once()) + ->method('getConfig') + ->with() + ->willReturn(['persistent' => 1]); + + $this->objectManagerMock + ->expects($this->once()) + ->method('create') + ->with(get_class($this->connectionMock), ['config' => ['use_buffered_query' => false]]) + ->willReturn($this->connectionNewMock); + + $this->assertSame($this->connectionNewMock, $this->connectionFactory->getConnection($connectionName)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/FilterAssemblerTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/FilterAssemblerTest.php new file mode 100644 index 0000000000000..3b01105a8873b --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/FilterAssemblerTest.php @@ -0,0 +1,143 @@ +nameResolverMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\NameResolver::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectBuilderMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\SelectBuilder::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->selectBuilderMock->expects($this->any()) + ->method('getFilters') + ->willReturn([]); + + $this->conditionResolverMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\ConditionResolver::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\ReportXml\DB\Assembler\FilterAssembler::class, + [ + 'conditionResolver' => $this->conditionResolverMock, + 'nameResolver' => $this->nameResolverMock + ] + ); + } + + /** + * @return void + */ + public function testAssembleEmpty() + { + $queryConfigMock = [ + 'source' => [ + 'name' => 'sales_order', + 'alias' => 'sales' + ] + ]; + + $this->selectBuilderMock->expects($this->never()) + ->method('setFilters'); + + $this->assertEquals( + $this->selectBuilderMock, + $this->subject->assemble($this->selectBuilderMock, $queryConfigMock) + ); + } + + /** + * @return void + */ + public function testAssembleNotEmpty() + { + $queryConfigMock = [ + 'source' => [ + 'name' => 'sales_order', + 'alias' => 'sales', + 'filter' => [ + [ + 'glue' => 'and', + 'condition' => [ + [ + 'attribute' => 'entity_id', + 'operator' => 'null' + ] + ] + ] + ] + ] + ]; + + $this->nameResolverMock->expects($this->any()) + ->method('getAlias') + ->with($queryConfigMock['source']) + ->willReturn($queryConfigMock['source']['alias']); + + $this->conditionResolverMock->expects($this->once()) + ->method('getFilter') + ->with( + $this->selectBuilderMock, + $queryConfigMock['source']['filter'], + $queryConfigMock['source']['alias'] + ) + ->willReturn('(sales.entity_id IS NULL)'); + + $this->selectBuilderMock->expects($this->once()) + ->method('setFilters') + ->with(['(sales.entity_id IS NULL)']); + + $this->assertEquals( + $this->selectBuilderMock, + $this->subject->assemble($this->selectBuilderMock, $queryConfigMock) + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/FromAssemblerTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/FromAssemblerTest.php new file mode 100644 index 0000000000000..575db94a7b7e1 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/FromAssemblerTest.php @@ -0,0 +1,167 @@ +nameResolverMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\NameResolver::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectBuilderMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\SelectBuilder::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->selectBuilderMock->expects($this->any()) + ->method('getColumns') + ->willReturn([]); + + $this->columnsResolverMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\ColumnsResolver::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->resourceConnection = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\ReportXml\DB\Assembler\FromAssembler::class, + [ + 'nameResolver' => $this->nameResolverMock, + 'columnsResolver' => $this->columnsResolverMock, + 'resourceConnection' => $this->resourceConnection, + ] + ); + } + + /** + * @dataProvider assembleDataProvider + * @param array $queryConfig + * @param string $tableName + * @return void + */ + public function testAssemble(array $queryConfig, $tableName) + { + $this->nameResolverMock->expects($this->any()) + ->method('getAlias') + ->with($queryConfig['source']) + ->willReturn($queryConfig['source']['alias']); + + $this->nameResolverMock->expects($this->once()) + ->method('getName') + ->with($queryConfig['source']) + ->willReturn($queryConfig['source']['name']); + + $this->resourceConnection + ->expects($this->once()) + ->method('getTableName') + ->with($queryConfig['source']['name']) + ->willReturn($tableName); + + $this->selectBuilderMock->expects($this->once()) + ->method('setFrom') + ->with([$queryConfig['source']['alias'] => $tableName]); + + $this->columnsResolverMock->expects($this->once()) + ->method('getColumns') + ->with($this->selectBuilderMock, $queryConfig['source']) + ->willReturn(['entity_id' => 'sales.entity_id']); + + $this->selectBuilderMock->expects($this->once()) + ->method('setColumns') + ->with(['entity_id' => 'sales.entity_id']); + + $this->assertEquals( + $this->selectBuilderMock, + $this->subject->assemble($this->selectBuilderMock, $queryConfig) + ); + } + + /** + * @return array + */ + public function assembleDataProvider() + { + return [ + 'Tables without prefixes' => [ + [ + 'source' => [ + 'name' => 'sales_order', + 'alias' => 'sales', + 'attribute' => [ + [ + 'name' => 'entity_id' + ] + ], + ], + ], + 'sales_order', + ], + 'Tables with prefixes' => [ + [ + 'source' => [ + 'name' => 'sales_order', + 'alias' => 'sales', + 'attribute' => [ + [ + 'name' => 'entity_id' + ] + ], + ], + ], + 'pref_sales_order', + ] + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/JoinAssemblerTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/JoinAssemblerTest.php new file mode 100644 index 0000000000000..aaafd731552a0 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/Assembler/JoinAssemblerTest.php @@ -0,0 +1,279 @@ +nameResolverMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\NameResolver::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectBuilderMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\SelectBuilder::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->selectBuilderMock->expects($this->any()) + ->method('getFilters') + ->willReturn([]); + $this->selectBuilderMock->expects($this->any()) + ->method('getColumns') + ->willReturn([]); + $this->selectBuilderMock->expects($this->any()) + ->method('getJoins') + ->willReturn([]); + + $this->columnsResolverMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\ColumnsResolver::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->conditionResolverMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\ConditionResolver::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->resourceConnection = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\ReportXml\DB\Assembler\JoinAssembler::class, + [ + 'conditionResolver' => $this->conditionResolverMock, + 'nameResolver' => $this->nameResolverMock, + 'columnsResolver' => $this->columnsResolverMock, + 'resourceConnection' => $this->resourceConnection, + ] + ); + } + + /** + * @return void + */ + public function testAssembleEmpty() + { + $queryConfigMock = [ + 'source' => [ + 'name' => 'sales_order', + 'alias' => 'sales' + ] + ]; + + $this->selectBuilderMock->expects($this->never()) + ->method('setColumns'); + $this->selectBuilderMock->expects($this->never()) + ->method('setFilters'); + $this->selectBuilderMock->expects($this->never()) + ->method('setJoins'); + + $this->assertEquals( + $this->selectBuilderMock, + $this->subject->assemble($this->selectBuilderMock, $queryConfigMock) + ); + } + + /** + * @param array $queryConfigMock + * @param array $joinsMock + * @param array $tablesMapping + * @return void + * @dataProvider assembleNotEmptyDataProvider + */ + public function testAssembleNotEmpty(array $queryConfigMock, array $joinsMock, array $tablesMapping) + { + $filtersMock = []; + + $this->nameResolverMock->expects($this->at(0)) + ->method('getAlias') + ->with($queryConfigMock['source']) + ->willReturn($queryConfigMock['source']['alias']); + $this->nameResolverMock->expects($this->at(1)) + ->method('getAlias') + ->with($queryConfigMock['source']['link-source'][0]) + ->willReturn($queryConfigMock['source']['link-source'][0]['alias']); + $this->nameResolverMock->expects($this->once()) + ->method('getName') + ->with($queryConfigMock['source']['link-source'][0]) + ->willReturn($queryConfigMock['source']['link-source'][0]['name']); + + $this->resourceConnection + ->expects($this->any()) + ->method('getTableName') + ->willReturnOnConsecutiveCalls(...array_values($tablesMapping)); + + $this->conditionResolverMock->expects($this->at(0)) + ->method('getFilter') + ->with( + $this->selectBuilderMock, + $queryConfigMock['source']['link-source'][0]['using'], + $queryConfigMock['source']['link-source'][0]['alias'], + $queryConfigMock['source']['alias'] + ) + ->willReturn('(billing.parent_id = `sales`.`entity_id`)'); + + if (isset($queryConfigMock['source']['link-source'][0]['filter'])) { + $filtersMock = ['(sales.entity_id IS NULL)']; + + $this->conditionResolverMock->expects($this->at(1)) + ->method('getFilter') + ->with( + $this->selectBuilderMock, + $queryConfigMock['source']['link-source'][0]['filter'], + $queryConfigMock['source']['link-source'][0]['alias'], + $queryConfigMock['source']['alias'] + ) + ->willReturn($filtersMock[0]); + + $this->columnsResolverMock->expects($this->once()) + ->method('getColumns') + ->with($this->selectBuilderMock, $queryConfigMock['source']['link-source'][0]) + ->willReturn( + [ + 'entity_id' => 'sales.entity_id', + 'billing_address_id' => 'billing.entity_id' + ] + ); + + $this->selectBuilderMock->expects($this->once()) + ->method('setColumns') + ->with( + [ + 'entity_id' => 'sales.entity_id', + 'billing_address_id' => 'billing.entity_id' + ] + ); + } + + $this->selectBuilderMock->expects($this->once()) + ->method('setFilters') + ->with($filtersMock); + $this->selectBuilderMock->expects($this->once()) + ->method('setJoins') + ->with($joinsMock); + + $this->assertEquals( + $this->selectBuilderMock, + $this->subject->assemble($this->selectBuilderMock, $queryConfigMock) + ); + } + + /** + * @return array + */ + public function assembleNotEmptyDataProvider() + { + return [ + [ + [ + 'source' => [ + 'name' => 'sales_order', + 'alias' => 'sales', + 'link-source' => [ + [ + 'name' => 'sales_order_address', + 'alias' => 'billing', + 'link-type' => 'left', + 'attribute' => [ + [ + 'alias' => 'billing_address_id', + 'name' => 'entity_id' + ] + ], + 'using' => [ + [ + 'glue' => 'and', + 'condition' => [ + [ + 'attribute' => 'parent_id', + 'operator' => 'eq', + 'type' => 'identifier', + '_value' => 'entity_id' + ] + ] + ] + ], + 'filter' => [ + [ + 'glue' => 'and', + 'condition' => [ + [ + 'attribute' => 'entity_id', + 'operator' => 'null' + ] + ] + ] + ] + ] + ] + ] + ], + [ + 'billing' => [ + 'link-type' => 'left', + 'table' => [ + 'billing' => 'pref_sales_order_address' + ], + 'condition' => '(billing.parent_id = `sales`.`entity_id`)' + ] + ], + ['sales_order_address' => 'pref_sales_order_address'] + ] + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ColumnsResolverTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ColumnsResolverTest.php new file mode 100644 index 0000000000000..bdbe3d1d22c22 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ColumnsResolverTest.php @@ -0,0 +1,150 @@ +selectBuilderMock = $this->getMockBuilder(SelectBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new ObjectManagerHelper($this); + $this->columnsResolver = $objectManager->getObject( + ColumnsResolver::class, + [ + 'nameResolver' => new NameResolver(), + 'resourceConnection' => $this->resourceConnectionMock + ] + ); + } + + public function testGetColumnsWithoutAttributes() + { + $this->assertEquals($this->columnsResolver->getColumns($this->selectBuilderMock, []), []); + } + + /** + * @dataProvider getColumnsDataProvider + */ + public function testGetColumnsWithFunction($expectedColumns, $expectedGroup, $entityConfig) + { + $this->resourceConnectionMock->expects($this->any()) + ->method('getConnection') + ->willReturn($this->connectionMock); + $this->connectionMock->expects($this->any()) + ->method('quoteIdentifier') + ->with('cpe.name') + ->willReturn('`cpe`.`name`'); + $this->selectBuilderMock->expects($this->once()) + ->method('getColumns') + ->willReturn([]); + $this->selectBuilderMock->expects($this->once()) + ->method('getGroup') + ->willReturn([]); + $this->selectBuilderMock->expects($this->once()) + ->method('setGroup') + ->with($expectedGroup); + $this->assertEquals( + $expectedColumns, + $this->columnsResolver->getColumns( + $this->selectBuilderMock, + $entityConfig + ) + ); + } + + /** + * @return array + */ + public function getColumnsDataProvider() + { + return [ + 'COUNT( DISTINCT `cpe`.`name`) AS name' => [ + 'expectedColumns' => [ + 'name' => new ColumnValueExpression('COUNT( DISTINCT `cpe`.`name`)') + ], + 'expectedGroup' => [ + 'name' => new ColumnValueExpression('COUNT( DISTINCT `cpe`.`name`)') + ], + 'entityConfig' => + [ + 'name' => 'catalog_product_entity', + 'alias' => 'cpe', + 'attribute' => [ + [ + 'name' => 'name', + 'function' => 'COUNT', + 'distinct' => true, + 'group' => true + ] + ], + ], + ], + 'AVG(`cpe`.`name`) AS avg_name' => [ + 'expectedColumns' => [ + 'avg_name' => new ColumnValueExpression('AVG(`cpe`.`name`)') + ], + 'expectedGroup' => [], + 'entityConfig' => + [ + 'name' => 'catalog_product_entity', + 'alias' => 'cpe', + 'attribute' => [ + [ + 'name' => 'name', + 'alias' => 'avg_name', + 'function' => 'AVG', + ] + ], + ], + ] + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ConditionResolverTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ConditionResolverTest.php new file mode 100644 index 0000000000000..c8182d068fba5 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ConditionResolverTest.php @@ -0,0 +1,108 @@ +resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectBuilderMock = $this->getMockBuilder(SelectBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->conditionResolver = new ConditionResolver($this->resourceConnectionMock); + } + + public function testGetFilter() + { + $condition = ["type" => "variable", "_value" => "1", "attribute" => "id", "operator" => "neq"]; + $valueCondition = ["type" => "value", "_value" => "2", "attribute" => "first_name", "operator" => "eq"]; + $identifierCondition = [ + "type" => "identifier", + "_value" => "other_field", + "attribute" => "last_name", + "operator" => "eq"]; + $filter = [["glue" => "AND", "condition" => [$valueCondition]]]; + $filterConfig = [ + ["glue" => "OR", "condition" => [$condition], 'filter' => $filter], + ["glue" => "OR", "condition" => [$identifierCondition]], + ]; + $aliasName = 'n'; + $this->selectBuilderMock->expects($this->any()) + ->method('setParams') + ->with(array_merge([], [$condition['_value']])); + + $this->selectBuilderMock->expects($this->once()) + ->method('getParams') + ->willReturn([]); + + $this->selectBuilderMock->expects($this->any()) + ->method('getColumns') + ->willReturn(['price' => new Expression("(n.price = 400)")]); + + $this->resourceConnectionMock->expects($this->once()) + ->method('getConnection') + ->willReturn($this->connectionMock); + + $this->connectionMock->expects($this->any()) + ->method('quote') + ->willReturn("'John'"); + $this->connectionMock->expects($this->exactly(4)) + ->method('quoteIdentifier') + ->willReturnMap([ + ['n.id', false, '`n`.`id`'], + ['n.first_name', false, '`n`.`first_name`'], + ['n.last_name', false, '`n`.`last_name`'], + ['other_field', false, '`other_field`'], + ]); + + $result = "(`n`.`id` != 1 OR ((`n`.`first_name` = 'John'))) OR (`n`.`last_name` = `other_field`)"; + $this->assertEquals( + $result, + $this->conditionResolver->getFilter($this->selectBuilderMock, $filterConfig, $aliasName) + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/NameResolverTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/NameResolverTest.php new file mode 100644 index 0000000000000..4accd03aef3ea --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/NameResolverTest.php @@ -0,0 +1,90 @@ +nameResolverMock = $this->getMockBuilder(NameResolver::class) + ->disableOriginalConstructor() + ->setMethods(['getName']) + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->nameResolver = $this->objectManagerHelper->getObject(NameResolver::class); + } + + public function testGetName() + { + $elementConfigMock = [ + 'name' => 'sales_order', + 'alias' => 'sales', + ]; + + $this->assertSame('sales_order', $this->nameResolver->getName($elementConfigMock)); + } + + /** + * @param array $elementConfig + * @param string|null $elementAlias + * + * @dataProvider getAliasDataProvider + */ + public function testGetAlias($elementConfig, $elementAlias) + { + $elementName = 'elementName'; + + $this->nameResolverMock + ->expects($this->once()) + ->method('getName') + ->with($elementConfig) + ->willReturn($elementName); + + $this->assertSame($elementAlias ?: $elementName, $this->nameResolverMock->getAlias($elementConfig)); + } + + /** + * @return array + */ + public function getAliasDataProvider() + { + return [ + 'ElementConfigWithAliases' => [ + ['alias' => 'sales', 'name' => 'sales_order'], + 'sales', + ], + 'ElementConfigWithoutAliases' => [ + ['name' => 'sales_order'], + null, + ] + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ReportValidatorTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ReportValidatorTest.php new file mode 100644 index 0000000000000..bbb9ca4b511b6 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/ReportValidatorTest.php @@ -0,0 +1,125 @@ +connectionFactoryMock = $this->getMockBuilder(ConnectionFactory::class) + ->disableOriginalConstructor()->getMock(); + $this->queryFactoryMock = $this->getMockBuilder(QueryFactory::class) + ->disableOriginalConstructor()->getMock(); + $this->queryMock = $this->getMockBuilder(Query::class)->disableOriginalConstructor() + ->getMock(); + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass(); + $this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor() + ->getMock(); + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->reportValidator = $this->objectManagerHelper->getObject( + ReportValidator::class, + [ + 'connectionFactory' => $this->connectionFactoryMock, + 'queryFactory' => $this->queryFactoryMock + ] + ); + } + + /** + * @dataProvider errorDataProvider + * @param string $reportName + * @param array $result + * @param \PHPUnit_Framework_MockObject_Stub $queryReturnStub + */ + public function testValidate($reportName, $result, \PHPUnit_Framework_MockObject_Stub $queryReturnStub) + { + $connectionName = 'testConnection'; + $this->queryFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->queryMock); + $this->queryMock->expects($this->once())->method('getConnectionName')->willReturn($connectionName); + $this->connectionFactoryMock->expects($this->once())->method('getConnection') + ->with($connectionName) + ->willReturn($this->connectionMock); + $this->queryMock->expects($this->atLeastOnce())->method('getSelect')->willReturn($this->selectMock); + $this->selectMock->expects($this->once())->method('limit')->with(0); + $this->connectionMock->expects($this->once())->method('query')->with($this->selectMock)->will($queryReturnStub); + $this->assertEquals($result, $this->reportValidator->validate($reportName)); + } + + /** + * Provide variations of the error returning + * + * @return array + */ + public function errorDataProvider() + { + $reportName = 'test'; + $errorMessage = 'SQL Error 42'; + return [ + [ + $reportName, + 'expectedResult' => [], + 'queryReturnStub' => $this->returnValue(null) + ], + [ + $reportName, + 'expectedResult' => [$reportName, $errorMessage], + 'queryReturnStub' => $this->throwException(new \Zend_Db_Statement_Exception($errorMessage)) + ] + ]; + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/SelectBuilderTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/SelectBuilderTest.php new file mode 100644 index 0000000000000..a82a187cdb3f8 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/DB/SelectBuilderTest.php @@ -0,0 +1,103 @@ +resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectMock = $this->getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectBuilder = new SelectBuilder($this->resourceConnectionMock); + } + + public function testCreate() + { + $connectionName = 'MySql'; + $from = ['customer c']; + $columns = ['id', 'name', 'price']; + $filter = 'filter'; + $joins = [ + ['link-type' => 'left', 'table' => 'customer', 'condition' => 'in'], + ['link-type' => 'inner', 'table' => 'price', 'condition' => 'eq'], + ['link-type' => 'right', 'table' => 'attribute', 'condition' => 'neq'], + ]; + $groups = ['id', 'name']; + $this->selectBuilder->setConnectionName($connectionName); + $this->selectBuilder->setFrom($from); + $this->selectBuilder->setColumns($columns); + $this->selectBuilder->setFilters([$filter]); + $this->selectBuilder->setJoins($joins); + $this->selectBuilder->setGroup($groups); + $this->resourceConnectionMock->expects($this->once()) + ->method('getConnection') + ->with($connectionName) + ->willReturn($this->connectionMock); + $this->connectionMock->expects($this->once()) + ->method('select') + ->willReturn($this->selectMock); + $this->selectMock->expects($this->once()) + ->method('from') + ->with($from, []); + $this->selectMock->expects($this->once()) + ->method('columns') + ->with($columns); + $this->selectMock->expects($this->once()) + ->method('where') + ->with($filter); + $this->selectMock->expects($this->once()) + ->method('joinLeft') + ->with($joins[0]['table'], $joins[0]['condition'], []); + $this->selectMock->expects($this->once()) + ->method('joinInner') + ->with($joins[1]['table'], $joins[1]['condition'], []); + $this->selectMock->expects($this->once()) + ->method('joinRight') + ->with($joins[2]['table'], $joins[2]['condition'], []); + $this->selectBuilder->create(); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/IteratorFactoryTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/IteratorFactoryTest.php new file mode 100644 index 0000000000000..1d3f293ed676a --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/IteratorFactoryTest.php @@ -0,0 +1,59 @@ +objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->iteratorIteratorMock = $this->getMockBuilder(\IteratorIterator::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->iteratorFactory = new IteratorFactory( + $this->objectManagerMock + ); + } + + public function testCreate() + { + $arrayObject = new \ArrayIterator([1, 2, 3, 4, 5]); + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with(\IteratorIterator::class, ['iterator' => $arrayObject]) + ->willReturn($this->iteratorIteratorMock); + + $this->assertEquals($this->iteratorFactory->create($arrayObject), $this->iteratorIteratorMock); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/QueryFactoryTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/QueryFactoryTest.php new file mode 100644 index 0000000000000..9a3805a50f167 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/QueryFactoryTest.php @@ -0,0 +1,239 @@ +queryMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\Query::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->configMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\Config::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectMock = $this->getMockBuilder( + \Magento\Framework\DB\Select::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assemblerMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\Assembler\AssemblerInterface::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->queryCacheMock = $this->getMockBuilder( + \Magento\Framework\App\CacheInterface::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerMock = $this->getMockBuilder( + \Magento\Framework\ObjectManagerInterface::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectHydratorMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\SelectHydrator::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectBuilderFactoryMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\SelectBuilderFactory::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\ReportXml\QueryFactory::class, + [ + 'config' => $this->configMock, + 'selectBuilderFactory' => $this->selectBuilderFactoryMock, + 'assemblers' => [$this->assemblerMock], + 'queryCache' => $this->queryCacheMock, + 'objectManager' => $this->objectManagerMock, + 'selectHydrator' => $this->selectHydratorMock + ] + ); + } + + /** + * @return void + */ + public function testCreateCached() + { + $queryName = 'test_query'; + + $this->queryCacheMock->expects($this->any()) + ->method('load') + ->with($queryName) + ->willReturn('{"connectionName":"sales","config":{},"select_parts":{}}'); + + $this->selectHydratorMock->expects($this->any()) + ->method('recreate') + ->with([]) + ->willReturn($this->selectMock); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with( + \Magento\Analytics\ReportXml\Query::class, + [ + 'select' => $this->selectMock, + 'selectHydrator' => $this->selectHydratorMock, + 'connectionName' => 'sales', + 'config' => [] + ] + ) + ->willReturn($this->queryMock); + + $this->queryCacheMock->expects($this->never()) + ->method('save'); + + $this->assertEquals( + $this->queryMock, + $this->subject->create($queryName) + ); + } + + /** + * @return void + */ + public function testCreateNotCached() + { + $queryName = 'test_query'; + + $queryConfigMock = [ + 'name' => 'test_query', + 'connection' => 'sales' + ]; + + $selectBuilderMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\DB\SelectBuilder::class + ) + ->disableOriginalConstructor() + ->getMock(); + $selectBuilderMock->expects($this->once()) + ->method('setConnectionName') + ->with($queryConfigMock['connection']); + $selectBuilderMock->expects($this->any()) + ->method('create') + ->willReturn($this->selectMock); + $selectBuilderMock->expects($this->any()) + ->method('getConnectionName') + ->willReturn($queryConfigMock['connection']); + + $this->queryCacheMock->expects($this->any()) + ->method('load') + ->with($queryName) + ->willReturn(null); + + $this->configMock->expects($this->any()) + ->method('get') + ->with($queryName) + ->willReturn($queryConfigMock); + + $this->selectBuilderFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($selectBuilderMock); + + $this->assemblerMock->expects($this->once()) + ->method('assemble') + ->with($selectBuilderMock, $queryConfigMock) + ->willReturn($selectBuilderMock); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with( + \Magento\Analytics\ReportXml\Query::class, + [ + 'select' => $this->selectMock, + 'selectHydrator' => $this->selectHydratorMock, + 'connectionName' => $queryConfigMock['connection'], + 'config' => $queryConfigMock + ] + ) + ->willReturn($this->queryMock); + + $this->queryCacheMock->expects($this->once()) + ->method('save') + ->with(json_encode($this->queryMock), $queryName); + + $this->assertEquals( + $this->queryMock, + $this->subject->create($queryName) + ); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/QueryTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/QueryTest.php new file mode 100644 index 0000000000000..a4b08a9ce5e0a --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/QueryTest.php @@ -0,0 +1,90 @@ +selectMock = $this->getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectHydratorMock = $this->getMockBuilder(selectHydrator::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->query = $this->objectManagerHelper->getObject( + Query::class, + [ + 'select' => $this->selectMock, + 'connectionName' => $this->connectionName, + 'selectHydrator' => $this->selectHydratorMock, + 'config' => [] + ] + ); + } + + /** + * @return void + */ + public function testJsonSerialize() + { + $selectParts = ['part' => 1]; + + $this->selectHydratorMock + ->expects($this->once()) + ->method('extract') + ->with($this->selectMock) + ->willReturn($selectParts); + + $expectedResult = [ + 'connectionName' => $this->connectionName, + 'select_parts' => $selectParts, + 'config' => [] + ]; + + $this->assertSame($expectedResult, $this->query->jsonSerialize()); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/ReportProviderTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/ReportProviderTest.php new file mode 100644 index 0000000000000..5f329993dd291 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/ReportProviderTest.php @@ -0,0 +1,180 @@ +selectMock = $this->getMockBuilder( + \Magento\Framework\DB\Select::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->queryMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\Query::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->queryMock->expects($this->any()) + ->method('getSelect') + ->willReturn($this->selectMock); + + $this->iteratorMock = $this->getMockBuilder( + \IteratorIterator::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->statementMock = $this->getMockBuilder( + \Magento\Framework\DB\Statement\Pdo\Mysql::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->statementMock->expects($this->any()) + ->method('getIterator') + ->willReturn($this->iteratorMock); + + $this->connectionMock = $this->getMockBuilder( + \Magento\Framework\DB\Adapter\AdapterInterface::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->queryFactoryMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\QueryFactory::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->iteratorFactoryMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\IteratorFactory::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->iteratorMock = $this->getMockBuilder( + \IteratorIterator::class + ) + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerHelper = + new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->connectionFactoryMock = $this->getMockBuilder( + \Magento\Analytics\ReportXml\ConnectionFactory::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->subject = $this->objectManagerHelper->getObject( + \Magento\Analytics\ReportXml\ReportProvider::class, + [ + 'queryFactory' => $this->queryFactoryMock, + 'connectionFactory' => $this->connectionFactoryMock, + 'iteratorFactory' => $this->iteratorFactoryMock + ] + ); + } + + /** + * @return void + */ + public function testGetReport() + { + $reportName = 'test_report'; + $connectionName = 'sales'; + + $this->queryFactoryMock->expects($this->once()) + ->method('create') + ->with($reportName) + ->willReturn($this->queryMock); + + $this->connectionFactoryMock->expects($this->once()) + ->method('getConnection') + ->with($connectionName) + ->willReturn($this->connectionMock); + + $this->queryMock->expects($this->once()) + ->method('getConnectionName') + ->willReturn($connectionName); + + $this->queryMock->expects($this->once()) + ->method('getConfig') + ->willReturn( + [ + 'connection' => $connectionName + ] + ); + + $this->connectionMock->expects($this->once()) + ->method('query') + ->with($this->selectMock) + ->willReturn($this->statementMock); + + $this->iteratorFactoryMock->expects($this->once()) + ->method('create') + ->with($this->statementMock, null) + ->willReturn($this->iteratorMock); + $this->assertEquals($this->iteratorMock, $this->subject->getReport($reportName)); + } +} diff --git a/app/code/Magento/Analytics/Test/Unit/ReportXml/SelectHydratorTest.php b/app/code/Magento/Analytics/Test/Unit/ReportXml/SelectHydratorTest.php new file mode 100644 index 0000000000000..ce57a1eca3689 --- /dev/null +++ b/app/code/Magento/Analytics/Test/Unit/ReportXml/SelectHydratorTest.php @@ -0,0 +1,257 @@ +resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->selectMock = $this->getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->selectHydrator = $this->objectManagerHelper->getObject( + SelectHydrator::class, + [ + 'resourceConnection' => $this->resourceConnectionMock, + 'objectManager' => $this->objectManagerMock, + ] + ); + } + + public function testExtract() + { + $selectParts = + [ + Select::DISTINCT, + Select::COLUMNS, + Select::UNION, + Select::FROM, + Select::WHERE, + Select::GROUP, + Select::HAVING, + Select::ORDER, + Select::LIMIT_COUNT, + Select::LIMIT_OFFSET, + Select::FOR_UPDATE + ]; + + $result = []; + foreach ($selectParts as $part) { + $result[$part] = "Part"; + } + $this->selectMock->expects($this->any()) + ->method('getPart') + ->willReturn("Part"); + $this->assertEquals($this->selectHydrator->extract($this->selectMock), $result); + } + + /** + * @dataProvider recreateWithoutExpressionDataProvider + * @param array $selectParts + * @param array $parts + * @param array $partValues + */ + public function testRecreateWithoutExpression($selectParts, $parts, $partValues) + { + $this->resourceConnectionMock->expects($this->once()) + ->method('getConnection') + ->willReturn($this->connectionMock); + $this->connectionMock->expects($this->once()) + ->method('select') + ->willReturn($this->selectMock); + foreach ($parts as $key => $part) { + $this->selectMock->expects($this->at($key)) + ->method('setPart') + ->with($part, $partValues[$key]); + } + + $this->assertSame($this->selectMock, $this->selectHydrator->recreate($selectParts)); + } + + /** + * @return array + */ + public function recreateWithoutExpressionDataProvider() + { + return [ + 'Select without expressions' => [ + [ + Select::COLUMNS => [ + [ + 'table_name', + 'field_name', + 'alias', + ], + [ + 'table_name', + 'field_name_2', + 'alias_2', + ], + ] + ], + [Select::COLUMNS], + [[ + [ + 'table_name', + 'field_name', + 'alias', + ], + [ + 'table_name', + 'field_name_2', + 'alias_2', + ], + ]], + ], + ]; + } + + /** + * @dataProvider recreateWithExpressionDataProvider + * @param array $selectParts + * @param array $expectedParts + * @param \PHPUnit_Framework_MockObject_MockObject[] $expressionMocks + */ + public function testRecreateWithExpression( + array $selectParts, + array $expectedParts, + array $expressionMocks + ) { + $this->objectManagerMock + ->expects($this->exactly(count($expressionMocks))) + ->method('create') + ->with($this->isType('string'), $this->isType('array')) + ->willReturnOnConsecutiveCalls(...$expressionMocks); + $this->resourceConnectionMock + ->expects($this->once()) + ->method('getConnection') + ->with() + ->willReturn($this->connectionMock); + $this->connectionMock + ->expects($this->once()) + ->method('select') + ->with() + ->willReturn($this->selectMock); + foreach (array_keys($selectParts) as $key => $partName) { + $this->selectMock + ->expects($this->at($key)) + ->method('setPart') + ->with($partName, $expectedParts[$partName]); + } + + $this->assertSame($this->selectMock, $this->selectHydrator->recreate($selectParts)); + } + + /** + * @return array + */ + public function recreateWithExpressionDataProvider() + { + $expressionMock = $this->getMockBuilder(JsonSerializableExpression::class) + ->disableOriginalConstructor() + ->getMock(); + + return [ + 'Select without expressions' => [ + 'Parts' => [ + Select::COLUMNS => [ + [ + 'table_name', + 'field_name', + 'alias', + ], + [ + 'table_name', + [ + 'class' => 'Some_class', + 'arguments' => [ + 'expression' => ['some(expression)'] + ] + ], + 'alias_2', + ], + ] + ], + 'expectedParts' => [ + Select::COLUMNS => [ + [ + 'table_name', + 'field_name', + 'alias', + ], + [ + 'table_name', + $expressionMock, + 'alias_2', + ], + ] + ], + 'expectedExpressions' => [ + $expressionMock + ] + ], + ]; + } +} diff --git a/app/code/Magento/Analytics/composer.json b/app/code/Magento/Analytics/composer.json new file mode 100644 index 0000000000000..349e5f3c08c4c --- /dev/null +++ b/app/code/Magento/Analytics/composer.json @@ -0,0 +1,26 @@ +{ + "name": "magento/module-analytics", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/module-backend": "100.2.*", + "magento/module-config": "101.0.*", + "magento/module-integration": "100.2.*", + "magento/module-store": "100.2.*", + "magento/framework": "101.0.*" + }, + "type": "magento2-module", + "version": "100.2.0", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\Analytics\\": "" + } + } +} diff --git a/app/code/Magento/Analytics/docs/images/M2_MA_signup.png b/app/code/Magento/Analytics/docs/images/M2_MA_signup.png new file mode 100644 index 0000000000000..78ed8fad92881 Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/M2_MA_signup.png differ diff --git a/app/code/Magento/Analytics/docs/images/analytics_modules.png b/app/code/Magento/Analytics/docs/images/analytics_modules.png new file mode 100644 index 0000000000000..0bf6048b0d9cc Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/analytics_modules.png differ diff --git a/app/code/Magento/Analytics/docs/images/data_transition.png b/app/code/Magento/Analytics/docs/images/data_transition.png new file mode 100644 index 0000000000000..a75e97983e15d Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/data_transition.png differ diff --git a/app/code/Magento/Analytics/docs/images/definition.png b/app/code/Magento/Analytics/docs/images/definition.png new file mode 100644 index 0000000000000..16acc576320b0 Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/definition.png differ diff --git a/app/code/Magento/Analytics/docs/images/mbi_file_exchange.png b/app/code/Magento/Analytics/docs/images/mbi_file_exchange.png new file mode 100644 index 0000000000000..f39d2e4900703 Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/mbi_file_exchange.png differ diff --git a/app/code/Magento/Analytics/docs/images/signup.png b/app/code/Magento/Analytics/docs/images/signup.png new file mode 100644 index 0000000000000..561e18b3a351f Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/signup.png differ diff --git a/app/code/Magento/Analytics/docs/images/update.png b/app/code/Magento/Analytics/docs/images/update.png new file mode 100644 index 0000000000000..149f5b5d3f9bd Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/update.png differ diff --git a/app/code/Magento/Analytics/docs/images/update_request.png b/app/code/Magento/Analytics/docs/images/update_request.png new file mode 100644 index 0000000000000..7181251e3634e Binary files /dev/null and b/app/code/Magento/Analytics/docs/images/update_request.png differ diff --git a/app/code/Magento/Analytics/etc/acl.xml b/app/code/Magento/Analytics/etc/acl.xml new file mode 100644 index 0000000000000..bf2251895f929 --- /dev/null +++ b/app/code/Magento/Analytics/etc/acl.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Analytics/etc/adminhtml/di.xml b/app/code/Magento/Analytics/etc/adminhtml/di.xml new file mode 100644 index 0000000000000..5e305e70e5ad3 --- /dev/null +++ b/app/code/Magento/Analytics/etc/adminhtml/di.xml @@ -0,0 +1,16 @@ + + + + + + + Magento\Analytics\Model\System\Message\NotificationAboutFailedSubscription + + + + diff --git a/app/code/Magento/Analytics/etc/adminhtml/menu.xml b/app/code/Magento/Analytics/etc/adminhtml/menu.xml new file mode 100644 index 0000000000000..915211c4bb85e --- /dev/null +++ b/app/code/Magento/Analytics/etc/adminhtml/menu.xml @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/app/code/Magento/Analytics/etc/adminhtml/routes.xml b/app/code/Magento/Analytics/etc/adminhtml/routes.xml new file mode 100644 index 0000000000000..0ae2762dacc5f --- /dev/null +++ b/app/code/Magento/Analytics/etc/adminhtml/routes.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/Analytics/etc/adminhtml/system.xml b/app/code/Magento/Analytics/etc/adminhtml/system.xml new file mode 100644 index 0000000000000..889517e629e04 --- /dev/null +++ b/app/code/Magento/Analytics/etc/adminhtml/system.xml @@ -0,0 +1,50 @@ + + + + +
+ + general + Magento_Analytics::analytics_settings + + + For more information, see our + terms and conditions.]]> + + + Magento\Config\Model\Config\Source\Enabledisable + Magento\Analytics\Model\Config\Backend\Enabled + Magento\Analytics\Block\Adminhtml\System\Config\SubscriptionStatusLabel + analytics/subscription/enabled + + + + Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel + Magento\Analytics\Model\Config\Backend\CollectionTime + + + Industry Data + + In order to personalize your Advanced Reporting experience, please select your industry. + Magento\Analytics\Model\Config\Source\Vertical + Magento\Analytics\Model\Config\Backend\Vertical + Magento\Analytics\Block\Adminhtml\System\Config\Vertical + + + + Learn more about Magento BI Essentials and BI Pro tiers.]]> + Magento\Analytics\Block\Adminhtml\System\Config\AdditionalComment + + +
+
+
diff --git a/app/code/Magento/Analytics/etc/analytics.xml b/app/code/Magento/Analytics/etc/analytics.xml new file mode 100644 index 0000000000000..77ebe751a31cf --- /dev/null +++ b/app/code/Magento/Analytics/etc/analytics.xml @@ -0,0 +1,50 @@ + + + + + + + + modules + + + + + + + + + + + + + + stores + + + + + + + + + websites + + + + + + + + + groups + + + + + diff --git a/app/code/Magento/Analytics/etc/analytics.xsd b/app/code/Magento/Analytics/etc/analytics.xsd new file mode 100644 index 0000000000000..2506e3d6a6a9a --- /dev/null +++ b/app/code/Magento/Analytics/etc/analytics.xsd @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + File name attribute can has only [a-zA-Z0-9/_]. + + + + + + + + + + Value is required. + + + + + + + diff --git a/app/code/Magento/Analytics/etc/config.xml b/app/code/Magento/Analytics/etc/config.xml new file mode 100644 index 0000000000000..b6194ba12993f --- /dev/null +++ b/app/code/Magento/Analytics/etc/config.xml @@ -0,0 +1,25 @@ + + + + + + + https://advancedreporting.rjmetrics.com/signup + https://advancedreporting.rjmetrics.com/update + https://dashboard.rjmetrics.com/v2/magento/signup + https://advancedreporting.rjmetrics.com/otp + https://advancedreporting.rjmetrics.com/report + https://advancedreporting.rjmetrics.com/report + + Magento Analytics user + + 02,00,00 + + + + diff --git a/app/code/Magento/Analytics/etc/crontab.xml b/app/code/Magento/Analytics/etc/crontab.xml new file mode 100644 index 0000000000000..a4beef0359540 --- /dev/null +++ b/app/code/Magento/Analytics/etc/crontab.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/Analytics/etc/di.xml b/app/code/Magento/Analytics/etc/di.xml new file mode 100644 index 0000000000000..b9bb9cc9ff00c --- /dev/null +++ b/app/code/Magento/Analytics/etc/di.xml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + Magento\Analytics\Model\Connector\SignUpCommand + Magento\Analytics\Model\Connector\UpdateCommand + Magento\Analytics\Model\Connector\NotifyDataChangedCommand + + + + + + + Magento\Analytics\ReportXml\Config\Data + + + + + Magento\Analytics\ReportXml\Config\Reader + Magento_Analytics_ReportXml_CacheId + + + + + urn:magento:module:Magento_Analytics:etc/reports.xsd + + + + + Magento\Analytics\ReportXml\Config\Converter\Xml + Magento\Analytics\ReportXml\Config\SchemaLocator + reports.xml + + name + + name + alias + + name + name + + glue + + attribute + operator + + + glue + + attribute + operator + + + glue + + attribute + operator + + glue + + attribute + operator + + + + + + + + Magento\Analytics\ReportXml\Config\Reader\Xml + + + + + + + Magento\Analytics\Model\Config\Data + + + + + Magento\Analytics\Model\Config\Reader + Magento_Analytics_CacheId + + + + + urn:magento:module:Magento_Analytics:etc/analytics.xsd + + + + + Magento\Analytics\ReportXml\Config\Converter\Xml + Magento\Analytics\Model\Config\SchemaLocator + analytics.xml + + name + + + + + + + + Magento\Analytics\ReportXml\DB\Assembler\FromAssembler + Magento\Analytics\ReportXml\DB\Assembler\FilterAssembler + Magento\Analytics\ReportXml\DB\Assembler\JoinAssembler + + + + + + + Magento\Analytics\Model\Config\Reader\Xml + + + + + + + web/unsecure/base_url + currency/options/base + general/locale/timezone + general/country/default + carriers/dhl/title + carriers/dhl/active + carriers/fedex/title + carriers/fedex/active + carriers/flatrate/title + carriers/flatrate/active + carriers/tablerate/title + carriers/tablerate/active + carriers/freeshipping/title + carriers/freeshipping/active + carriers/ups/title + carriers/ups/active + carriers/usps/title + carriers/usps/active + payment/free/title + payment/free/active + payment/checkmo/title + payment/checkmo/active + payment/purchaseorder/title + payment/purchaseorder/active + payment/banktransfer/title + payment/banktransfer/active + payment/cashondelivery/title + payment/cashondelivery/active + payment/authorizenet_directpost/title + payment/authorizenet_directpost/active + payment/paypal_billing_agreement/title + payment/paypal_billing_agreement/active + payment/braintree/title + payment/braintree/active + payment/braintree_paypal/title + payment/braintree_paypal/active + analytics/general/vertical + + + + + + + Apps and Games + Athletic/Sporting Goods + Art and Design + Auto Parts + Baby/Children’s Apparel, Gear and Toys + Beauty and Cosmetics + Books, Music and Magazines + Crafts and Stationery + Consumer Electronics + Deal Site + Fashion Apparel and Accessories + Food, Beverage and Grocery + Home Goods and Furniture + Home Improvement + Jewelry and Watches + Mass Merchant + Office Supplies + Outdoor and Camping Gear + Pet Goods + Pharma and Medical Devices + Technology B2B + Other + + + + + + + + + + \Magento\Analytics\Model\Connector\ResponseHandler\SignUp + + + + + + + Magento\Analytics\Model\Connector\ResponseHandler\Update + Magento\Analytics\Model\Connector\ResponseHandler\ReSignUp + + + + + + + Magento\Analytics\Model\Connector\ResponseHandler\OTP + Magento\Analytics\Model\Connector\ResponseHandler\ReSignUp + + + + + + + Magento\Analytics\Model\Connector\ResponseHandler\ReSignUp + + + + + + SignUpResponseResolver + + + + + UpdateResponseResolver + + + + + OtpResponseResolver + + + + + NotifyDataChangedResponseResolver + + + + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + + + 1 + 1 + 1 + + + + diff --git a/app/code/Magento/Analytics/etc/module.xml b/app/code/Magento/Analytics/etc/module.xml new file mode 100644 index 0000000000000..32ee5d23a4d86 --- /dev/null +++ b/app/code/Magento/Analytics/etc/module.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/app/code/Magento/Analytics/etc/reports.xml b/app/code/Magento/Analytics/etc/reports.xml new file mode 100644 index 0000000000000..8a43658670293 --- /dev/null +++ b/app/code/Magento/Analytics/etc/reports.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/code/Magento/Analytics/etc/reports.xsd b/app/code/Magento/Analytics/etc/reports.xsd new file mode 100644 index 0000000000000..d0ba4068244fe --- /dev/null +++ b/app/code/Magento/Analytics/etc/reports.xsd @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Analytics/etc/webapi.xml b/app/code/Magento/Analytics/etc/webapi.xml new file mode 100644 index 0000000000000..8252d039f1d03 --- /dev/null +++ b/app/code/Magento/Analytics/etc/webapi.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/app/code/Magento/Analytics/i18n/en_US.csv b/app/code/Magento/Analytics/i18n/en_US.csv new file mode 100644 index 0000000000000..516c388feb823 --- /dev/null +++ b/app/code/Magento/Analytics/i18n/en_US.csv @@ -0,0 +1,84 @@ +"Subscription status","Subscription status" +"Sorry, there has been an error processing your request. Please try again later.","Sorry, there has been an error processing your request. Please try again later." +"Sorry, there was an error processing your registration request to Magento Analytics. Please try again later.","Sorry, there was an error processing your registration request to Magento Analytics. Please try again later." +"Error occurred during postponement notification","Error occurred during postponement notification" +"Time value has an unsupported format","Time value has an unsupported format" +"Cron settings can't be saved","Cron settings can't be saved" +"There was an error save new configuration value.","There was an error save new configuration value." +"Please select a vertical.","Please select a vertical." +"--Please Select--","--Please Select--" +"Command was not found.","Command was not found." +"Input data must be string or convertible into string.","Input data must be string or convertible into string." +"Input data must be non-empty string.","Input data must be non-empty string." +"Not valid cipher method.","Not valid cipher method." +"Encryption key can't be empty.","Encryption key can't be empty." +"Source ""%1"" is not exist","Source ""%1"" is not exist" +"These arguments can't be empty ""%1""","These arguments can't be empty ""%1""" +"Cannot find predefined integration user!","Cannot find predefined integration user!" +"File is not ready yet.","File is not ready yet." +"Your Base URL has been changed and your reports are being updated. Advanced Reporting will be available once this change has been processed. Please try again later.","Your Base URL has been changed and your reports are being updated. Advanced Reporting will be available once this change has been processed. Please try again later." +"Failed to synchronize data to the Magento Business Intelligence service. ","Failed to synchronize data to the Magento Business Intelligence service. " +"Retry Synchronization","Retry Synchronization" +TestMessage,TestMessage +"Error message","Error message" +"Apps and Games","Apps and Games" +"Athletic/Sporting Goods","Athletic/Sporting Goods" +"Art and Design","Art and Design" +"Advanced Reporting","Advanced Reporting" +"Gain new insights and take command of your business' performance, using our dynamic product, order, and customer reports tailored to your customer data.","Gain new insights and take command of your business' performance, using our dynamic product, order, and customer reports tailored to your customer data." +"View details","View details" +"Go to Advanced Reporting","Go to Advanced Reporting" +"An error occurred while subscription process.","An error occurred while subscription process." +Analytics,Analytics +API,API +Configuration,Configuration +"Business Intelligence","Business Intelligence" +"BI Essentials","BI Essentials" +"This service provides a dynamic suite of reports with rich insights about your business. + Your reports can be accessed securely on a personalized dashboard outside of the admin panel by clicking on the + ""Go to Advanced Reporting"" link.
For more information, see our + terms and conditions. + ","This service provides a dynamic suite of reports with rich insights about your business. + Your reports can be accessed securely on a personalized dashboard outside of the admin panel by clicking on the + ""Go to Advanced Reporting"" link.
For more information, see our + terms and conditions." +"Advanced Reporting Service","Advanced Reporting Service" +Industry,Industry +"Time of day to send data","Time of day to send data" +"Get more insights from Magento Business Intelligence","Get more insights from Magento Business Intelligence" +"Magento Business Intelligence provides you with a simple and clear path to + becoming more data driven.
Learn more about BI Essentials tier.","Magento Business Intelligence provides you with a simple and clear path to + becoming more data driven.
Learn more about BI Essentials tier." +"Auto Parts","Auto Parts" +"Baby/Children’s Apparel, Gear and Toys","Baby/Children’s Apparel, Gear and Toys" +"Beauty and Cosmetics","Beauty and Cosmetics" +"Books, Music and Magazines","Books, Music and Magazines" +"Crafts and Stationery","Crafts and Stationery" +"Consumer Electronics","Consumer Electronics" +"Deal Site","Deal Site" +"Fashion Apparel and Accessories","Fashion Apparel and Accessories" +"Food, Beverage and Grocery","Food, Beverage and Grocery" +"Home Goods and Furniture","Home Goods and Furniture" +"Home Improvement","Home Improvement" +"Jewelry and Watches","Jewelry and Watches" +"Mass Merchant","Mass Merchant" +"Office Supplies","Office Supplies" +"Outdoor and Camping Gear","Outdoor and Camping Gear" +"Pet Goods","Pet Goods" +"Pharma and Medical Devices","Pharma and Medical Devices" +"Technology B2B","Technology B2B" +"Analytics Subscription","Analytics Subscription" +"powered by Magento Business Intelligence","powered by Magento Business Intelligence" +"Are you sure you want to opt out?","Are you sure you want to opt out?" +Cancel,Cancel +"Opt out","Opt out" +"

Advanced Reporting in included, + free of charge, in your Magento software. When you opt out, we collect no product, order, and + customer data to generate our dynamic reports.

To opt in later: You can always turn on Advanced + Reporting in you Admin Panel.

","

Advanced Reporting in included, + free of charge, in your Magento software. When you opt out, we collect no product, order, and + customer data to generate our dynamic reports.

To opt in later: You can always turn on Advanced + Reporting in you Admin Panel.

" +"In order to personalize your Advanced Reporting experience, please select your industry.","In order to personalize your Advanced Reporting experience, please select your industry." diff --git a/app/code/Magento/Analytics/registration.php b/app/code/Magento/Analytics/registration.php new file mode 100644 index 0000000000000..58d3688b7491d --- /dev/null +++ b/app/code/Magento/Analytics/registration.php @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/app/code/Magento/Analytics/view/adminhtml/templates/dashboard/section.phtml b/app/code/Magento/Analytics/view/adminhtml/templates/dashboard/section.phtml new file mode 100644 index 0000000000000..a22c603b2a8b3 --- /dev/null +++ b/app/code/Magento/Analytics/view/adminhtml/templates/dashboard/section.phtml @@ -0,0 +1,28 @@ + + +
+
+
+ escapeHtml(__('Advanced Reporting')) ?> +
+
+ escapeHtml(__('Gain new insights and take command of your business\' performance,' . + ' using our dynamic product, order, and customer reports tailored to your customer data.')) ?> +
+
+ +
diff --git a/app/code/Magento/Authorization/composer.json b/app/code/Magento/Authorization/composer.json index a894193888100..c0b0f9c6b13df 100644 --- a/app/code/Magento/Authorization/composer.json +++ b/app/code/Magento/Authorization/composer.json @@ -4,10 +4,10 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-backend": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Authorizenet/composer.json b/app/code/Magento/Authorizenet/composer.json index 2abfebc3c1cb7..1022bd47a5786 100644 --- a/app/code/Magento/Authorizenet/composer.json +++ b/app/code/Magento/Authorizenet/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-sales": "100.2.*", + "magento/module-sales": "101.0.*", "magento/module-store": "100.2.*", - "magento/module-quote": "100.2.*", + "magento/module-quote": "101.0.*", "magento/module-checkout": "100.2.*", "magento/module-backend": "100.2.*", "magento/module-payment": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/framework": "100.2.*" + "magento/module-catalog": "102.0.*", + "magento/framework": "101.0.*" }, "suggest": { - "magento/module-config": "100.2.*" + "magento/module-config": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "proprietary" ], diff --git a/app/code/Magento/Backend/Block/Cache.php b/app/code/Magento/Backend/Block/Cache.php index e14358396aa70..82c36bf3a1fe4 100644 --- a/app/code/Magento/Backend/Block/Cache.php +++ b/app/code/Magento/Backend/Block/Cache.php @@ -22,24 +22,29 @@ protected function _construct() $this->_headerText = __('Cache Storage Management'); parent::_construct(); $this->buttonList->remove('add'); - $this->buttonList->add( - 'flush_magento', - [ - 'label' => __('Flush Magento Cache'), - 'onclick' => 'setLocation(\'' . $this->getFlushSystemUrl() . '\')', - 'class' => 'primary flush-cache-magento' - ] - ); - $message = __('The cache storage may contain additional data. Are you sure that you want to flush it?'); - $this->buttonList->add( - 'flush_system', - [ - 'label' => __('Flush Cache Storage'), - 'onclick' => 'confirmSetLocation(\'' . $message . '\', \'' . $this->getFlushStorageUrl() . '\')', - 'class' => 'flush-cache-storage' - ] - ); + if ($this->_authorization->isAllowed('Magento_Backend::flush_magento_cache')) { + $this->buttonList->add( + 'flush_magento', + [ + 'label' => __('Flush Magento Cache'), + 'onclick' => 'setLocation(\'' . $this->getFlushSystemUrl() . '\')', + 'class' => 'primary flush-cache-magento' + ] + ); + } + + if ($this->_authorization->isAllowed('Magento_Backend::flush_cache_storage')) { + $message = __('The cache storage may contain additional data. Are you sure that you want to flush it?'); + $this->buttonList->add( + 'flush_system', + [ + 'label' => __('Flush Cache Storage'), + 'onclick' => 'confirmSetLocation(\'' . $message . '\', \'' . $this->getFlushStorageUrl() . '\')', + 'class' => 'flush-cache-storage' + ] + ); + } } /** diff --git a/app/code/Magento/Backend/Block/Cache/Permissions.php b/app/code/Magento/Backend/Block/Cache/Permissions.php new file mode 100644 index 0000000000000..272a603145f09 --- /dev/null +++ b/app/code/Magento/Backend/Block/Cache/Permissions.php @@ -0,0 +1,62 @@ +authorization = $authorization; + } + + /** + * @return bool + */ + public function hasAccessToFlushCatalogImages() + { + return $this->authorization->isAllowed('Magento_Backend::flush_catalog_images'); + } + /** + * @return bool + */ + public function hasAccessToFlushJsCss() + { + return $this->authorization->isAllowed('Magento_Backend::flush_js_css'); + } + /** + * @return bool + */ + public function hasAccessToFlushStaticFiles() + { + return $this->authorization->isAllowed('Magento_Backend::flush_static_files'); + } + /** + * @return bool + */ + public function hasAccessToAdditionalActions() + { + return ($this->hasAccessToFlushCatalogImages() + || $this->hasAccessToFlushJsCss() + || $this->hasAccessToFlushStaticFiles()); + } +} diff --git a/app/code/Magento/Backend/Block/Dashboard/Graph.php b/app/code/Magento/Backend/Block/Dashboard/Graph.php index cecd7b8050352..301dffbdc4987 100644 --- a/app/code/Magento/Backend/Block/Dashboard/Graph.php +++ b/app/code/Magento/Backend/Block/Dashboard/Graph.php @@ -421,6 +421,8 @@ public function getChartUrl($directUrl = true) $tmpstring = implode('|', $this->_axisLabels[$idx]); $valueBuffer[] = $indexid . ":|" . $tmpstring; + } elseif ($idx == 'y') { + $valueBuffer[] = $indexid . ":|" . implode('|', $yLabels); } $indexid++; } diff --git a/app/code/Magento/Backend/Block/Dashboard/Orders/Grid.php b/app/code/Magento/Backend/Block/Dashboard/Orders/Grid.php index 9d9409fba093b..50279786c0a5b 100644 --- a/app/code/Magento/Backend/Block/Dashboard/Orders/Grid.php +++ b/app/code/Magento/Backend/Block/Dashboard/Orders/Grid.php @@ -92,7 +92,7 @@ protected function _prepareCollection() protected function _afterLoadCollection() { foreach ($this->getCollection() as $item) { - $item->getCustomer() ?: $item->setCustomer('Guest'); + $item->getCustomer() ?: $item->setCustomer($item->getBillingAddress()->getName()); } return $this; } diff --git a/app/code/Magento/Backend/Block/GlobalSearch.php b/app/code/Magento/Backend/Block/GlobalSearch.php index f4a46283808f4..9af4e9faef761 100644 --- a/app/code/Magento/Backend/Block/GlobalSearch.php +++ b/app/code/Magento/Backend/Block/GlobalSearch.php @@ -3,19 +3,61 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Backend\Block; +use Magento\Backend\Model\GlobalSearch\SearchEntityFactory; +use Magento\Backend\Model\GlobalSearch\SearchEntity; +use Magento\Framework\App\ObjectManager; + /** * @api * @since 100.0.2 */ class GlobalSearch extends \Magento\Backend\Block\Template { + /** + * @var SearchEntityFactory + */ + private $searchEntityFactory; + /** * @var string */ protected $_template = 'Magento_Backend::system/search.phtml'; + /** + * @var array + */ + private $entityResources; + + /** + * @var array + */ + private $entityPaths; + + /** + * @param Template\Context $context + * @param array $data + * @param array $entityResources + * @param array $entityPaths + * @param SearchEntityFactory|null $searchEntityFactory + */ + public function __construct( + Template\Context $context, + array $data = [], + array $entityResources = [], + array $entityPaths = [], + SearchEntityFactory $searchEntityFactory = null + ) { + $this->entityResources = $entityResources; + $this->entityPaths = $entityPaths; + $this->searchEntityFactory = $searchEntityFactory ?: ObjectManager::getInstance() + ->get(SearchEntityFactory::class); + + parent::__construct($context, $data); + } + /** * Get components configuration * @return array @@ -34,4 +76,48 @@ public function getWidgetInitOptions() ] ]; } + + /** + * Get entities which are allowed to show. + * + * @return SearchEntity[] + */ + public function getEntitiesToShow() + { + $allowedEntityTypes = []; + $entitiesToShow = []; + + foreach ($this->entityResources as $entityType => $resource) { + if ($this->getAuthorization()->isAllowed($resource)) { + $allowedEntityTypes[] = $entityType; + } + } + + foreach ($allowedEntityTypes as $entityType) { + $url = $this->getUrlEntityType($entityType); + + $searchEntity = $this->searchEntityFactory->create(); + $searchEntity->setId('searchPreview' . $entityType); + $searchEntity->setTitle('in ' . $entityType); + $searchEntity->setUrl($url); + + $entitiesToShow[] = $searchEntity; + } + + return $entitiesToShow; + } + + /** + * Get url path by entity type. + * + * @param string $entityType + * + * @return string + */ + private function getUrlEntityType(string $entityType) + { + $urlPath = $this->entityPaths[$entityType] ?? ''; + + return $this->getUrl($urlPath); + } } diff --git a/app/code/Magento/Backend/Block/System/Store/Edit/AbstractForm.php b/app/code/Magento/Backend/Block/System/Store/Edit/AbstractForm.php index f19799d2e4939..034887c67d1ee 100644 --- a/app/code/Magento/Backend/Block/System/Store/Edit/AbstractForm.php +++ b/app/code/Magento/Backend/Block/System/Store/Edit/AbstractForm.php @@ -37,7 +37,7 @@ protected function _prepareForm() ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']] ); - $this->_prepareStoreFieldSet($form); + $this->_prepareStoreFieldset($form); $form->addField( 'store_type', diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php index 40a5d92c56b6f..632603d389d21 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php @@ -127,7 +127,7 @@ public function getHtml() /** * @param string|null $index - * @return string + * @return array|string|int|float|null */ public function getEscapedValue($index = null) { @@ -138,6 +138,11 @@ public function getEscapedValue($index = null) $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT) ); } + + if (is_string($value)) { + return $this->escapeHtml($value); + } + return $value; } diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php index 96b3471db845e..a5e4a34389671 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php @@ -140,8 +140,8 @@ public function getHtml() /** * Return escaped value for calendar * - * @param string $index - * @return string + * @param string|null $index + * @return array|string|int|float|null */ public function getEscapedValue($index = null) { @@ -150,6 +150,11 @@ public function getEscapedValue($index = null) if ($value instanceof \DateTimeInterface) { return $this->_localeDate->formatDateTime($value); } + + if (is_string($value)) { + return $this->escapeHtml($value); + } + return $value; } diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Massaction.php b/app/code/Magento/Backend/Block/Widget/Grid/Massaction.php index d9b00d2ba2503..662cbedaed8db 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Massaction.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Massaction.php @@ -3,8 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Backend\Block\Widget\Grid; +use Magento\Backend\Block\Template\Context; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\AuthorizationInterface; +use Magento\Framework\DataObject; +use Magento\Framework\Json\EncoderInterface; + /** * Grid widget massaction default block * @@ -14,4 +21,72 @@ */ class Massaction extends \Magento\Backend\Block\Widget\Grid\Massaction\AbstractMassaction { + /** + * @var AuthorizationInterface + */ + private $authorization; + + /** + * Map bind item id to a particular acl type + * itemId => acl + * + * @var array + */ + private $restrictions = [ + 'enable' => 'Magento_Backend::toggling_cache_type', + 'disable' => 'Magento_Backend::toggling_cache_type', + 'refresh' => 'Magento_Backend::refresh_cache_type', + ]; + + /** + * Massaction constructor. + * + * @param Context $context + * @param EncoderInterface $jsonEncoder + * @param array $data + * @param AuthorizationInterface $authorization + */ + public function __construct( + Context $context, + EncoderInterface $jsonEncoder, + array $data = [], + AuthorizationInterface $authorization = null + ) { + $this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class); + + parent::__construct($context, $jsonEncoder, $data); + } + + /** + * {@inheritdoc} + * + * @param string $itemId + * @param array|DataObject $item + * + * @return $this + */ + public function addItem($itemId, $item) + { + if (!$this->isRestricted($itemId)) { + parent::addItem($itemId, $item); + } + + return $this; + } + + /** + * Check if access to action restricted + * + * @param string $itemId + * + * @return bool + */ + private function isRestricted(string $itemId): bool + { + if (!key_exists($itemId, $this->restrictions)) { + return false; + } + + return !$this->authorization->isAllowed($this->restrictions[$itemId]); + } } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php index 1895bd08c464f..7a926b1c09c3e 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php @@ -11,6 +11,13 @@ class CleanImages extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::flush_catalog_images'; + /** * Clean JS/css files cache * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php index 521cb9806a135..72f23ab65cf8a 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php @@ -11,6 +11,13 @@ class CleanMedia extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::flush_js_css'; + /** * Clean JS/css files cache * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php index adfbf7cfe63c8..27ae2fc31e150 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanStaticFiles.php @@ -10,6 +10,13 @@ class CleanStaticFiles extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::flush_static_files'; + /** * Clean static files cache * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php index 2f9dc9ad6a7a5..ca89ea58fa6f3 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushAll.php @@ -8,6 +8,13 @@ class FlushAll extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::flush_cache_storage'; + /** * Flush cache storage * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php index 0f55a59353d65..f0fed159e0f22 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/FlushSystem.php @@ -8,6 +8,13 @@ class FlushSystem extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::flush_magento_cache'; + /** * Flush all magento cache * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php index 204105852b9f1..2bfa937b06b77 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php @@ -16,6 +16,13 @@ */ class MassDisable extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::toggling_cache_type'; + /** * @var State */ diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php index 32acf47887c44..113e0f2d8961b 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php @@ -16,6 +16,13 @@ */ class MassEnable extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::toggling_cache_type'; + /** * @var State */ diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php index e18aa1555e11b..3843b030afb3d 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php @@ -11,6 +11,13 @@ class MassRefresh extends \Magento\Backend\Controller\Adminhtml\Cache { + /** + * Authorization level of a basic admin session + * + * @see _isAllowed() + */ + const ADMIN_RESOURCE = 'Magento_Backend::refresh_cache_type'; + /** * Mass action for cache refresh * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php index f03d58b9a3eb7..87153c381c1f7 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Noroute/Index.php @@ -8,6 +8,13 @@ class Index extends \Magento\Backend\App\Action { + /** + * Array of actions which can be processed without secret key validation + * + * @var string[] + */ + protected $_publicActions = ['index']; + /** * @var \Magento\Framework\View\Result\PageFactory */ @@ -34,7 +41,7 @@ public function execute() { /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); - $resultPage->setStatusHeader(404, '1.1', 'Forbidden'); + $resultPage->setStatusHeader(404, '1.1', 'Not Found'); $resultPage->setHeader('Status', '404 File not found'); $resultPage->addHandle('adminhtml_noroute'); return $resultPage; diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index c9bce1cbf3888..421885a0c32a3 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -54,9 +54,9 @@ public function execute() $user = $this->_objectManager->create(\Magento\User\Model\User::class)->load($userId); $user->setId($userId) - ->setUsername($this->getRequest()->getParam('username', false)) - ->setFirstname($this->getRequest()->getParam('firstname', false)) - ->setLastname($this->getRequest()->getParam('lastname', false)) + ->setUserName($this->getRequest()->getParam('username', false)) + ->setFirstName($this->getRequest()->getParam('firstname', false)) + ->setLastName($this->getRequest()->getParam('lastname', false)) ->setEmail(strtolower($this->getRequest()->getParam('email', false))); if ($this->_objectManager->get(\Magento\Framework\Validator\Locale::class)->isValid($interfaceLocale)) { diff --git a/app/code/Magento/Backend/Model/Auth/StorageInterface.php b/app/code/Magento/Backend/Model/Auth/StorageInterface.php index 52b2b089c71e1..e643165a93317 100644 --- a/app/code/Magento/Backend/Model/Auth/StorageInterface.php +++ b/app/code/Magento/Backend/Model/Auth/StorageInterface.php @@ -23,7 +23,7 @@ interface StorageInterface public function processLogin(); /** - * Perform login specific actions + * Perform logout specific actions * * @return $this * @abstract diff --git a/app/code/Magento/Backend/Model/GlobalSearch/SearchEntity.php b/app/code/Magento/Backend/Model/GlobalSearch/SearchEntity.php new file mode 100644 index 0000000000000..18691802b9218 --- /dev/null +++ b/app/code/Magento/Backend/Model/GlobalSearch/SearchEntity.php @@ -0,0 +1,73 @@ +getData('id'); + } + + /** + * Get url. + * + * @return string + */ + public function getUrl() + { + return $this->getData('url'); + } + + /** + * Get title. + * + * @return string + */ + public function getTitle() + { + return $this->getData('title'); + } + + /** + * Set Id. + * + * @param string $value + */ + public function setId(string $value) + { + $this->setData('id', $value); + } + + /** + * Set url. + * + * @param string $value + */ + public function setUrl(string $value) + { + $this->setData('url', $value); + } + + /** + * Set title. + * + * @param string $value + */ + public function setTitle(string $value) + { + $this->setData('title', $value); + } +} diff --git a/app/code/Magento/Backend/Model/Menu/Item.php b/app/code/Magento/Backend/Model/Menu/Item.php index fe6564d24e891..42febe94d0abf 100644 --- a/app/code/Magento/Backend/Model/Menu/Item.php +++ b/app/code/Magento/Backend/Model/Menu/Item.php @@ -467,15 +467,15 @@ public function toArray() { return [ 'parent_id' => $this->_parentId, - 'module_name' => $this->_moduleName, + 'module' => $this->_moduleName, 'sort_index' => $this->_sortIndex, - 'depends_on_config' => $this->_dependsOnConfig, + 'dependsOnConfig' => $this->_dependsOnConfig, 'id' => $this->_id, 'resource' => $this->_resource, 'path' => $this->_path, 'action' => $this->_action, - 'depends_on_module' => $this->_dependsOnModule, - 'tooltip' => $this->_tooltip, + 'dependsOnModule' => $this->_dependsOnModule, + 'toolTip' => $this->_tooltip, 'title' => $this->_title, 'target' => $this->target, 'sub_menu' => isset($this->_submenu) ? $this->_submenu->toArray() : null @@ -492,15 +492,15 @@ public function toArray() public function populateFromArray(array $data) { $this->_parentId = $this->_getArgument($data, 'parent_id'); - $this->_moduleName = $this->_getArgument($data, 'module_name', 'Magento_Backend'); + $this->_moduleName = $this->_getArgument($data, 'module', 'Magento_Backend'); $this->_sortIndex = $this->_getArgument($data, 'sort_index'); - $this->_dependsOnConfig = $this->_getArgument($data, 'depends_on_config'); + $this->_dependsOnConfig = $this->_getArgument($data, 'dependsOnConfig'); $this->_id = $this->_getArgument($data, 'id'); $this->_resource = $this->_getArgument($data, 'resource'); $this->_path = $this->_getArgument($data, 'path', ''); $this->_action = $this->_getArgument($data, 'action'); - $this->_dependsOnModule = $this->_getArgument($data, 'depends_on_module'); - $this->_tooltip = $this->_getArgument($data, 'tooltip', ''); + $this->_dependsOnModule = $this->_getArgument($data, 'dependsOnModule'); + $this->_tooltip = $this->_getArgument($data, 'toolTip'); $this->_title = $this->_getArgument($data, 'title'); $this->target = $this->_getArgument($data, 'target'); if (isset($data['sub_menu'])) { diff --git a/app/code/Magento/Backend/Model/Url.php b/app/code/Magento/Backend/Model/Url.php index 48b443fe7ffd3..cf895268bcb7d 100644 --- a/app/code/Magento/Backend/Model/Url.php +++ b/app/code/Magento/Backend/Model/Url.php @@ -202,7 +202,7 @@ public function getUrl($routePath = null, $routeParams = null) } $cacheSecretKey = false; - if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) { + if (isset($routeParams['_cache_secret_key'])) { unset($routeParams['_cache_secret_key']); $cacheSecretKey = true; } @@ -210,25 +210,22 @@ public function getUrl($routePath = null, $routeParams = null) if (!$this->useSecretKey()) { return $result; } + $this->_setRoutePath($routePath); $routeName = $this->_getRouteName('*'); $controllerName = $this->_getControllerName(self::DEFAULT_CONTROLLER_NAME); $actionName = $this->_getActionName(self::DEFAULT_ACTION_NAME); - if ($cacheSecretKey) { - $secret = [self::SECRET_KEY_PARAM_NAME => "\${$routeName}/{$controllerName}/{$actionName}\$"]; - } else { - $secret = [ - self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($routeName, $controllerName, $actionName), - ]; - } - if (is_array($routeParams)) { - $routeParams = array_merge($secret, $routeParams); - } else { - $routeParams = $secret; - } - if (is_array($this->_getRouteParams())) { - $routeParams = array_merge($this->_getRouteParams(), $routeParams); + + if (!isset($routeParams[self::SECRET_KEY_PARAM_NAME])) { + if (!is_array($routeParams)) { + $routeParams = []; + } + $secretKey = $cacheSecretKey + ? "\${$routeName}/{$controllerName}/{$actionName}\$" + : $this->getSecretKey($routeName, $controllerName, $actionName); + $routeParams[self::SECRET_KEY_PARAM_NAME] = $secretKey; } + return parent::getUrl("{$routeName}/{$controllerName}/{$actionName}", $routeParams); } diff --git a/app/code/Magento/Backend/Model/Widget/Grid/Parser.php b/app/code/Magento/Backend/Model/Widget/Grid/Parser.php index e2b77fb471acd..fbed7149aa565 100644 --- a/app/code/Magento/Backend/Model/Widget/Grid/Parser.php +++ b/app/code/Magento/Backend/Model/Widget/Grid/Parser.php @@ -30,8 +30,9 @@ public function parseExpression($expression) $expression = trim($expression); foreach ($this->_operations as $operation) { $splittedExpr = preg_split('/\\' . $operation . '/', $expression, -1, PREG_SPLIT_DELIM_CAPTURE); - if (count($splittedExpr) > 1) { - for ($i = 0; $i < count($splittedExpr); $i++) { + $count = count($splittedExpr); + if ($count > 1) { + for ($i = 0; $i < $count; $i++) { $stack = array_merge($stack, $this->parseExpression($splittedExpr[$i])); if ($i > 0) { $stack[] = $operation; diff --git a/app/code/Magento/Backend/Test/Unit/Block/Cache/PermissionsTest.php b/app/code/Magento/Backend/Test/Unit/Block/Cache/PermissionsTest.php new file mode 100644 index 0000000000000..6975b8ac092ad --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Block/Cache/PermissionsTest.php @@ -0,0 +1,76 @@ +objectManager = new ObjectManager($this); + + $this->mockAuthorization = $this->getMockBuilder(Authorization::class) + ->disableOriginalConstructor() + ->setMethods(['isAllowed']) + ->getMock(); + + $this->permissions = new Permissions($this->mockAuthorization); + } + + public function testHasAccessToFlushCatalogImages() + { + $this->mockAuthorization->expects($this->atLeastOnce()) + ->method('isAllowed') + ->with('Magento_Backend::flush_catalog_images') + ->willReturn(true); + + $this->assertTrue($this->permissions->hasAccessToFlushCatalogImages()); + } + + public function testHasAccessToFlushJsCss() + { + $this->mockAuthorization->expects($this->atLeastOnce()) + ->method('isAllowed') + ->with('Magento_Backend::flush_js_css') + ->willReturn(true); + + $this->assertTrue($this->permissions->hasAccessToFlushJsCss()); + } + + public function testHasAccessToFlushStaticFiles() + { + $this->mockAuthorization->expects($this->atLeastOnce()) + ->method('isAllowed') + ->with('Magento_Backend::flush_static_files') + ->willReturn(true); + + $this->assertTrue($this->permissions->hasAccessToFlushStaticFiles()); + } +} diff --git a/app/code/Magento/Backend/Test/Unit/Block/GlobalSearchTest.php b/app/code/Magento/Backend/Test/Unit/Block/GlobalSearchTest.php new file mode 100644 index 0000000000000..0010ffad87524 --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Block/GlobalSearchTest.php @@ -0,0 +1,123 @@ + \Magento\Catalog\Controller\Adminhtml\Product::ADMIN_RESOURCE, + 'Orders' => \Magento\Sales\Controller\Adminhtml\Order::ADMIN_RESOURCE, + 'Customers' => \Magento\Customer\Controller\Adminhtml\Index::ADMIN_RESOURCE, + 'Pages' => \Magento\Cms\Controller\Adminhtml\Page\Index::ADMIN_RESOURCE, + ]; + + /** + * @var array + */ + private $entityPaths = [ + 'Products' => 'catalog/product/index/', + 'Orders' => 'sales/order/index/', + 'Customers' => 'customer/index/index', + 'Pages' => 'cms/page/index/', + ]; + + protected function setUp() + { + $objectManager = new ObjectManager($this); + + $this->authorization = $this->createMock(\Magento\Framework\AuthorizationInterface::class); + $this->urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class); + $context = $this->createMock(\Magento\Backend\Block\Template\Context::class); + + $context->expects($this->atLeastOnce())->method('getAuthorization')->willReturn($this->authorization); + $context->expects($this->atLeastOnce())->method('getUrlBuilder')->willReturn($this->urlBuilder); + + $this->searchEntityFactory = $this->createMock(\Magento\Backend\Model\GlobalSearch\SearchEntityFactory::class); + + $this->globalSearch = $objectManager->getObject( + GlobalSearch::class, + [ + 'context' => $context, + 'searchEntityFactory' => $this->searchEntityFactory, + 'entityResources' => $this->entityResources, + 'entityPaths' => $this->entityPaths, + ] + ); + } + + /** + * @param array $results + * @param int $expectedEntitiesQty + * + * @dataProvider getEntitiesToShowDataProvider + */ + public function testGetEntitiesToShow(array $results, int $expectedEntitiesQty) + { + $searchEntity = $this->createMock(SearchEntity::class); + + $this->authorization->expects($this->exactly(count($results)))->method('isAllowed') + ->willReturnOnConsecutiveCalls($results[0], $results[1], $results[2], $results[3]); + $this->urlBuilder->expects($this->exactly($expectedEntitiesQty)) + ->method('getUrl')->willReturn('some/url/is/here'); + $this->searchEntityFactory->expects($this->exactly($expectedEntitiesQty)) + ->method('create')->willReturn($searchEntity); + + $searchEntity->expects($this->exactly($expectedEntitiesQty))->method('setId'); + $searchEntity->expects($this->exactly($expectedEntitiesQty))->method('setTitle'); + $searchEntity->expects($this->exactly($expectedEntitiesQty))->method('setUrl'); + + $this->assertSame($expectedEntitiesQty, count($this->globalSearch->getEntitiesToShow())); + } + + public function getEntitiesToShowDataProvider() + { + return [ + [ + [true, false, true, false], + 2, + ], + [ + [true, true, true, true], + 4, + ], + [ + [false, false, false, false], + 0, + ], + ]; + } +} diff --git a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnSetTest.php b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnSetTest.php index be171a8ed40bf..df242a4cf6129 100644 --- a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnSetTest.php +++ b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnSetTest.php @@ -117,7 +117,7 @@ public function testSetFilterTypePropagatesFilterTypeToColumns() public function testGetRowUrlIfUrlPathNotSet() { - $this->assertEquals('#', $this->_block->getRowUrl(new \StdClass())); + $this->assertEquals('#', $this->_block->getRowUrl(new \stdClass())); } public function testGetRowUrl() diff --git a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnTest.php b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnTest.php index da13af87b71ea..c5c56fd75fbe7 100644 --- a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnTest.php +++ b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ColumnTest.php @@ -351,7 +351,7 @@ public function testSetGetGrid() $this->_block->setFilter('StdClass'); - $grid = new \StdClass(); + $grid = new \stdClass(); $this->_block->setGrid($grid); $this->assertEquals($grid, $this->_block->getGrid()); } diff --git a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php index bb389a996e1ed..29ce448a04ecb 100644 --- a/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php +++ b/app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php @@ -10,6 +10,7 @@ namespace Magento\Backend\Test\Unit\Block\Widget\Grid; use Magento\Backend\Block\Widget\Grid\Massaction\VisibilityCheckerInterface as VisibilityChecker; +use Magento\Framework\Authorization; class MassactionTest extends \PHPUnit\Framework\TestCase { @@ -43,6 +44,11 @@ class MassactionTest extends \PHPUnit\Framework\TestCase */ protected $_requestMock; + /** + * @var Authorization|\PHPUnit_Framework_MockObject_MockObject + */ + protected $_authorizationMock; + /** * @var VisibilityChecker|\PHPUnit_Framework_MockObject_MockObject */ @@ -86,11 +92,17 @@ protected function setUp() $this->visibilityCheckerMock = $this->getMockBuilder(VisibilityChecker::class) ->getMockForAbstractClass(); + $this->_authorizationMock = $this->getMockBuilder(Authorization::class) + ->disableOriginalConstructor() + ->setMethods(['isAllowed']) + ->getMock(); + $arguments = [ 'layout' => $this->_layoutMock, 'request' => $this->_requestMock, 'urlBuilder' => $this->_urlModelMock, - 'data' => ['massaction_id_field' => 'test_id', 'massaction_id_filter' => 'test_id'] + 'data' => ['massaction_id_field' => 'test_id', 'massaction_id_filter' => 'test_id'], + 'authorization' => $this->_authorizationMock, ]; $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -145,6 +157,10 @@ public function testItemsProcessing($itemId, $item, $expectedItem) ->method('getUrl') ->willReturnMap($urlReturnValueMap); + $this->_authorizationMock->expects($this->any()) + ->method('isAllowed') + ->willReturn(true); + $this->_block->addItem($itemId, $item); $this->assertEquals(1, $this->_block->getCount()); @@ -184,6 +200,28 @@ public function itemsProcessingDataProvider() "id" => 'test_id2', ] ) + ], + [ + 'enabled', + new \Magento\Framework\DataObject(["label" => "Test Item Enabled", "url" => "*/*/test2"]), + new \Magento\Framework\DataObject( + [ + "label" => "Test Item Enabled", + "url" => "http://localhost/index.php/backend/admin/test/test2", + "id" => 'enabled', + ] + ) + ], + [ + 'refresh', + new \Magento\Framework\DataObject(["label" => "Test Item Refresh", "url" => "*/*/test2"]), + new \Magento\Framework\DataObject( + [ + "label" => "Test Item Refresh", + "url" => "http://localhost/index.php/backend/admin/test/test2", + "id" => 'refresh', + ] + ) ] ]; } @@ -237,7 +275,7 @@ public function testGetGridIdsJsonWithoutUseSelectAll() public function testGetGridIdsJsonWithUseSelectAll(array $items, $result) { $this->_block->setUseSelectAll(true); - + if ($this->_block->getMassactionIdField()) { $massActionIdField = $this->_block->getMassactionIdField(); } else { @@ -290,14 +328,20 @@ public function dataProviderGetGridIdsJsonWithUseSelectAll() * @param int $count * @param bool $withVisibilityChecker * @param bool $isVisible + * @param bool $isAllowed + * * @dataProvider addItemDataProvider */ - public function testAddItem($itemId, $item, $count, $withVisibilityChecker, $isVisible) + public function testAddItem($itemId, $item, $count, $withVisibilityChecker, $isVisible, $isAllowed) { $this->visibilityCheckerMock->expects($this->any()) ->method('isVisible') ->willReturn($isVisible); + $this->_authorizationMock->expects($this->any()) + ->method('isAllowed') + ->willReturn($isAllowed); + if ($withVisibilityChecker) { $item['visible'] = $this->visibilityCheckerMock; } @@ -311,7 +355,7 @@ public function testAddItem($itemId, $item, $count, $withVisibilityChecker, $isV ->willReturnMap($urlReturnValueMap); $this->_block->addItem($itemId, $item); - $this->assertEquals($count, $this->_block->getCount()); + $this->assertEquals($count, $this->_block->getCount(), $itemId); } /** @@ -325,7 +369,8 @@ public function addItemDataProvider() 'item' => ['label' => 'Test 1', 'url' => '*/*/test1'], 'count' => 1, 'withVisibilityChecker' => false, - '$isVisible' => false, + 'isVisible' => false, + 'isAllowed' => true, ], [ 'itemId' => 'test2', @@ -333,21 +378,56 @@ public function addItemDataProvider() 'count' => 1, 'withVisibilityChecker' => false, 'isVisible' => true, + 'isAllowed' => true, ], [ - 'itemId' => 'test1', - 'item' => ['label' => 'Test 1. Hide', 'url' => '*/*/test1'], + 'itemId' => 'test3', + 'item' => ['label' => 'Test 3. Hide', 'url' => '*/*/test3'], 'count' => 0, 'withVisibilityChecker' => true, 'isVisible' => false, + 'isAllowed' => true, ], [ - 'itemId' => 'test2', - 'item' => ['label' => 'Test 2. Does not hide', 'url' => '*/*/test2'], + 'itemId' => 'test4', + 'item' => ['label' => 'Test 4. Does not hide', 'url' => '*/*/test4'], 'count' => 1, 'withVisibilityChecker' => true, 'isVisible' => true, - ] + 'isAllowed' => true, + ], + [ + 'itemId' => 'enable', + 'item' => ['label' => 'Test 5. Not restricted', 'url' => '*/*/test5'], + 'count' => 1, + 'withVisibilityChecker' => true, + 'isVisible' => true, + 'isAllowed' => true, + ], + [ + 'itemId' => 'enable', + 'item' => ['label' => 'Test 5. restricted', 'url' => '*/*/test5'], + 'count' => 0, + 'withVisibilityChecker' => true, + 'isVisible' => true, + 'isAllowed' => false, + ], + [ + 'itemId' => 'refresh', + 'item' => ['label' => 'Test 6. Not Restricted', 'url' => '*/*/test6'], + 'count' => 1, + 'withVisibilityChecker' => true, + 'isVisible' => true, + 'isAllowed' => true, + ], + [ + 'itemId' => 'refresh', + 'item' => ['label' => 'Test 6. Restricted', 'url' => '*/*/test6'], + 'count' => 0, + 'withVisibilityChecker' => true, + 'isVisible' => true, + 'isAllowed' => false, + ], ]; } } diff --git a/app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php b/app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php index 31a13191750a3..2f0102ffd410d 100755 --- a/app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php @@ -20,7 +20,8 @@ public function testBeforeSave($value, $errorMessage = null) \Magento\Backend\Model\Config\SessionLifetime\BackendModel::class ); if ($errorMessage !== null) { - $this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage); + $this->expectException(\Magento\Framework\Exception\LocalizedException::class); + $this->expectExceptionMessage($errorMessage); } $model->setValue($value); $object = $model->beforeSave(); diff --git a/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php b/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php index 74368537c39c7..ad172cbfbd165 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php @@ -56,9 +56,9 @@ class ItemTest extends \PHPUnit\Framework\TestCase 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ]; protected function setUp() diff --git a/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_constructor_data.php b/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_constructor_data.php index b0c74461980a2..82f07e264b963 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_constructor_data.php +++ b/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_constructor_data.php @@ -12,21 +12,21 @@ 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], [ 'parent_id' => null, - 'module_name' => 'Magento_Backend', + 'module' => 'Magento_Backend', 'sort_index' => null, - 'depends_on_config' => 'system/config/isEnabled', + 'dependsOnConfig' => 'system/config/isEnabled', 'id' => 'item', 'resource' => 'Magento_Config::config', 'path' => '', 'action' => '/system/config', - 'depends_on_module' => 'Magento_Backend', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'toolTip' => 'Item tooltip', 'title' => 'Item Title', 'sub_menu' => null, 'target' => null @@ -38,43 +38,43 @@ 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', - 'depends_on_config' => null, + 'dependsOnConfig' => null, 'id' => '5', 'resource' => null, 'path' => null, 'action' => null, - 'depends_on_module' => null, - 'tooltip' => null, + 'dependsOnModule' => null, + 'toolTip' => null, 'title' => null, 'sub_menu' => [ 'id' => 'item', 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], ], [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', - 'depends_on_config' => null, + 'dependsOnConfig' => null, 'id' => '5', 'resource' => null, 'path' => '', 'action' => null, - 'depends_on_module' => null, - 'tooltip' => '', + 'dependsOnModule' => null, + 'toolTip' => '', 'title' => null, 'sub_menu' => ['submenuArray'], 'target' => null @@ -83,51 +83,51 @@ 'data with submenu to constructor' => [ [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', - 'depends_on_config' => null, + 'dependsOnConfig' => null, 'id' => '5', 'resource' => null, 'path' => null, 'action' => null, - 'depends_on_module' => null, - 'tooltip' => null, + 'dependsOnModule' => null, + 'toolTip' => null, 'title' => null, 'sub_menu' => [ 'id' => 'item', 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], ], [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', 'sub_menu' => [ 'id' => 'item', 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], ], [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', - 'depends_on_config' => null, + 'dependsOnConfig' => null, 'id' => null, 'resource' => null, 'path' => '', 'action' => null, - 'depends_on_module' => null, - 'tooltip' => '', + 'dependsOnModule' => null, + 'toolTip' => '', 'title' => null, 'sub_menu' => ['submenuArray'], 'target' => null diff --git a/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_data.php b/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_data.php index 30a43b0158ae3..b1a310d7d440b 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_data.php +++ b/app/code/Magento/Backend/Test/Unit/Model/_files/menu_item_data.php @@ -11,22 +11,22 @@ 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', 'sub_menu' => null, ], [ 'parent_id' => null, - 'module_name' => 'Magento_Backend', + 'module' => 'Magento_Backend', 'sort_index' => null, - 'depends_on_config' => 'system/config/isEnabled', + 'dependsOnConfig' => 'system/config/isEnabled', 'id' => 'item', 'resource' => 'Magento_Config::config', 'path' => '', 'action' => '/system/config', - 'depends_on_module' => 'Magento_Backend', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'toolTip' => 'Item tooltip', 'title' => 'Item Title', 'sub_menu' => null, 'target' => null @@ -35,46 +35,46 @@ 'with submenu' => [ [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', - 'depends_on_config' => null, + 'dependsOnConfig' => null, 'id' => '5', 'resource' => null, 'path' => null, 'action' => null, - 'depends_on_module' => null, - 'tooltip' => null, + 'dependsOnModule' => null, + 'toolTip' => null, 'title' => null, 'sub_menu' => [ 'id' => 'item', 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], ], [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', - 'depends_on_config' => null, + 'dependsOnConfig' => null, 'id' => '5', 'resource' => null, 'path' => null, 'action' => null, - 'depends_on_module' => null, - 'tooltip' => '', + 'dependsOnModule' => null, + 'toolTip' => '', 'title' => null, 'sub_menu' => [ 'id' => 'item', 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], 'target' => null ] @@ -82,38 +82,38 @@ 'small set of data' => [ [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', 'sub_menu' => [ 'id' => 'item', 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], ], [ 'parent_id' => '1', - 'module_name' => 'Magento_Module1', + 'module' => 'Magento_Module1', 'sort_index' => '50', - 'depends_on_config' => null, + 'dependsOnConfig' => null, 'id' => null, 'resource' => null, 'path' => '', 'action' => null, - 'depends_on_module' => null, - 'tooltip' => '', + 'dependsOnModule' => null, + 'toolTip' => '', 'title' => null, 'sub_menu' => [ 'id' => 'item', 'title' => 'Item Title', 'action' => '/system/config', 'resource' => 'Magento_Config::config', - 'depends_on_module' => 'Magento_Backend', - 'depends_on_config' => 'system/config/isEnabled', - 'tooltip' => 'Item tooltip', + 'dependsOnModule' => 'Magento_Backend', + 'dependsOnConfig' => 'system/config/isEnabled', + 'toolTip' => 'Item tooltip', ], 'target' => null ] diff --git a/app/code/Magento/Backend/composer.json b/app/code/Magento/Backend/composer.json index d3c94c1e286e0..13a99176b6532 100644 --- a/app/code/Magento/Backend/composer.json +++ b/app/code/Magento/Backend/composer.json @@ -6,25 +6,25 @@ "magento/module-store": "100.2.*", "magento/module-directory": "100.2.*", "magento/module-developer": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-reports": "100.2.*", - "magento/module-sales": "100.2.*", - "magento/module-quote": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-user": "100.2.*", + "magento/module-sales": "101.0.*", + "magento/module-quote": "101.0.*", + "magento/module-catalog": "102.0.*", + "magento/module-user": "101.0.*", "magento/module-security": "100.2.*", "magento/module-backup": "100.2.*", - "magento/module-customer": "100.2.*", + "magento/module-customer": "101.0.*", "magento/module-translation": "100.2.*", "magento/module-require-js": "100.2.*", - "magento/module-config": "100.2.*", - "magento/framework": "100.2.*" + "magento/module-config": "101.0.*", + "magento/framework": "101.0.*" }, "suggest": { "magento/module-theme": "100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.3", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Backend/etc/acl.xml b/app/code/Magento/Backend/etc/acl.xml index af4ab5856e94c..cf9471e75bed9 100644 --- a/app/code/Magento/Backend/etc/acl.xml +++ b/app/code/Magento/Backend/etc/acl.xml @@ -38,7 +38,21 @@ - + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Backend/etc/adminhtml/di.xml b/app/code/Magento/Backend/etc/adminhtml/di.xml index 5154c4eb56c91..de8286e7f3ecc 100644 --- a/app/code/Magento/Backend/etc/adminhtml/di.xml +++ b/app/code/Magento/Backend/etc/adminhtml/di.xml @@ -145,6 +145,30 @@ Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED + + + + + + + + Magento\Backend\Block\Template + + + + + + Magento_Catalog::products + Magento_Sales::sales_order + Magento_Customer::manage + Magento_Cms::page + + + catalog/product/index/ + sales/order/index/ + customer/index/index + cms/page/index/ + diff --git a/app/code/Magento/Backend/etc/adminhtml/system.xml b/app/code/Magento/Backend/etc/adminhtml/system.xml index 27fd16cc920dc..3a58ef9f63e8d 100644 --- a/app/code/Magento/Backend/etc/adminhtml/system.xml +++ b/app/code/Magento/Backend/etc/adminhtml/system.xml @@ -215,7 +215,7 @@ Magento\Directory\Model\Config\Source\Country - + Magento\Directory\Model\Config\Source\Country @@ -409,7 +409,7 @@ general Magento_Config::web - + @@ -419,7 +419,7 @@ Warning! When using Store Code in URLs, in some cases system may not work properly if URLs without Store Codes are specified in the third party services (e.g. PayPal etc.).]]> - + Magento\Config\Model\Config\Source\Web\Redirect I.e. redirect from http://example.com/store/ to http://www.example.com/store/ diff --git a/app/code/Magento/Backend/i18n/en_US.csv b/app/code/Magento/Backend/i18n/en_US.csv index 2730d4d92835b..aa28a670b9205 100644 --- a/app/code/Magento/Backend/i18n/en_US.csv +++ b/app/code/Magento/Backend/i18n/en_US.csv @@ -214,10 +214,13 @@ YTD,YTD "Admin session lifetime must be greater than or equal to 60 seconds","Admin session lifetime must be greater than or equal to 60 seconds" Order,Order "Order #%1","Order #%1" -"Access denied","Access denied" -"Please try to sign out and sign in again.","Please try to sign out and sign in again." -"If you continue to receive this message, please contact the store owner.","If you continue to receive this message, please contact the store owner." "You need more permissions to access this.","You need more permissions to access this." +"Sorry, you need permissions to view this content.","Sorry, you need permissions to view this content." +"Next steps","Next steps" +"If you think this is an error, try signing out and signing in again.","If you think this is an error, try signing out and signing in again." +"Contact a system administrator or store owner to gain permissions.","Contact a system administrator or store owner to gain permissions." +"Return to","Return to" +"previous page","previous page" "Welcome, please sign in","Welcome, please sign in" Username,Username "user name","user name" @@ -458,3 +461,7 @@ Pagination,Pagination "Alternative text for the next pages link in the pagination menu. If empty, default arrow image is used.","Alternative text for the next pages link in the pagination menu. If empty, default arrow image is used." "Anchor Text for Next","Anchor Text for Next" "Theme Name","Theme Name" +"In Products","In Products" +"In Orders","In Orders" +"In Customers","In Customers" +"In Pages","In Pages" diff --git a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_block.xml b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_block.xml index f6a93fbd84099..50d210f71025b 100644 --- a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_block.xml +++ b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_block.xml @@ -42,7 +42,7 @@ 0 - + Cache Type cache_type @@ -53,7 +53,7 @@ true - + Description description @@ -63,7 +63,7 @@ true - + Tags tags @@ -73,7 +73,7 @@ 0 - + Status status diff --git a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_index.xml b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_index.xml index ab5ddc414b51f..4bbe70b6cdb92 100644 --- a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_index.xml +++ b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_cache_index.xml @@ -11,7 +11,11 @@ - + + + Magento\Backend\Block\Cache\Permissions + + diff --git a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_design_grid_block.xml b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_design_grid_block.xml index 52d88ce717043..b96614f4bd8db 100644 --- a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_design_grid_block.xml +++ b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_design_grid_block.xml @@ -28,7 +28,7 @@ - + Store 100px @@ -38,7 +38,7 @@ store_id - + Design options @@ -47,7 +47,7 @@ design - + Date From left @@ -57,7 +57,7 @@ date_from - + Date To left diff --git a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_store_grid_block.xml b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_store_grid_block.xml index 8dcb6e07b3c4e..126de5eb4084f 100644 --- a/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_store_grid_block.xml +++ b/app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_store_grid_block.xml @@ -18,7 +18,7 @@ storeGrid - + Web Site left @@ -27,7 +27,7 @@ Magento\Backend\Block\System\Store\Grid\Render\Website - + Store left @@ -36,7 +36,7 @@ Magento\Backend\Block\System\Store\Grid\Render\Group - + Store View left diff --git a/app/code/Magento/Backend/view/adminhtml/templates/admin/access_denied.phtml b/app/code/Magento/Backend/view/adminhtml/templates/admin/access_denied.phtml index 852ecd5a07962..843328fbf17d7 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/admin/access_denied.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/admin/access_denied.phtml @@ -12,12 +12,23 @@ * @see \Magento\Backend\Block\Denied */ ?> -

-hasAvailableResources()): ?> -

-
- -

- -

- +
+
+

escapeHtml(__('Sorry, you need permissions to view this content.')) ?>

+ escapeHtml(__('Next steps')) ?> + +
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 40b7173f47417..8feccc9cf1b8f 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/page/header.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/page/header.phtml @@ -29,7 +29,7 @@ data-mage-init='{"dropdown":{}}' data-toggle="dropdown"> - +
    @@ -39,7 +39,7 @@ href="getUrl('adminhtml/system_account/index') ?>" getUiId('user', 'account', 'settings') ?> title="escapeHtml(__('Account Setting')) ?>"> - (escapeHtml($block->getUser()->getUsername()) ?>) + (escapeHtml($block->getUser()->getUserName()) ?>) diff --git a/app/code/Magento/Backend/view/adminhtml/templates/page/report.phtml b/app/code/Magento/Backend/view/adminhtml/templates/page/report.phtml index 3a3dbd99bfba9..4ef6d378cc4a4 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/page/report.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/page/report.phtml @@ -8,5 +8,7 @@ ?> getBugreportUrl()): ?> - + + + diff --git a/app/code/Magento/Backend/view/adminhtml/templates/system/cache/additional.phtml b/app/code/Magento/Backend/view/adminhtml/templates/system/cache/additional.phtml index 84bbc4ea601ef..8e30afdf51f7f 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/system/cache/additional.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/system/cache/additional.phtml @@ -5,34 +5,39 @@ */ // @codingStandardsIgnoreFile + +/** @var \Magento\Backend\Block\Cache\Permissions|null $permissions */ +$permissions = $block->getData('permissions'); ?> -
    -

    - -

    -

    - - -

    -

    - - -

    - isInProductionMode()): - ?> -

    - - -

    - - getChildHtml() ?> -
    +hasAccessToAdditionalActions()): ?> +
    + hasAccessToFlushCatalogImages()): ?> +

    + escapeHtml(__('Additional Cache Management')); ?> +

    +

    + + escapeHtml(__('Pregenerated product images files')); ?> +

    + + hasAccessToFlushJsCss()): ?> +

    + + escapeHtml(__('Themes JavaScript and CSS files combined to one file')) ?> +

    + + isInProductionMode() && $permissions->hasAccessToFlushStaticFiles()): ?> +

    + + escapeHtml(__('Preprocessed view files and static files')); ?> +

    + + getChildHtml() ?> +
    + diff --git a/app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml b/app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml index a528133b2bc3a..3c65c0358eb57 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml @@ -27,18 +27,15 @@ - diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/tree.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/tree.phtml index a3cf4b478ad3b..9865589556e7b 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/tree.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/tree.phtml @@ -59,6 +59,8 @@ } }; + var treeRoot = '#tree-div'; + /** * Fix ext compatibility with prototype 1.6 */ @@ -491,7 +493,7 @@ if (data.error) { reRenderTree(); } else { - $(obj.tree.container.dom).trigger('categoryMove.tree'); + $(treeRoot).trigger('categoryMove.tree'); } $('.page-main-actions').next('.messages').remove(); $('.page-main-actions').next('#messages').remove(); diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/js.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/js.phtml index 69bc847c30f46..8a5f1919f78be 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/js.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/js.phtml @@ -196,9 +196,11 @@ function switchDefaultValueField() helper('Magento\Catalog\Helper\Data')->getAttributeHiddenFields() as $type => $fields): ?> case '': + var isFrontTabHidden = false; getFrontTab().hide(); + isFrontTabHidden = true; defaultValueTextVisibility = defaultValueTextareaVisibility = @@ -210,6 +212,10 @@ function switchDefaultValueField() setRowVisibility('', false); + + if (!isFrontTabHidden){ + getFrontTab().show(); + } break; diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml index a0041d2e02988..f812a27f87ad9 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml @@ -57,7 +57,7 @@ $stores = $block->getStoresSortedBySortOrder(); + diff --git a/app/code/Magento/CatalogSearch/view/frontend/web/js/search-terms-log.js b/app/code/Magento/CatalogSearch/view/frontend/web/js/search-terms-log.js new file mode 100644 index 0000000000000..8638a837f56b9 --- /dev/null +++ b/app/code/Magento/CatalogSearch/view/frontend/web/js/search-terms-log.js @@ -0,0 +1,21 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', + 'mageUtils' +], function ($, utils) { + 'use strict'; + + return function (data) { + $.ajax({ + method: 'GET', + url: data.url, + data: { + 'q': utils.getUrlParameters(window.location.href).q + } + }); + }; +}); diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category/UpdateUrlPath.php b/app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category/UpdateUrlPath.php new file mode 100644 index 0000000000000..75959c3872fe0 --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category/UpdateUrlPath.php @@ -0,0 +1,116 @@ +categoryUrlPathGenerator = $categoryUrlPathGenerator; + $this->categoryUrlRewriteGenerator = $categoryUrlRewriteGenerator; + $this->urlPersist = $urlPersist; + $this->storeViewService = $storeViewService; + } + + /** + * Perform url updating for different stores + * + * @param CategoryResource $subject + * @param CategoryResource $result + * @param AbstractModel $category + * @return CategoryResource + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterSave( + CategoryResource $subject, + CategoryResource $result, + AbstractModel $category + ) { + $parentCategoryId = $category->getParentId(); + if ($category->isObjectNew() + && !$category->isInRootCategoryList() + && !empty($parentCategoryId)) { + foreach ($category->getStoreIds() as $storeId) { + if (!$this->isGlobalScope($storeId) + && $this->storeViewService->doesEntityHaveOverriddenUrlPathForStore( + $storeId, + $parentCategoryId, + Category::ENTITY + ) + ) { + $category->setStoreId($storeId); + $this->updateUrlPathForCategory($category, $subject); + $this->urlPersist->replace($this->categoryUrlRewriteGenerator->generate($category)); + } + } + } + return $result; + } + + /** + * Check that store id is in global scope + * + * @param int|null $storeId + * @return bool + */ + private function isGlobalScope(int $storeId): bool + { + return null === $storeId || $storeId === Store::DEFAULT_STORE_ID; + } + + /** + * @param Category $category + * @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource + */ + private function updateUrlPathForCategory(Category $category, CategoryResource $categoryResource) + { + $category->unsUrlPath(); + $category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category)); + $categoryResource->saveAttribute($category, 'url_path'); + } +} diff --git a/app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php index 81bbb08b0f39e..9c5c37b51f0b2 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php @@ -207,8 +207,9 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ */ public function isCategoryProperForGenerating(Category $category, $storeId) { - if ($category->getParentId() != \Magento\Catalog\Model\Category::TREE_ROOT_ID) { - list(, $rootCategoryId) = $category->getParentIds(); + $parentIds = $category->getParentIds(); + if (count($parentIds) >= 2) { + $rootCategoryId = $parentIds[1]; return $rootCategoryId == $this->storeManager->getStore($storeId)->getRootCategoryId(); } return false; diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php b/app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php index 748589924d916..f0351467e5f0e 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/Storage/DbStorage.php @@ -12,25 +12,37 @@ class DbStorage extends BaseDbStorage { /** - * @param array $data - * @return \Magento\Framework\DB\Select + * {@inheritDoc} */ protected function prepareSelect(array $data) { + $metadata = []; + if (array_key_exists(UrlRewrite::METADATA, $data)) { + $metadata = $data[UrlRewrite::METADATA]; + unset($data[UrlRewrite::METADATA]); + } + $select = $this->connection->select(); - $select->from(['url_rewrite' => $this->resource->getTableName('url_rewrite')]) - ->joinLeft( - ['relation' => $this->resource->getTableName(Product::TABLE_NAME)], - 'url_rewrite.url_rewrite_id = relation.url_rewrite_id' - ) - ->where('url_rewrite.entity_id IN (?)', $data['entity_id']) - ->where('url_rewrite.entity_type = ?', $data['entity_type']) - ->where('url_rewrite.store_id IN (?)', $data['store_id']); - if (empty($data[UrlRewrite::METADATA]['category_id'])) { + $select->from([ + 'url_rewrite' => $this->resource->getTableName(self::TABLE_NAME) + ]); + $select->joinLeft( + ['relation' => $this->resource->getTableName(Product::TABLE_NAME)], + 'url_rewrite.url_rewrite_id = relation.url_rewrite_id' + ); + + foreach ($data as $column => $value) { + $select->where('url_rewrite.' . $column . ' IN (?)', $value); + } + if (empty($metadata['category_id'])) { $select->where('relation.category_id IS NULL'); } else { - $select->where('relation.category_id = ?', $data[UrlRewrite::METADATA]['category_id']); + $select->where( + 'relation.category_id = ?', + $metadata['category_id'] + ); } + return $select; } } diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php index 92a46facbe71c..5130b43333d47 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\CatalogUrlRewrite\Observer; use Magento\Catalog\Model\Category; @@ -12,6 +13,9 @@ use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap; use Magento\CatalogUrlRewrite\Model\UrlRewriteBunchReplacer; use Magento\Framework\Event\ObserverInterface; +use Magento\Store\Model\ResourceModel\Group\CollectionFactory; +use Magento\Store\Model\ResourceModel\Group\Collection as StoreGroupCollection; +use Magento\Framework\App\ObjectManager; /** * Generates Category Url Rewrites after save and Products Url Rewrites assigned to the category that's being saved @@ -43,12 +47,18 @@ class CategoryProcessUrlRewriteSavingObserver implements ObserverInterface */ private $dataUrlRewriteClassNames; + /** + * @var CollectionFactory + */ + private $storeGroupFactory; + /** * @param CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator * @param UrlRewriteHandler $urlRewriteHandler * @param UrlRewriteBunchReplacer $urlRewriteBunchReplacer * @param DatabaseMapPool $databaseMapPool * @param string[] $dataUrlRewriteClassNames + * @param CollectionFactory|null $storeGroupFactory */ public function __construct( CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator, @@ -56,15 +66,18 @@ public function __construct( UrlRewriteBunchReplacer $urlRewriteBunchReplacer, DatabaseMapPool $databaseMapPool, $dataUrlRewriteClassNames = [ - DataCategoryUrlRewriteDatabaseMap::class, - DataProductUrlRewriteDatabaseMap::class - ] + DataCategoryUrlRewriteDatabaseMap::class, + DataProductUrlRewriteDatabaseMap::class + ], + CollectionFactory $storeGroupFactory = null ) { $this->categoryUrlRewriteGenerator = $categoryUrlRewriteGenerator; $this->urlRewriteHandler = $urlRewriteHandler; $this->urlRewriteBunchReplacer = $urlRewriteBunchReplacer; $this->databaseMapPool = $databaseMapPool; $this->dataUrlRewriteClassNames = $dataUrlRewriteClassNames; + $this->storeGroupFactory = $storeGroupFactory + ?: ObjectManager::getInstance()->get(CollectionFactory::class); } /** @@ -82,10 +95,14 @@ public function execute(\Magento\Framework\Event\Observer $observer) return; } + if (!$category->hasData('store_id')) { + $this->setCategoryStoreId($category); + } + $mapsGenerated = false; if ($category->dataHasChangedFor('url_key') || $category->dataHasChangedFor('is_anchor') - || $category->getIsChangedProductList() + || $category->getChangedProductIds() ) { if ($category->dataHasChangedFor('url_key')) { $categoryUrlRewriteResult = $this->categoryUrlRewriteGenerator->generate($category); @@ -102,6 +119,29 @@ public function execute(\Magento\Framework\Event\Observer $observer) } } + /** + * in case store_id is not set for category then we can assume that it was passed through product import. + * store group must have only one root category, so receiving category's path and checking if one of it parts + * is the root category for store group, we can set default_store_id value from it to category. + * it prevents urls duplication for different stores + * ("Default Category/category/sub" and "Default Category2/category/sub") + * + * @param Category $category + * @return void + */ + private function setCategoryStoreId($category) + { + /** @var StoreGroupCollection $storeGroupCollection */ + $storeGroupCollection = $this->storeGroupFactory->create(); + + foreach ($storeGroupCollection as $storeGroup) { + /** @var \Magento\Store\Model\Group $storeGroup */ + if (in_array($storeGroup->getRootCategoryId(), explode('/', $category->getPath()))) { + $category->setStoreId($storeGroup->getDefaultStoreId()); + } + } + } + /** * Resets used data maps to free up memory and temporary tables * diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php index e4ccd0b869db7..c4d67f447e2cf 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php @@ -50,13 +50,6 @@ public function execute(\Magento\Framework\Event\Observer $observer) || $product->getIsChangedWebsites() || $product->dataHasChangedFor('visibility') ) { - $this->urlPersist->deleteByData([ - UrlRewrite::ENTITY_ID => $product->getId(), - UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, - UrlRewrite::REDIRECT_TYPE => 0, - UrlRewrite::STORE_ID => $product->getStoreId() - ]); - if ($product->isVisibleInSiteVisibility()) { $this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product)); } diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php b/app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php index 5a6777f94e2d5..9892465d1538a 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php @@ -104,7 +104,8 @@ public function generateProductUrlRewrites(\Magento\Catalog\Model\Category $cate $this->isSkippedProduct[$category->getEntityId()] = []; $saveRewriteHistory = $category->getData('save_rewrites_history'); $storeId = $category->getStoreId(); - if ($category->getAffectedProductIds()) { + + if ($category->getChangedProductIds()) { $this->isSkippedProduct[$category->getEntityId()] = $category->getAffectedProductIds(); /* @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */ $collection = $this->productCollectionFactory->create() @@ -140,6 +141,7 @@ public function generateProductUrlRewrites(\Magento\Catalog\Model\Category $cate ) ); } + foreach ($this->childrenCategoriesProvider->getChildren($category, true) as $childCategory) { $mergeDataProvider->merge( $this->getCategoryProductsUrlRewrites( diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/Category/UpdateUrlPathTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/Category/UpdateUrlPathTest.php new file mode 100644 index 0000000000000..a09620f0797ab --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/Category/UpdateUrlPathTest.php @@ -0,0 +1,163 @@ +objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->categoryUrlPathGenerator = $this->getMockBuilder( + \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator::class + ) + ->disableOriginalConstructor() + ->setMethods(['getUrlPath']) + ->getMock(); + $this->categoryUrlRewriteGenerator = $this->getMockBuilder( + \Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator::class + ) + ->disableOriginalConstructor() + ->setMethods(['generate']) + ->getMock(); + $this->categoryResource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Category::class) + ->disableOriginalConstructor() + ->setMethods(['saveAttribute']) + ->getMock(); + $this->category = $this->getMockBuilder(\Magento\Catalog\Model\Category::class) + ->disableOriginalConstructor() + ->setMethods( + [ + 'getStoreId', + 'getParentId', + 'isObjectNew', + 'isInRootCategoryList', + 'getStoreIds', + 'setStoreId', + 'unsUrlPath', + 'setUrlPath' + ] + ) + ->getMock(); + $this->storeViewService = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Service\V1\StoreViewService::class) + ->disableOriginalConstructor() + ->setMethods(['doesEntityHaveOverriddenUrlPathForStore']) + ->getMock(); + $this->urlPersist = $this->getMockBuilder(\Magento\UrlRewrite\Model\UrlPersistInterface::class) + ->disableOriginalConstructor() + ->setMethods(['replace']) + ->getMockForAbstractClass(); + + $this->updateUrlPathPlugin = $this->objectManager->getObject( + \Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\UpdateUrlPath::class, + [ + 'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator, + 'categoryUrlRewriteGenerator' => $this->categoryUrlRewriteGenerator, + 'urlPersist' => $this->urlPersist, + 'storeViewService' => $this->storeViewService + ] + ); + } + + public function testAroundSaveWithoutRootCategory() + { + $this->category->expects($this->atLeastOnce())->method('getParentId')->willReturn(0); + $this->category->expects($this->atLeastOnce())->method('isObjectNew')->willReturn(true); + $this->category->expects($this->atLeastOnce())->method('isInRootCategoryList')->willReturn(false); + $this->category->expects($this->never())->method('getStoreIds'); + + $this->assertEquals( + $this->categoryResource, + $this->updateUrlPathPlugin->afterSave($this->categoryResource, $this->categoryResource, $this->category) + ); + } + + public function testAroundSaveWithRootCategory() + { + $parentId = 1; + $categoryStoreIds = [0,1,2]; + $generatedUrlPath = 'parent_category/child_category'; + + $this->categoryUrlPathGenerator->expects($this->once())->method('getUrlPath')->with($this->category) + ->willReturn($generatedUrlPath); + $this->category->expects($this->atLeastOnce())->method('getParentId')->willReturn($parentId); + $this->category->expects($this->atLeastOnce())->method('isObjectNew')->willReturn(true); + $this->category->expects($this->atLeastOnce())->method('isInRootCategoryList')->willReturn(false); + $this->category->expects($this->atLeastOnce())->method('getStoreIds')->willReturn($categoryStoreIds); + $this->category->expects($this->once())->method('setStoreId')->with($categoryStoreIds[2])->willReturnSelf(); + $this->category->expects($this->once())->method('unsUrlPath')->willReturnSelf(); + $this->category->expects($this->once())->method('setUrlPath')->with($generatedUrlPath)->willReturnSelf(); + $this->storeViewService->expects($this->exactly(2))->method('doesEntityHaveOverriddenUrlPathForStore') + ->willReturnMap( + [ + [ + $categoryStoreIds[1], $parentId, 'catalog_category', false + ], + [ + $categoryStoreIds[2], $parentId, 'catalog_category', true + ] + ] + ); + $this->categoryResource->expects($this->once())->method('saveAttribute')->with($this->category, 'url_path') + ->willReturnSelf(); + $generatedUrlRewrite = $this->getMockBuilder(\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::class) + ->disableOriginalConstructor() + ->getMock(); + $this->categoryUrlRewriteGenerator->expects($this->once())->method('generate')->with($this->category) + ->willReturn([$generatedUrlRewrite]); + $this->urlPersist->expects($this->once())->method('replace')->with([$generatedUrlRewrite])->willReturnSelf(); + + $this->assertEquals( + $this->categoryResource, + $this->updateUrlPathPlugin->afterSave($this->categoryResource, $this->categoryResource, $this->category) + ); + } +} diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductScopeRewriteGeneratorTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductScopeRewriteGeneratorTest.php index 48399d5ef612b..06be01445df4c 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductScopeRewriteGeneratorTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductScopeRewriteGeneratorTest.php @@ -47,6 +47,9 @@ class ProductScopeRewriteGeneratorTest extends \PHPUnit\Framework\TestCase /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */ private $serializer; + /** @var \Magento\Catalog\Model\Category|\PHPUnit_Framework_MockObject_MockObject */ + private $categoryMock; + public function setUp() { $this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class); @@ -83,6 +86,10 @@ function ($value) { $this->storeViewService = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Service\V1\StoreViewService::class) ->disableOriginalConstructor()->getMock(); $this->storeManager = $this->createMock(StoreManagerInterface::class); + $storeRootCategoryId = 2; + $store = $this->getMockBuilder(\Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock(); + $store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($storeRootCategoryId)); + $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $mergeDataProviderFactory = $this->createPartialMock( \Magento\UrlRewrite\Model\MergeDataProviderFactory::class, ['create'] @@ -103,6 +110,7 @@ function ($value) { 'mergeDataProviderFactory' => $mergeDataProviderFactory ] ); + $this->categoryMock = $this->getMockBuilder(Category::class)->disableOriginalConstructor()->getMock(); } public function testGenerationForGlobalScope() @@ -112,12 +120,6 @@ public function testGenerationForGlobalScope() $product->expects($this->any())->method('getStoreIds')->will($this->returnValue([1])); $this->storeViewService->expects($this->once())->method('doesEntityHaveOverriddenUrlKeyForStore') ->will($this->returnValue(false)); - $categoryMock = $this->getMockBuilder(Category::class) - ->disableOriginalConstructor() - ->getMock(); - $categoryMock->expects($this->once()) - ->method('getParentId') - ->willReturn(1); $this->initObjectRegistryFactory([]); $canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer); $canonical->setRequestPath('category-1') @@ -149,25 +151,21 @@ public function testGenerationForGlobalScope() 'category-3_3' => $current, 'category-4_4' => $anchorCategories ], - $this->productScopeGenerator->generateForGlobalScope([$categoryMock], $product, 1) + $this->productScopeGenerator->generateForGlobalScope([$this->categoryMock], $product, 1) ); } public function testGenerationForSpecificStore() { + $storeRootCategoryId = 2; + $category_id = 4; $product = $this->createMock(\Magento\Catalog\Model\Product::class); $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); $product->expects($this->never())->method('getStoreIds'); - $storeRootCategoryId = 'root-for-store-id'; - $category = $this->createMock(\Magento\Catalog\Model\Category::class); - $category->expects($this->any())->method('getParentIds') + $this->categoryMock->expects($this->any())->method('getParentIds') ->will($this->returnValue(['root-id', $storeRootCategoryId])); - $category->expects($this->any())->method('getParentId')->will($this->returnValue('parent_id')); - $category->expects($this->any())->method('getId')->will($this->returnValue('category_id')); - $store = $this->getMockBuilder(\Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock(); - $store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($storeRootCategoryId)); - $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $this->initObjectRegistryFactory([$category]); + $this->categoryMock->expects($this->any())->method('getId')->will($this->returnValue($category_id)); + $this->initObjectRegistryFactory([$this->categoryMock]); $canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer); $canonical->setRequestPath('category-1') ->setStoreId(1); @@ -184,7 +182,7 @@ public function testGenerationForSpecificStore() $this->assertEquals( ['category-1_1' => $canonical], - $this->productScopeGenerator->generateForSpecificStoreView(1, [$category], $product, 1) + $this->productScopeGenerator->generateForSpecificStoreView(1, [$this->categoryMock], $product, 1) ); } @@ -212,4 +210,40 @@ protected function initObjectRegistryFactory($entities) ->with(['entities' => $entities]) ->will($this->returnValue($objectRegistry)); } + + /** + * Test the possibility of url rewrite generation. + * + * @param array $parentIds + * @param bool $expectedResult + * @dataProvider isCategoryProperForGeneratingDataProvider + */ + public function testIsCategoryProperForGenerating($parentIds, $expectedResult) + { + $storeId = 1; + $this->categoryMock->expects(self::any())->method('getParentIds')->willReturn($parentIds); + $result = $this->productScopeGenerator->isCategoryProperForGenerating( + $this->categoryMock, + $storeId + ); + self::assertEquals( + $expectedResult, + $result + ); + } + + /** + * Data provider for testIsCategoryProperForGenerating. + * + * @return array + */ + public function isCategoryProperForGeneratingDataProvider() + { + return [ + [['0'], false], + [['1'], false], + [['1', '2'], true], + [['1', '3'], false], + ]; + } } diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php new file mode 100644 index 0000000000000..d00b0c87fa5ad --- /dev/null +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php @@ -0,0 +1,142 @@ +urlRewriteFactory = $this + ->getMockBuilder(UrlRewriteFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $this->dataObjectHelper = $this->createMock(DataObjectHelper::class); + $this->connectionMock = $this->createMock(AdapterInterface::class); + $this->select = $this->createPartialMock( + Select::class, + ['from', 'where', 'deleteFromSelect', 'joinLeft'] + ); + $this->resource = $this->createMock(ResourceConnection::class); + + $this->resource->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue($this->connectionMock)); + $this->connectionMock->expects($this->any()) + ->method('select') + ->will($this->returnValue($this->select)); + + $this->storage = (new ObjectManager($this))->getObject( + DbStorage::class, + [ + 'urlRewriteFactory' => $this->urlRewriteFactory, + 'dataObjectHelper' => $this->dataObjectHelper, + 'resource' => $this->resource, + ] + ); + } + + public function testPrepareSelect() + { + //Passing expected parameters, checking select built. + $entityType = 'custom'; + $entityId= 42; + $storeId = 0; + $categoryId = 2; + $redirectType = 301; + //Expecting this methods to be called on select + $this->select + ->expects($this->at(2)) + ->method('where') + ->with('url_rewrite.entity_id IN (?)', $entityId) + ->willReturn($this->select); + $this->select + ->expects($this->at(3)) + ->method('where') + ->with('url_rewrite.entity_type IN (?)', $entityType) + ->willReturn($this->select); + $this->select + ->expects($this->at(4)) + ->method('where') + ->with('url_rewrite.store_id IN (?)', $storeId) + ->willReturn($this->select); + $this->select + ->expects($this->at(5)) + ->method('where') + ->with('url_rewrite.redirect_type IN (?)', $redirectType) + ->willReturn($this->select); + $this->select + ->expects($this->at(6)) + ->method('where') + ->with('relation.category_id = ?', $categoryId) + ->willReturn($this->select); + //Preparing mocks to be used + $this->select + ->expects($this->any()) + ->method('from') + ->willReturn($this->select); + $this->select + ->expects($this->any()) + ->method('joinLeft') + ->willReturn($this->select); + //Indirectly calling prepareSelect + $this->storage->findOneByData([ + UrlRewrite::ENTITY_ID => $entityId, + UrlRewrite::ENTITY_TYPE => $entityType, + UrlRewrite::STORE_ID => $storeId, + UrlRewrite::REDIRECT_TYPE => $redirectType, + UrlRewrite::METADATA => ['category_id' => $categoryId] + ]); + } +} diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php index d294f6d022ef3..39317b42af989 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php @@ -103,7 +103,6 @@ public function urlKeyDataProvider() 'isChangedWebsites' => false, 'isChangedCategories' => false, 'visibilityResult' => true, - 'expectedDeleteCount' => 1, 'expectedReplaceCount' => 1, ], @@ -113,7 +112,6 @@ public function urlKeyDataProvider() 'isChangedWebsites' => false, 'isChangedCategories' => false, 'visibilityResult' => true, - 'expectedDeleteCount' => 0, 'expectedReplaceCount' => 0 ], 'visibility changed' => [ @@ -122,7 +120,6 @@ public function urlKeyDataProvider() 'isChangedWebsites' => false, 'isChangedCategories' => false, 'visibilityResult' => true, - 'expectedDeleteCount' => 1, 'expectedReplaceCount' => 1 ], 'websites changed' => [ @@ -131,7 +128,6 @@ public function urlKeyDataProvider() 'isChangedWebsites' => true, 'isChangedCategories' => false, 'visibilityResult' => true, - 'expectedDeleteCount' => 1, 'expectedReplaceCount' => 1 ], 'categories changed' => [ @@ -140,7 +136,6 @@ public function urlKeyDataProvider() 'isChangedWebsites' => false, 'isChangedCategories' => true, 'visibilityResult' => true, - 'expectedDeleteCount' => 1, 'expectedReplaceCount' => 1 ], 'url changed invisible' => [ @@ -149,7 +144,6 @@ public function urlKeyDataProvider() 'isChangedWebsites' => false, 'isChangedCategories' => false, 'visibilityResult' => false, - 'expectedDeleteCount' => 1, 'expectedReplaceCount' => 0 ], ]; @@ -161,7 +155,6 @@ public function urlKeyDataProvider() * @param bool $isChangedWebsites * @param bool $isChangedCategories * @param bool $visibilityResult - * @param int $expectedDeleteCount * @param int $expectedReplaceCount * * @dataProvider urlKeyDataProvider @@ -172,7 +165,6 @@ public function testExecuteUrlKey( $isChangedWebsites, $isChangedCategories, $visibilityResult, - $expectedDeleteCount, $expectedReplaceCount ) { $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue(12)); @@ -194,13 +186,6 @@ public function testExecuteUrlKey( ->method('getIsChangedCategories') ->will($this->returnValue($isChangedCategories)); - $this->urlPersist->expects($this->exactly($expectedDeleteCount))->method('deleteByData')->with([ - UrlRewrite::ENTITY_ID => $this->product->getId(), - UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, - UrlRewrite::REDIRECT_TYPE => 0, - UrlRewrite::STORE_ID => $this->product->getStoreId() - ]); - $this->product->expects($this->any()) ->method('isVisibleInSiteVisibility') ->will($this->returnValue($visibilityResult)); diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/UrlRewriteHandlerTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/UrlRewriteHandlerTest.php index 747e0cfa771fd..b18597a42bf94 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/UrlRewriteHandlerTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/UrlRewriteHandlerTest.php @@ -127,7 +127,7 @@ public function testGenerateProductUrlRewrites() { /* @var \Magento\Catalog\Model\Category|\PHPUnit_Framework_MockObject_MockObject $category */ $category = $this->getMockBuilder(\Magento\Catalog\Model\Category::class) - ->setMethods(['getEntityId', 'getStoreId', 'getData', 'getAffectedProductIds']) + ->setMethods(['getEntityId', 'getStoreId', 'getData', 'getChangedProductIds']) ->disableOriginalConstructor() ->getMock(); $category->expects($this->any()) diff --git a/app/code/Magento/CatalogUrlRewrite/composer.json b/app/code/Magento/CatalogUrlRewrite/composer.json index 931e1f26f82e8..55cbab2077cef 100644 --- a/app/code/Magento/CatalogUrlRewrite/composer.json +++ b/app/code/Magento/CatalogUrlRewrite/composer.json @@ -4,17 +4,17 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-backend": "100.2.*", - "magento/module-catalog": "101.1.*", + "magento/module-catalog": "102.0.*", "magento/module-catalog-import-export": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-import-export": "100.2.*", "magento/module-store": "100.2.*", - "magento/module-url-rewrite": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-ui": "100.2.*" + "magento/module-url-rewrite": "101.0.*", + "magento/framework": "101.0.*", + "magento/module-ui": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.2", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CatalogUrlRewrite/etc/di.xml b/app/code/Magento/CatalogUrlRewrite/etc/di.xml index 2d421417bfdc0..f6426677e8ce8 100644 --- a/app/code/Magento/CatalogUrlRewrite/etc/di.xml +++ b/app/code/Magento/CatalogUrlRewrite/etc/di.xml @@ -19,6 +19,7 @@ + diff --git a/app/code/Magento/CatalogWidget/composer.json b/app/code/Magento/CatalogWidget/composer.json index 6bd93c6eb188b..44d1d6296eadd 100644 --- a/app/code/Magento/CatalogWidget/composer.json +++ b/app/code/Magento/CatalogWidget/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-catalog": "101.1.*", - "magento/module-widget": "100.2.*", + "magento/module-catalog": "102.0.*", + "magento/module-widget": "101.0.*", "magento/module-backend": "100.2.*", "magento/module-rule": "100.2.*", - "magento/module-eav": "100.2.*", - "magento/module-customer": "100.2.*", + "magento/module-eav": "101.0.*", + "magento/module-customer": "101.0.*", "magento/module-store": "100.2.*", - "magento/module-wishlist": "100.2.*", - "magento/framework": "100.2.*" + "magento/module-wishlist": "101.0.*", + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml b/app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml index 201d6ffe4c683..574cbe1107e88 100644 --- a/app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml +++ b/app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml @@ -35,8 +35,7 @@
      - -
    1. + ' : '
    2. ' ?>
      getImage($_item, $image)->toHtml() ?> diff --git a/app/code/Magento/Checkout/Block/Cart/Shipping.php b/app/code/Magento/Checkout/Block/Cart/Shipping.php index 7b0ab1bc03e5b..c52b7fe18814f 100644 --- a/app/code/Magento/Checkout/Block/Cart/Shipping.php +++ b/app/code/Magento/Checkout/Block/Cart/Shipping.php @@ -74,7 +74,8 @@ public function getJsLayout() foreach ($this->layoutProcessors as $processor) { $this->jsLayout = $processor->process($this->jsLayout); } - return $this->serializer->serialize($this->jsLayout); + + return json_encode($this->jsLayout, JSON_HEX_TAG); } /** @@ -94,6 +95,6 @@ public function getBaseUrl() */ public function getSerializedCheckoutConfig() { - return $this->serializer->serialize($this->getCheckoutConfig()); + return json_encode($this->getCheckoutConfig(), JSON_HEX_TAG); } } diff --git a/app/code/Magento/Checkout/Block/Cart/Totals.php b/app/code/Magento/Checkout/Block/Cart/Totals.php index d3d3adbe40f38..375c564f29059 100644 --- a/app/code/Magento/Checkout/Block/Cart/Totals.php +++ b/app/code/Magento/Checkout/Block/Cart/Totals.php @@ -69,7 +69,8 @@ public function getJsLayout() foreach ($this->layoutProcessors as $processor) { $this->jsLayout = $processor->process($this->jsLayout); } - return parent::getJsLayout(); + + return json_encode($this->jsLayout, JSON_HEX_TAG); } /** diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index 4ee3d070d5b77..d93475a4744ca 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -168,20 +168,19 @@ protected function getFieldConfig( $element = [ 'component' => isset($additionalConfig['component']) ? $additionalConfig['component'] : $uiComponent, - 'config' => [ - // customScope is used to group elements within a single form (e.g. they can be validated separately) - 'customScope' => $dataScopePrefix, - 'customEntry' => isset($additionalConfig['config']['customEntry']) - ? $additionalConfig['config']['customEntry'] - : null, - 'template' => 'ui/form/field', - 'elementTmpl' => isset($additionalConfig['config']['elementTmpl']) - ? $additionalConfig['config']['elementTmpl'] - : $elementTemplate, - 'tooltip' => isset($additionalConfig['config']['tooltip']) - ? $additionalConfig['config']['tooltip'] - : null - ], + 'config' => $this->mergeConfigurationNode( + 'config', + $additionalConfig, + [ + 'config' => [ + // customScope is used to group elements within a single + // form (e.g. they can be validated separately) + 'customScope' => $dataScopePrefix, + 'template' => 'ui/form/field', + 'elementTmpl' => $elementTemplate, + ], + ] + ), 'dataScope' => $dataScopePrefix . '.' . $attributeCode, 'label' => $attributeConfig['label'], 'provider' => $providerName, diff --git a/app/code/Magento/Checkout/Block/Onepage.php b/app/code/Magento/Checkout/Block/Onepage.php index bc3cd43a024a6..ca6b045ddbb5d 100644 --- a/app/code/Magento/Checkout/Block/Onepage.php +++ b/app/code/Magento/Checkout/Block/Onepage.php @@ -77,7 +77,8 @@ public function getJsLayout() foreach ($this->layoutProcessors as $processor) { $this->jsLayout = $processor->process($this->jsLayout); } - return $this->serializer->serialize($this->jsLayout); + + return json_encode($this->jsLayout, JSON_HEX_TAG); } /** @@ -119,6 +120,6 @@ public function getBaseUrl() */ public function getSerializedCheckoutConfig() { - return $this->serializer->serialize($this->getCheckoutConfig()); + return json_encode($this->getCheckoutConfig(), JSON_HEX_TAG); } } diff --git a/app/code/Magento/Checkout/Helper/Data.php b/app/code/Magento/Checkout/Helper/Data.php index b3c2e17e5d678..94a81ece5beab 100644 --- a/app/code/Magento/Checkout/Helper/Data.php +++ b/app/code/Magento/Checkout/Helper/Data.php @@ -20,6 +20,9 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper { const XML_PATH_GUEST_CHECKOUT = 'checkout/options/guest_checkout'; + /** + * @deprecated + */ const XML_PATH_CUSTOMER_MUST_BE_LOGGED = 'checkout/options/customer_must_be_logged'; /** @@ -393,6 +396,7 @@ public function isContextCheckout() * * @return boolean * @codeCoverageIgnore + * @deprecated */ public function isCustomerMustBeLogged() { diff --git a/app/code/Magento/Checkout/Model/Cart.php b/app/code/Magento/Checkout/Model/Cart.php index be5692a894865..c0ba9616754bb 100644 --- a/app/code/Magento/Checkout/Model/Cart.php +++ b/app/code/Magento/Checkout/Model/Cart.php @@ -13,9 +13,10 @@ /** * Shopping cart model + * * @api * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @deprecated 100.1.0 + * @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead */ class Cart extends DataObject implements CartInterface { diff --git a/app/code/Magento/Checkout/Model/Cart/CartInterface.php b/app/code/Magento/Checkout/Model/Cart/CartInterface.php index 2f4b679381740..890e6a5012ea5 100644 --- a/app/code/Magento/Checkout/Model/Cart/CartInterface.php +++ b/app/code/Magento/Checkout/Model/Cart/CartInterface.php @@ -12,7 +12,7 @@ * * @api * @author Magento Core Team - * @deprecated 100.1.0 + * @deprecated 100.1.0 Use \Magento\Quote\Model\Quote instead */ interface CartInterface { diff --git a/app/code/Magento/Checkout/Model/DefaultConfigProvider.php b/app/code/Magento/Checkout/Model/DefaultConfigProvider.php index b5727bf8f365e..5335e31b6b574 100644 --- a/app/code/Magento/Checkout/Model/DefaultConfigProvider.php +++ b/app/code/Magento/Checkout/Model/DefaultConfigProvider.php @@ -259,7 +259,6 @@ public function getConfig() $output['selectedShippingMethod'] = $this->getSelectedShippingMethod(); $output['storeCode'] = $this->getStoreCode(); $output['isGuestCheckoutAllowed'] = $this->isGuestCheckoutAllowed(); - $output['isCustomerLoginRequired'] = $this->isCustomerLoginRequired(); $output['registerUrl'] = $this->getRegisterUrl(); $output['checkoutUrl'] = $this->getCheckoutUrl(); $output['defaultSuccessPageUrl'] = $this->getDefaultSuccessPageUrl(); @@ -513,17 +512,6 @@ private function isCustomerLoggedIn() return (bool)$this->httpContext->getValue(CustomerContext::CONTEXT_AUTH); } - /** - * Check if customer must be logged in to proceed with checkout - * - * @return bool - * @codeCoverageIgnore - */ - private function isCustomerLoginRequired() - { - return $this->checkoutHelper->isCustomerMustBeLogged(); - } - /** * Return forgot password URL * diff --git a/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php b/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php index 6779da354faf8..22f4864e1620d 100644 --- a/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php +++ b/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php @@ -6,6 +6,8 @@ namespace Magento\Checkout\Model; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\ResourceConnection; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Framework\Exception\CouldNotSaveException; @@ -50,6 +52,11 @@ class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPa */ private $logger; + /** + * @var ResourceConnection + */ + private $connectionPull; + /** * @param \Magento\Quote\Api\GuestBillingAddressManagementInterface $billingAddressManagement * @param \Magento\Quote\Api\GuestPaymentMethodManagementInterface $paymentMethodManagement @@ -57,6 +64,7 @@ class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPa * @param \Magento\Checkout\Api\PaymentInformationManagementInterface $paymentInformationManagement * @param \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory * @param CartRepositoryInterface $cartRepository + * @param ResourceConnection|null * @codeCoverageIgnore */ public function __construct( @@ -65,7 +73,8 @@ public function __construct( \Magento\Quote\Api\GuestCartManagementInterface $cartManagement, \Magento\Checkout\Api\PaymentInformationManagementInterface $paymentInformationManagement, \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory, - CartRepositoryInterface $cartRepository + CartRepositoryInterface $cartRepository, + ResourceConnection $connectionPull = null ) { $this->billingAddressManagement = $billingAddressManagement; $this->paymentMethodManagement = $paymentMethodManagement; @@ -73,6 +82,7 @@ public function __construct( $this->paymentInformationManagement = $paymentInformationManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->cartRepository = $cartRepository; + $this->connectionPull = $connectionPull ?: ObjectManager::getInstance()->get(ResourceConnection::class); } /** @@ -84,21 +94,35 @@ public function savePaymentInformationAndPlaceOrder( \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { - $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress); + $salesConnection = $this->connectionPull->getConnection('sales'); + $checkoutConnection = $this->connectionPull->getConnection('checkout'); + $salesConnection->beginTransaction(); + $checkoutConnection->beginTransaction(); + try { - $orderId = $this->cartManagement->placeOrder($cartId); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - throw new CouldNotSaveException( - __($e->getMessage()), - $e - ); + $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress); + try { + $orderId = $this->cartManagement->placeOrder($cartId); + } catch (\Magento\Framework\Exception\LocalizedException $e) { + throw new CouldNotSaveException( + __($e->getMessage()), + $e + ); + } catch (\Exception $e) { + $this->getLogger()->critical($e); + throw new CouldNotSaveException( + __('An error occurred on the server. Please try to place the order again.'), + $e + ); + } + $salesConnection->commit(); + $checkoutConnection->commit(); } catch (\Exception $e) { - $this->getLogger()->critical($e); - throw new CouldNotSaveException( - __('An error occurred on the server. Please try to place the order again.'), - $e - ); + $salesConnection->rollBack(); + $checkoutConnection->rollBack(); + throw $e; } + return $orderId; } diff --git a/app/code/Magento/Checkout/Test/Unit/Block/Cart/ShippingTest.php b/app/code/Magento/Checkout/Test/Unit/Block/Cart/ShippingTest.php index e419a1535207e..6a2ffd87b1885 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/Cart/ShippingTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/Cart/ShippingTest.php @@ -98,10 +98,7 @@ public function testGetJsLayout() ->method('process') ->with($this->layout) ->willReturn($layoutProcessed); - - $this->serializer->expects($this->once())->method('serialize')->will( - $this->returnValue($jsonLayoutProcessed) - ); + $this->assertEquals( $jsonLayoutProcessed, $this->model->getJsLayout() @@ -121,9 +118,6 @@ public function testGetSerializedCheckoutConfig() { $checkoutConfig = ['checkout', 'config']; $this->configProvider->expects($this->once())->method('getConfig')->willReturn($checkoutConfig); - $this->serializer->expects($this->once())->method('serialize')->will( - $this->returnValue(json_encode($checkoutConfig)) - ); $this->assertEquals(json_encode($checkoutConfig), $this->model->getSerializedCheckoutConfig()); } diff --git a/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php b/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php index e47fac06d8057..54f77c95148ac 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php @@ -93,9 +93,6 @@ public function testGetJsLayout() $processedLayout = ['layout' => ['processed' => true]]; $jsonLayout = '{"layout":{"processed":true}}'; $this->layoutProcessorMock->expects($this->once())->method('process')->with([])->willReturn($processedLayout); - $this->serializer->expects($this->once())->method('serialize')->will( - $this->returnValue(json_encode($processedLayout)) - ); $this->assertEquals($jsonLayout, $this->model->getJsLayout()); } @@ -104,9 +101,6 @@ public function testGetSerializedCheckoutConfig() { $checkoutConfig = ['checkout', 'config']; $this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($checkoutConfig); - $this->serializer->expects($this->once())->method('serialize')->will( - $this->returnValue(json_encode($checkoutConfig)) - ); $this->assertEquals(json_encode($checkoutConfig), $this->model->getSerializedCheckoutConfig()); } diff --git a/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php index a33649551bdcb..48ea0b9f90aa1 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php @@ -5,6 +5,9 @@ */ namespace Magento\Checkout\Test\Unit\Model; +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\DB\Adapter\AdapterInterface; + /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -45,6 +48,11 @@ class GuestPaymentInformationManagementTest extends \PHPUnit\Framework\TestCase */ private $loggerMock; + /** + * @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject + */ + private $resourceConnectionMock; + protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -62,6 +70,10 @@ protected function setUp() ['create'] ); $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class); + $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->model = $objectManager->getObject( \Magento\Checkout\Model\GuestPaymentInformationManagement::class, [ @@ -69,7 +81,8 @@ protected function setUp() 'paymentMethodManagement' => $this->paymentMethodManagementMock, 'cartManagement' => $this->cartManagementMock, 'cartRepository' => $this->cartRepositoryMock, - 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + 'connectionPull' => $this->resourceConnectionMock, ] ); $objectManager->setBackwardCompatibleProperty($this->model, 'logger', $this->loggerMock); @@ -85,6 +98,27 @@ public function testSavePaymentInformationAndPlaceOrder() $billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf(); + $adapterMockForSales = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $adapterMockForCheckout = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->resourceConnectionMock->expects($this->at(0)) + ->method('getConnection') + ->with('sales') + ->willReturn($adapterMockForSales); + $adapterMockForSales->expects($this->once())->method('beginTransaction'); + $adapterMockForSales->expects($this->once())->method('commit'); + + $this->resourceConnectionMock->expects($this->at(1)) + ->method('getConnection') + ->with('checkout') + ->willReturn($adapterMockForCheckout); + $adapterMockForCheckout->expects($this->once())->method('beginTransaction'); + $adapterMockForCheckout->expects($this->once())->method('commit'); + $this->billingAddressManagementMock->expects($this->once()) ->method('assign') ->with($cartId, $billingAddressMock); @@ -110,6 +144,27 @@ public function testSavePaymentInformationAndPlaceOrderException() $billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf(); + $adapterMockForSales = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $adapterMockForCheckout = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->resourceConnectionMock->expects($this->at(0)) + ->method('getConnection') + ->with('sales') + ->willReturn($adapterMockForSales); + $adapterMockForSales->expects($this->once())->method('beginTransaction'); + $adapterMockForSales->expects($this->once())->method('rollback'); + + $this->resourceConnectionMock->expects($this->at(1)) + ->method('getConnection') + ->with('checkout') + ->willReturn($adapterMockForCheckout); + $adapterMockForCheckout->expects($this->once())->method('beginTransaction'); + $adapterMockForCheckout->expects($this->once())->method('rollback'); + $this->billingAddressManagementMock->expects($this->once()) ->method('assign') ->with($cartId, $billingAddressMock); @@ -171,6 +226,27 @@ public function testSavePaymentInformationAndPlaceOrderWithLocolizedException() $billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf(); + $adapterMockForSales = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $adapterMockForCheckout = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->resourceConnectionMock->expects($this->at(0)) + ->method('getConnection') + ->with('sales') + ->willReturn($adapterMockForSales); + $adapterMockForSales->expects($this->once())->method('beginTransaction'); + $adapterMockForSales->expects($this->once())->method('rollback'); + + $this->resourceConnectionMock->expects($this->at(1)) + ->method('getConnection') + ->with('checkout') + ->willReturn($adapterMockForCheckout); + $adapterMockForCheckout->expects($this->once())->method('beginTransaction'); + $adapterMockForCheckout->expects($this->once())->method('rollback'); + $this->billingAddressManagementMock->expects($this->once()) ->method('assign') ->with($cartId, $billingAddressMock); diff --git a/app/code/Magento/Checkout/composer.json b/app/code/Magento/Checkout/composer.json index 7dc6a9ae0ffb4..ac128bed1d2f8 100644 --- a/app/code/Magento/Checkout/composer.json +++ b/app/code/Magento/Checkout/composer.json @@ -4,30 +4,30 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-sales": "100.2.*", + "magento/module-sales": "101.0.*", "magento/module-backend": "100.2.*", "magento/module-catalog-inventory": "100.2.*", - "magento/module-config": "100.2.*", - "magento/module-customer": "100.2.*", - "magento/module-catalog": "101.1.*", + "magento/module-config": "101.0.*", + "magento/module-customer": "101.0.*", + "magento/module-catalog": "102.0.*", "magento/module-payment": "100.2.*", "magento/module-shipping": "100.2.*", "magento/module-tax": "100.2.*", "magento/module-directory": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-page-cache": "100.2.*", - "magento/module-sales-rule": "100.2.*", + "magento/module-sales-rule": "101.0.*", "magento/module-theme": "100.2.*", "magento/module-msrp": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-ui": "100.2.*", - "magento/module-quote": "100.2.*" + "magento/framework": "101.0.*", + "magento/module-ui": "101.0.*", + "magento/module-quote": "101.0.*" }, "suggest": { "magento/module-cookie": "100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.3", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Checkout/i18n/en_US.csv b/app/code/Magento/Checkout/i18n/en_US.csv index 8f84275b5488d..8d297c4060abd 100644 --- a/app/code/Magento/Checkout/i18n/en_US.csv +++ b/app/code/Magento/Checkout/i18n/en_US.csv @@ -62,7 +62,7 @@ Checkout,Checkout Error!,Error! "DB exception","DB exception" Message,Message -"Print receipt","Print receipt" +"Print receipt","Print receipt" "Apply Discount Code","Apply Discount Code" "Enter discount code","Enter discount code" "Apply Discount","Apply Discount" @@ -176,3 +176,4 @@ Payment,Payment "Not yet calculated","Not yet calculated" "We received your order!","We received your order!" "Thank you for your purchase!","Thank you for your purchase!" +"optional", "optional" diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml index 3e931611b9189..692089333715a 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml @@ -9,13 +9,13 @@ - + - + diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_review_item_renderers.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_review_item_renderers.xml index 866aec9aa33ef..a70a25a748f41 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_review_item_renderers.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_review_item_renderers.xml @@ -9,7 +9,7 @@ - + diff --git a/app/code/Magento/Checkout/view/frontend/templates/button.phtml b/app/code/Magento/Checkout/view/frontend/templates/button.phtml index e2bcd76cba35b..c3edfe30f8bdd 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/button.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/button.phtml @@ -10,6 +10,8 @@ getCanViewOrder() && $block->getCanPrintOrder()) :?> - Print receipt', $block->getPrintUrl()) ?> + + + getChildHtml() ?> diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/coupon.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/coupon.phtml index b224c96f07e9b..1d67b325e01c5 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/coupon.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/coupon.phtml @@ -24,7 +24,7 @@
      - + getCouponCode())): ?> disabled="disabled" />
      diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml index b41d548e95b99..c1db2f7775ca8 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml @@ -23,7 +23,7 @@ value="" title="" class="input-text qty" - data-validate="{'required-number':true,digits:true}"/> + data-validate="escapeHtml(json_encode($block->getQuantityValidators())) ?>"/>
      diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml index 02c969f849074..0567c61f0db60 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/item/default.phtml @@ -90,7 +90,7 @@ $canApplyMsrp = $helper->isShowBeforeOrderConfirm($product) && $helper->isMinima

      -
      +
      ,

      diff --git a/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html b/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html index db2ff7df0e0b1..bdb3a9e8454fd 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html @@ -24,10 +24,10 @@ checked: $parents[1].selectedShippingMethod, attr: { value: carrier_code + '_' + method_code, - id: 's_method_' + method_code + id: 's_method_' + carrier_code + '_' + method_code } "/> -
      @@ -61,7 +61,7 @@ ); ?>

      + href="https://marketplace.magento.com/"> diff --git a/app/code/Magento/Marketplace/view/adminhtml/web/partners/images/magento-connect.png b/app/code/Magento/Marketplace/view/adminhtml/web/partners/images/magento-connect.png deleted file mode 100644 index 575563f341b35..0000000000000 Binary files a/app/code/Magento/Marketplace/view/adminhtml/web/partners/images/magento-connect.png and /dev/null differ diff --git a/app/code/Magento/Marketplace/view/adminhtml/web/partners/images/magento-marketplace.svg b/app/code/Magento/Marketplace/view/adminhtml/web/partners/images/magento-marketplace.svg new file mode 100644 index 0000000000000..388544d5d7f3d --- /dev/null +++ b/app/code/Magento/Marketplace/view/adminhtml/web/partners/images/magento-marketplace.svg @@ -0,0 +1 @@ +Artboard 1 \ No newline at end of file diff --git a/app/code/Magento/MediaStorage/composer.json b/app/code/Magento/MediaStorage/composer.json index 80e154ebc8ef1..34b47d65c7f0c 100644 --- a/app/code/Magento/MediaStorage/composer.json +++ b/app/code/Magento/MediaStorage/composer.json @@ -5,11 +5,11 @@ "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", "magento/module-backend": "100.2.*", - "magento/module-config": "100.2.*", - "magento/framework": "100.2.*" + "magento/module-config": "101.0.*", + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Msrp/composer.json b/app/code/Magento/Msrp/composer.json index 587bbe88b4101..ad03bc767a449 100644 --- a/app/code/Magento/Msrp/composer.json +++ b/app/code/Magento/Msrp/composer.json @@ -4,19 +4,19 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-catalog": "101.1.*", + "magento/module-catalog": "102.0.*", "magento/module-downloadable": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-grouped-product": "100.2.*", "magento/module-tax": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "suggest": { "magento/module-bundle": "100.2.*", "magento/module-msrp-sample-data": "Sample Data version:100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Multishipping/Block/Checkout/Overview.php b/app/code/Magento/Multishipping/Block/Checkout/Overview.php index c62226dc8d063..2197598489358 100644 --- a/app/code/Magento/Multishipping/Block/Checkout/Overview.php +++ b/app/code/Magento/Multishipping/Block/Checkout/Overview.php @@ -120,11 +120,7 @@ public function getPaymentHtml() */ public function getPayment() { - if (!$this->hasData('payment')) { - $payment = new \Magento\Framework\DataObject($this->getRequest()->getPost('payment')); - $this->setData('payment', $payment); - } - return $this->_getData('payment'); + return $this->getCheckout()->getQuote()->getPayment(); } /** @@ -200,9 +196,9 @@ public function formatPrice($price) /** * @param Address $address - * @return mixed + * @return array */ - public function getShippingAddressItems($address) + public function getShippingAddressItems($address): array { return $address->getAllVisibleItems(); } @@ -309,16 +305,7 @@ public function getVirtualProductEditUrl() */ public function getVirtualItems() { - $items = []; - foreach ($this->getBillingAddress()->getItemsCollection() as $_item) { - if ($_item->isDeleted()) { - continue; - } - if ($_item->getProduct()->getIsVirtual() && !$_item->getParentItemId()) { - $items[] = $_item; - } - } - return $items; + return $this->getBillingAddress()->getAllVisibleItems(); } /** diff --git a/app/code/Magento/Multishipping/Block/Checkout/Results.php b/app/code/Magento/Multishipping/Block/Checkout/Results.php new file mode 100644 index 0000000000000..2331092be641d --- /dev/null +++ b/app/code/Magento/Multishipping/Block/Checkout/Results.php @@ -0,0 +1,190 @@ +multishipping = $multishipping; + $this->addressConfig = $addressConfig; + $this->orderRepository = $orderRepository; + $this->session = $session; + } + + /** + * Returns shipping addresses from quote. + * + * @return array + */ + public function getQuoteShippingAddresses(): array + { + return $this->multishipping->getQuote()->getAllShippingAddresses(); + } + + /** + * Returns all failed addresses from quote. + * + * @return array + */ + public function getFailedAddresses(): array + { + $addresses = $this->getQuoteShippingAddresses(); + if ($this->getAddressError($this->getQuoteBillingAddress())) { + $addresses[] = $this->getQuoteBillingAddress(); + } + return $addresses; + } + + /** + * Retrieve order shipping address. + * + * @param int $orderId + * @return OrderAddress|null + */ + public function getOrderShippingAddress(int $orderId) + { + return $this->orderRepository->get($orderId)->getShippingAddress(); + } + + /** + * Retrieve quote billing address. + * + * @return QuoteAddress + */ + public function getQuoteBillingAddress(): QuoteAddress + { + return $this->getCheckout()->getQuote()->getBillingAddress(); + } + + /** + * Returns formatted shipping address from placed order. + * + * @param OrderAddress $address + * @return string + */ + public function formatOrderShippingAddress(OrderAddress $address): string + { + return $this->getAddressOneline($address->getData()); + } + + /** + * Returns formatted shipping address from quote. + * + * @param QuoteAddress $address + * @return string + */ + public function formatQuoteShippingAddress(QuoteAddress $address): string + { + return $this->getAddressOneline($address->getData()); + } + + /** + * Checks if address type is shipping. + * + * @param QuoteAddress $address + * @return bool + */ + public function isShippingAddress(QuoteAddress $address): bool + { + return $address->getAddressType() === QuoteAddress::ADDRESS_TYPE_SHIPPING; + } + + /** + * Get unescaped address formatted as one line string. + * + * @param array $address + * @return string + */ + private function getAddressOneline(array $address): string + { + $renderer = $this->addressConfig->getFormatByCode('oneline')->getRenderer(); + + return $renderer->renderArray($address); + } + + /** + * Returns address error. + * + * @param QuoteAddress $address + * @return string + */ + public function getAddressError(QuoteAddress $address): string + { + $errors = $this->session->getAddressErrors(); + + return $errors[$address->getId()] ?? ''; + } + + /** + * Add title to block head. + * + * @throws LocalizedException + * @return Success + */ + protected function _prepareLayout(): Success + { + /** @var Title $pageTitle */ + $pageTitle = $this->getLayout()->getBlock('page.main.title'); + if ($pageTitle) { + $title = $this->getOrderIds() ? $pageTitle->getPartlySuccessTitle() : $pageTitle->getFailedTitle(); + $pageTitle->setPageTitle($title); + } + + return parent::_prepareLayout(); + } +} diff --git a/app/code/Magento/Multishipping/Block/Checkout/Success.php b/app/code/Magento/Multishipping/Block/Checkout/Success.php index 3f18132d04a45..0f39e03c56c63 100644 --- a/app/code/Magento/Multishipping/Block/Checkout/Success.php +++ b/app/code/Magento/Multishipping/Block/Checkout/Success.php @@ -36,7 +36,7 @@ public function __construct( */ public function getOrderIds() { - $ids = $this->_session->getOrderIds(true); + $ids = $this->_session->getOrderIds(); if ($ids && is_array($ids)) { return $ids; } diff --git a/app/code/Magento/Multishipping/Block/DataProviders/Billing.php b/app/code/Magento/Multishipping/Block/DataProviders/Billing.php new file mode 100644 index 0000000000000..b2514598fd4a9 --- /dev/null +++ b/app/code/Magento/Multishipping/Block/DataProviders/Billing.php @@ -0,0 +1,74 @@ +addressConfig = $addressConfig; + $this->configProvider = $configProvider; + $this->serializer = $serializer; + } + + /** + * Get address formatted as html string. + * + * @param Address $address + * @return string + */ + public function getAddressHtml(Address $address): string + { + $renderer = $this->addressConfig->getFormatByCode('html')->getRenderer(); + + return $renderer->renderArray($address->getData()); + } + + /** + * Returns serialized checkout config. + * + * @return string + * @throws \InvalidArgumentException + */ + public function getSerializedCheckoutConfigs(): string + { + return $this->serializer->serialize($this->configProvider->getConfig()); + } +} diff --git a/app/code/Magento/Multishipping/Block/DataProviders/Overview.php b/app/code/Magento/Multishipping/Block/DataProviders/Overview.php new file mode 100644 index 0000000000000..dff64b97dcd7a --- /dev/null +++ b/app/code/Magento/Multishipping/Block/DataProviders/Overview.php @@ -0,0 +1,74 @@ +session = $session; + } + + /** + * Returns address error. + * + * @param Address $address + * @return string + */ + public function getAddressError(Address $address): string + { + $addressErrors = $this->getAddressErrors(); + + return $addressErrors[$address->getId()] ?? ''; + } + + /** + * Returns all stored errors. + * + * @return array + */ + public function getAddressErrors(): array + { + if (empty($this->addressErrors)) { + $this->addressErrors = $this->session->getAddressErrors(true); + } + + return $this->addressErrors ?? []; + } + + /** + * Creates anchor name for address Id. + * + * @param int $addressId + * @return string + */ + public function getAddressAnchorName(int $addressId): string + { + return 'a' . $addressId; + } +} diff --git a/app/code/Magento/Multishipping/Block/DataProviders/Success.php b/app/code/Magento/Multishipping/Block/DataProviders/Success.php new file mode 100644 index 0000000000000..254a7e0fc50a9 --- /dev/null +++ b/app/code/Magento/Multishipping/Block/DataProviders/Success.php @@ -0,0 +1,18 @@ +getRequest()->getPost('payment', []); - $payment['checks'] = [ - \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, - \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, - \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, - \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL, - ]; - $this->_getCheckout()->setPaymentMethod($payment); - + if (!empty($payment)) { + $payment['checks'] = [ + AbstractMethod::CHECK_USE_FOR_COUNTRY, + AbstractMethod::CHECK_USE_FOR_CURRENCY, + AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, + AbstractMethod::CHECK_ZERO_TOTAL, + ]; + $this->_getCheckout()->setPaymentMethod($payment); + } $this->_getState()->setCompleteStep(State::STEP_BILLING); $this->_view->loadLayout(); $this->_view->renderLayout(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $this->_redirect('*/*/billing'); } catch (\Exception $e) { - $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); + $this->_objectManager->get(LoggerInterface::class)->critical($e); $this->messageManager->addException($e, __('We cannot open the overview page.')); $this->_redirect('*/*/billing'); } diff --git a/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php b/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php index d23f8863d0728..f05a7f43b8118 100644 --- a/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php +++ b/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php @@ -9,6 +9,7 @@ use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\Exception\PaymentException; +use Magento\Framework\Session\SessionManagerInterface; /** * Class OverviewPost @@ -32,6 +33,11 @@ class OverviewPost extends \Magento\Multishipping\Controller\Checkout */ protected $agreementsValidator; + /** + * @var SessionManagerInterface + */ + private $session; + /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession @@ -40,6 +46,7 @@ class OverviewPost extends \Magento\Multishipping\Controller\Checkout * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementValidator + * @param SessionManagerInterface $session */ public function __construct( \Magento\Framework\App\Action\Context $context, @@ -48,11 +55,14 @@ public function __construct( AccountManagementInterface $accountManagement, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Psr\Log\LoggerInterface $logger, - \Magento\Checkout\Api\AgreementsValidatorInterface $agreementValidator + \Magento\Checkout\Api\AgreementsValidatorInterface $agreementValidator, + SessionManagerInterface $session ) { $this->formKeyValidator = $formKeyValidator; $this->logger = $logger; $this->agreementsValidator = $agreementValidator; + $this->session = $session; + parent::__construct( $context, $customerSession, @@ -95,11 +105,17 @@ public function execute() $paymentInstance->setCcCid($payment['cc_cid']); } $this->_getCheckout()->createOrders(); - $this->_getState()->setActiveStep(State::STEP_SUCCESS); $this->_getState()->setCompleteStep(State::STEP_OVERVIEW); - $this->_getCheckout()->getCheckoutSession()->clearQuote(); - $this->_getCheckout()->getCheckoutSession()->setDisplaySuccess(true); - $this->_redirect('*/*/success'); + + if ($this->session->getAddressErrors()) { + $this->_getState()->setActiveStep(State::STEP_RESULTS); + $this->_redirect('*/*/results'); + } else { + $this->_getState()->setActiveStep(State::STEP_SUCCESS); + $this->_getCheckout()->getCheckoutSession()->clearQuote(); + $this->_getCheckout()->getCheckoutSession()->setDisplaySuccess(true); + $this->_redirect('*/*/success'); + } } catch (PaymentException $e) { $message = $e->getMessage(); if (!empty($message)) { diff --git a/app/code/Magento/Multishipping/Controller/Checkout/Results.php b/app/code/Magento/Multishipping/Controller/Checkout/Results.php new file mode 100644 index 0000000000000..863dac840803c --- /dev/null +++ b/app/code/Magento/Multishipping/Controller/Checkout/Results.php @@ -0,0 +1,14 @@ +state = $state; + $this->multishipping = $multishipping; + + parent::__construct($context); + } + /** * Multishipping checkout success page * @@ -17,13 +49,13 @@ class Success extends \Magento\Multishipping\Controller\Checkout */ public function execute() { - if (!$this->_getState()->getCompleteStep(State::STEP_OVERVIEW)) { + if (!$this->state->getCompleteStep(State::STEP_OVERVIEW)) { $this->_redirect('*/*/addresses'); return; } $this->_view->loadLayout(); - $ids = $this->_getCheckout()->getOrderIds(); + $ids = $this->multishipping->getOrderIds(); $this->_eventManager->dispatch('multishipping_checkout_controller_success_action', ['order_ids' => $ids]); $this->_view->renderLayout(); } diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php index f9d6d0adaae93..c510ccffd3611 100644 --- a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php @@ -6,11 +6,14 @@ namespace Magento\Multishipping\Model\Checkout\Type; use Magento\Customer\Api\AddressRepositoryInterface; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\App\ObjectManager; use Magento\Directory\Model\AllowedCountries; +use Psr\Log\LoggerInterface; /** * Multishipping checkout model @@ -157,6 +160,16 @@ class Multishipping extends \Magento\Framework\DataObject */ private $shippingAssignmentProcessor; + /** + * @var Multishipping\PlaceOrderFactory + */ + private $placeOrderFactory; + + /** + * @var LoggerInterface + */ + private $logger; + /** * Constructor * @@ -184,6 +197,8 @@ class Multishipping extends \Magento\Framework\DataObject * @param array $data * @param \Magento\Quote\Api\Data\CartExtensionFactory|null $cartExtensionFactory * @param AllowedCountries|null $allowedCountryReader + * @param Multishipping\PlaceOrderFactory $placeOrderFactory + * @param LoggerInterface $logger * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -210,7 +225,9 @@ public function __construct( \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, array $data = [], \Magento\Quote\Api\Data\CartExtensionFactory $cartExtensionFactory = null, - AllowedCountries $allowedCountryReader = null + AllowedCountries $allowedCountryReader = null, + Multishipping\PlaceOrderFactory $placeOrderFactory = null, + LoggerInterface $logger = null ) { $this->_eventManager = $eventManager; $this->_scopeConfig = $scopeConfig; @@ -237,6 +254,10 @@ public function __construct( ->get(\Magento\Quote\Api\Data\CartExtensionFactory::class); $this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance() ->get(AllowedCountries::class); + $this->placeOrderFactory = $placeOrderFactory ?: ObjectManager::getInstance() + ->get(Multishipping\PlaceOrderFactory::class); + $this->logger = $logger ?: ObjectManager::getInstance() + ->get(LoggerInterface::class); parent::__construct($data); $this->_init(); } @@ -760,21 +781,48 @@ public function createOrders() ); } + $paymentProviderCode = $this->getQuote()->getPayment()->getMethod(); + $placeOrderService = $this->placeOrderFactory->create($paymentProviderCode); + $exceptionList = $placeOrderService->place($orders); + $this->logExceptions($exceptionList); + + /** @var OrderInterface[] $failedOrders */ + $failedOrders = []; + /** @var OrderInterface[] $successfulOrders */ + $successfulOrders = []; foreach ($orders as $order) { - $order->place(); - $order->save(); + if (isset($exceptionList[$order->getIncrementId()])) { + $failedOrders[] = $order; + } else { + $successfulOrders[] = $order; + } + } + + $placedAddressItems = []; + foreach ($successfulOrders as $order) { + $orderIds[$order->getId()] = $order->getIncrementId(); if ($order->getCanSendNewEmailFlag()) { $this->orderSender->send($order); } - $orderIds[$order->getId()] = $order->getIncrementId(); + $placedAddressItems = array_merge($placedAddressItems, $this->getQuoteAddressItems($order)); } - $this->_session->setOrderIds($orderIds); - $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId()); - - $this->getQuote()->setIsActive(false); - $this->quoteRepository->save($this->getQuote()); + $addressErrors = []; + if (!empty($failedOrders)) { + $this->removePlacedItemsFromQuote($shippingAddresses, $placedAddressItems); + $addressErrors = $this->getQuoteAddressErrors( + $failedOrders, + $shippingAddresses, + $exceptionList + ); + } else { + $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId()); + $this->getQuote()->setIsActive(false); + $this->quoteRepository->save($this->getQuote()); + } + $this->_session->setOrderIds($orderIds); + $this->_session->setAddressErrors($addressErrors); $this->_eventManager->dispatch( 'checkout_submit_all_after', ['orders' => $orders, 'quote' => $this->getQuote()] @@ -787,6 +835,19 @@ public function createOrders() } } + /** + * Logs exceptions. + * + * @param \Exception[] $exceptionList + * @return void + */ + private function logExceptions(array $exceptionList) + { + foreach ($exceptionList as $exception) { + $this->logger->critical($exception); + } + } + /** * Collect quote totals and save quote object * @@ -817,13 +878,21 @@ public function reset() */ public function validateMinimumAmount() { - return !($this->_scopeConfig->isSetFlag( + $minimumOrderActive = $this->_scopeConfig->isSetFlag( 'sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) && $this->_scopeConfig->isSetFlag( + ); + + if ($this->_scopeConfig->isSetFlag( 'sales/minimum_order/multi_address', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) && !$this->getQuote()->validateMinimumAmount()); + \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ) { + $result = !($minimumOrderActive && !$this->getQuote()->validateMinimumAmount()); + } else { + $result = !($minimumOrderActive && !$this->validateMinimumAmountForAddressItems()); + } + + return $result; } /** @@ -873,7 +942,10 @@ public function getMinimumAmountError() public function getOrderIds($asAssoc = false) { $idsAssoc = $this->_session->getOrderIds(); - return $asAssoc ? $idsAssoc : array_keys($idsAssoc); + if ($idsAssoc !== null) { + return $asAssoc ? $idsAssoc : array_keys($idsAssoc); + } + return []; } /** @@ -1031,4 +1103,149 @@ private function getShippingAssignmentProcessor() } return $this->shippingAssignmentProcessor; } + + /** + * Validate minimum amount for "Checkout with Multiple Addresses" when + * "Validate Each Address Separately in Multi-address Checkout" is No. + * + * @return bool + */ + private function validateMinimumAmountForAddressItems() + { + $result = true; + $storeId = $this->getQuote()->getStoreId(); + + $minAmount = $this->_scopeConfig->getValue( + 'sales/minimum_order/amount', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $storeId + ); + $taxInclude = $this->_scopeConfig->getValue( + 'sales/minimum_order/tax_including', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $storeId + ); + + $addresses = $this->getQuote()->getAllAddresses(); + + $baseTotal = 0; + foreach ($addresses as $address) { + $taxes = $taxInclude ? $address->getBaseTaxAmount() : 0; + $baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes; + } + + if ($baseTotal < $minAmount) { + $result = false; + } + + return $result; + } + + /** + * Remove successfully placed items from quote. + * + * @param \Magento\Quote\Model\Quote\Address[] $shippingAddresses + * @param int[] $placedAddressItems + * @return void + */ + private function removePlacedItemsFromQuote(array $shippingAddresses, array $placedAddressItems) + { + foreach ($shippingAddresses as $address) { + foreach ($address->getAllItems() as $addressItem) { + if (in_array($addressItem->getId(), $placedAddressItems)) { + if ($addressItem->getProduct()->getIsVirtual()) { + $addressItem->isDeleted(true); + } else { + $address->isDeleted(true); + } + + $this->decreaseQuoteItemQty($addressItem->getQuoteItemId(), $addressItem->getQty()); + } + } + } + $this->save(); + } + + /** + * Decrease quote item quantity. + * + * @param int $quoteItemId + * @param int $qty + * @return void + */ + private function decreaseQuoteItemQty(int $quoteItemId, int $qty) + { + $quoteItem = $this->getQuote()->getItemById($quoteItemId); + if ($quoteItem) { + $newItemQty = $quoteItem->getQty() - $qty; + if ($newItemQty > 0) { + $quoteItem->setQty($newItemQty); + } else { + $this->getQuote()->removeItem($quoteItem->getId()); + $this->getQuote()->setIsMultiShipping(1); + } + } + } + + /** + * Returns quote address id that was assigned to order. + * + * @param OrderInterface $order + * @param \Magento\Quote\Model\Quote\Address[] $addresses + * + * @return int + * @throws NotFoundException + */ + private function searchQuoteAddressId(OrderInterface $order, array $addresses): int + { + $items = $order->getItems(); + $item = array_pop($items); + foreach ($addresses as $address) { + foreach ($address->getAllItems() as $addressItem) { + if ($addressItem->getId() == $item->getQuoteItemId()) { + return (int)$address->getId(); + } + } + } + + throw new NotFoundException(__('Quote address for failed order not found.')); + } + + /** + * @param OrderInterface[] $orders + * @param \Magento\Quote\Model\Quote\Address[] $addresses + * @param \Exception[] $exceptionList + * + * @return string[] + * @throws NotFoundException + */ + private function getQuoteAddressErrors(array $orders, array $addresses, array $exceptionList): array + { + $addressErrors = []; + foreach ($orders as $failedOrder) { + if (!isset($exceptionList[$failedOrder->getIncrementId()])) { + throw new NotFoundException(__('Exception for failed order not found.')); + } + $addressId = $this->searchQuoteAddressId($failedOrder, $addresses); + $addressErrors[$addressId] = $exceptionList[$failedOrder->getIncrementId()]->getMessage(); + } + + return $addressErrors; + } + + /** + * Returns quote address item id. + * + * @param OrderInterface $order + * @return array + */ + private function getQuoteAddressItems(OrderInterface $order): array + { + $placedAddressItems = []; + foreach ($order->getItems() as $orderItem) { + $placedAddressItems[] = $orderItem->getQuoteItemId(); + } + + return $placedAddressItems; + } } diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderDefault.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderDefault.php new file mode 100644 index 0000000000000..03904102341a3 --- /dev/null +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderDefault.php @@ -0,0 +1,46 @@ +orderManagement = $orderManagement; + } + + /** + * {@inheritdoc} + */ + public function place(array $orderList): array + { + $errorList = []; + foreach ($orderList as $order) { + try { + $this->orderManagement->place($order); + } catch (\Exception $e) { + $incrementId = $order->getIncrementId(); + $errorList[$incrementId] = $e; + } + } + + return $errorList; + } +} diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderFactory.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderFactory.php new file mode 100644 index 0000000000000..00ab729a4a9ef --- /dev/null +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderFactory.php @@ -0,0 +1,50 @@ +objectManager = $objectManager; + $this->placeOrderPool = $placeOrderPool; + } + + /** + * @param string $paymentProviderCode + * @return PlaceOrderInterface + */ + public function create(string $paymentProviderCode): PlaceOrderInterface + { + $service = $this->placeOrderPool->get($paymentProviderCode); + if ($service === null) { + $service = $this->objectManager->get(PlaceOrderDefault::class); + } + + return $service; + } +} diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderInterface.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderInterface.php new file mode 100644 index 0000000000000..70b4c6f99278a --- /dev/null +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/PlaceOrderInterface.php @@ -0,0 +1,22 @@ +services = $tmapFactory->createSharedObjectsMap( + [ + 'array' => $services, + 'type' => PlaceOrderInterface::class + ] + ); + } + + /** + * Returns place order service for defined payment provider. + * + * @param string $paymentProviderCode + * @return PlaceOrderInterface|null + */ + public function get(string $paymentProviderCode) + { + if (!isset($this->services[$paymentProviderCode])) { + return null; + } + + return $this->services[$paymentProviderCode]; + } +} diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/State.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/State.php index 2615ad1b540c8..2e53817351d3c 100644 --- a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/State.php +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping/State.php @@ -25,6 +25,8 @@ class State extends \Magento\Framework\DataObject const STEP_SUCCESS = 'multishipping_success'; + const STEP_RESULTS = 'multishipping_results'; + /** * Allow steps array * @@ -61,6 +63,7 @@ public function __construct(Session $checkoutSession, Multishipping $multishippi self::STEP_BILLING => new \Magento\Framework\DataObject(['label' => __('Billing Information')]), self::STEP_OVERVIEW => new \Magento\Framework\DataObject(['label' => __('Place Order')]), self::STEP_SUCCESS => new \Magento\Framework\DataObject(['label' => __('Order Success')]), + self::STEP_RESULTS => new \Magento\Framework\DataObject(['label' => __('Order Results')]), ]; foreach ($this->_steps as $step) { diff --git a/app/code/Magento/Multishipping/Test/Unit/Block/Checkout/SuccessTest.php b/app/code/Magento/Multishipping/Test/Unit/Block/Checkout/SuccessTest.php index 26e22487cf445..403e6cfcb48dc 100644 --- a/app/code/Magento/Multishipping/Test/Unit/Block/Checkout/SuccessTest.php +++ b/app/code/Magento/Multishipping/Test/Unit/Block/Checkout/SuccessTest.php @@ -56,14 +56,14 @@ protected function setUp() public function testGetOrderIdsWithoutId() { - $this->sessionMock->expects($this->once())->method('getOrderIds')->with(true)->will($this->returnValue(null)); + $this->sessionMock->method('getOrderIds')->willReturn(null); $this->assertFalse($this->model->getOrderIds()); } public function testGetOrderIdsWithEmptyIdsArray() { - $this->sessionMock->expects($this->once())->method('getOrderIds')->with(true)->will($this->returnValue([])); + $this->sessionMock->method('getOrderIds')->willReturn([]); $this->assertFalse($this->model->getOrderIds()); } @@ -71,7 +71,7 @@ public function testGetOrderIdsWithEmptyIdsArray() public function testGetOrderIds() { $ids = [100, 102, 103]; - $this->sessionMock->expects($this->once())->method('getOrderIds')->with(true)->will($this->returnValue($ids)); + $this->sessionMock->method('getOrderIds')->willReturn($ids);; $this->assertEquals($ids, $this->model->getOrderIds()); } diff --git a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderDefaultTest.php b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderDefaultTest.php new file mode 100644 index 0000000000000..61a88b8810f15 --- /dev/null +++ b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderDefaultTest.php @@ -0,0 +1,68 @@ +orderManagement = $this->getMockForAbstractClass(OrderManagementInterface::class); + + $this->placeOrderDefault = new PlaceOrderDefault($this->orderManagement); + } + + public function testPlace() + { + $incrementId = '000000001'; + + $order = $this->getMockForAbstractClass(OrderInterface::class); + $order->method('getIncrementId')->willReturn($incrementId); + $orderList = [$order]; + + $this->orderManagement->expects($this->once()) + ->method('place') + ->with($order) + ->willReturn($order); + $errors = $this->placeOrderDefault->place($orderList); + + $this->assertEmpty($errors); + } + + public function testPlaceWithErrors() + { + $incrementId = '000000001'; + + $order = $this->getMockForAbstractClass(OrderInterface::class); + $order->method('getIncrementId')->willReturn($incrementId); + $orderList = [$order]; + + $exception = new \Exception('error'); + $this->orderManagement->method('place')->willThrowException($exception); + $errors = $this->placeOrderDefault->place($orderList); + + $this->assertEquals( + [$incrementId => $exception], + $errors + ); + } +} diff --git a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderFactoryTest.php b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderFactoryTest.php new file mode 100644 index 0000000000000..4b92c739f55c0 --- /dev/null +++ b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderFactoryTest.php @@ -0,0 +1,80 @@ +objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); + + $this->placeOrderPool = $this->getMockBuilder(PlaceOrderPool::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->placeOrderFactory = new PlaceOrderFactory($this->objectManager, $this->placeOrderPool); + } + + public function testCreate() + { + $paymentProviderCode = 'code'; + + $placeOrder = $this->getMockForAbstractClass(PlaceOrderInterface::class); + $this->placeOrderPool->method('get') + ->with($paymentProviderCode) + ->willReturn($placeOrder); + + $instance = $this->placeOrderFactory->create($paymentProviderCode); + + $this->assertInstanceOf(PlaceOrderInterface::class, $instance); + } + + /** + * Checks that default place order service is created when place order pull returns null. + */ + public function testCreateWithDefault() + { + $paymentProviderCode = 'code'; + + $this->placeOrderPool->method('get') + ->with($paymentProviderCode) + ->willReturn(null); + $placeOrder = $this->getMockBuilder(PlaceOrderDefault::class) + ->disableOriginalConstructor() + ->getMock(); + $this->objectManager->method('get') + ->with(PlaceOrderDefault::class) + ->willReturn($placeOrder); + + $instance = $this->placeOrderFactory->create($paymentProviderCode); + + $this->assertInstanceOf(PlaceOrderDefault::class, $instance); + } +} diff --git a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderPoolTest.php b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderPoolTest.php new file mode 100644 index 0000000000000..9289f5afd1aad --- /dev/null +++ b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderPoolTest.php @@ -0,0 +1,48 @@ +getMockBuilder(TMapFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $tMapFactory->method('createSharedObjectsMap')->willReturn($placeOrderList); + + $placeOrderPool = new PlaceOrderPool($tMapFactory); + $result = $placeOrderPool->get($paymentProviderCode); + + $this->assertEquals($expectedResult, $result); + } + + /** + * @return array + */ + public function getDataProvider(): array + { + $placeOrder = $this->getMockForAbstractClass(PlaceOrderInterface::class); + $placeOrderList = ['payment_code' => $placeOrder]; + + return [ + 'code exists in pool' => ['payment_code', $placeOrderList, $placeOrder], + 'no code in pool' => ['some_code', $placeOrderList, null], + ]; + } +} diff --git a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php index 1d779c11d5935..f90e85a904352 100644 --- a/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php +++ b/app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php @@ -118,13 +118,18 @@ class MultishippingTest extends \PHPUnit\Framework\TestCase */ private $quoteRepositoryMock; + /** + * @var PHPUnit_Framework_MockObject_MockObject + */ + private $scopeConfigMock; + protected function setUp() { $this->checkoutSessionMock = $this->createSimpleMock(Session::class); $this->customerSessionMock = $this->createSimpleMock(CustomerSession::class); $orderFactoryMock = $this->createSimpleMock(OrderFactory::class); $eventManagerMock = $this->createSimpleMock(ManagerInterface::class); - $scopeConfigMock = $this->createSimpleMock(ScopeConfigInterface::class); + $this->scopeConfigMock = $this->createSimpleMock(ScopeConfigInterface::class); $sessionMock = $this->createSimpleMock(Generic::class); $addressFactoryMock = $this->createSimpleMock(AddressFactory::class); $toOrderMock = $this->createSimpleMock(ToOrder::class); @@ -166,7 +171,7 @@ protected function setUp() $orderFactoryMock, $this->addressRepositoryMock, $eventManagerMock, - $scopeConfigMock, + $this->scopeConfigMock, $sessionMock, $addressFactoryMock, $toOrderMock, @@ -497,4 +502,37 @@ private function createSimpleMock($className) ->disableOriginalConstructor() ->getMock(); } + + public function testValidateMinimumAmountMultiAddressTrue() + { + $this->scopeConfigMock->expects($this->exactly(2))->method('isSetFlag')->withConsecutive( + ['sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE], + ['sales/minimum_order/multi_address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE] + )->willReturnOnConsecutiveCalls(true, true); + + $this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock); + $this->quoteMock->expects($this->once())->method('validateMinimumAmount')->willReturn(false); + $this->assertFalse($this->model->validateMinimumAmount()); + } + + public function testValidateMinimumAmountMultiAddressFalse() + { + $addressMock = $this->createMock(\Magento\Quote\Model\Quote\Address::class); + $this->scopeConfigMock->expects($this->exactly(2))->method('isSetFlag')->withConsecutive( + ['sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE], + ['sales/minimum_order/multi_address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE] + )->willReturnOnConsecutiveCalls(true, false); + + $this->scopeConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive( + ['sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE], + ['sales/minimum_order/tax_including', \Magento\Store\Model\ScopeInterface::SCOPE_STORE] + )->willReturnOnConsecutiveCalls(100, false); + + $this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock); + $this->quoteMock->expects($this->once())->method('getStoreId')->willReturn(1); + $this->quoteMock->expects($this->once())->method('getAllAddresses')->willReturn([$addressMock]); + $addressMock->expects($this->once())->method('getBaseSubtotalWithDiscount')->willReturn(101); + + $this->assertTrue($this->model->validateMinimumAmount()); + } } diff --git a/app/code/Magento/Multishipping/composer.json b/app/code/Magento/Multishipping/composer.json index 456248065e949..2e7e5160a55bf 100644 --- a/app/code/Magento/Multishipping/composer.json +++ b/app/code/Magento/Multishipping/composer.json @@ -3,21 +3,19 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/framework": "101.0.*", "magento/module-store": "100.2.*", "magento/module-checkout": "100.2.*", - "magento/module-sales": "100.2.*", + "magento/module-sales": "101.0.*", "magento/module-payment": "100.2.*", "magento/module-tax": "100.2.*", - "magento/module-customer": "100.2.*", - "magento/module-quote": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-directory": "100.2.*" - }, - "suggest": { + "magento/module-customer": "101.0.*", + "magento/module-quote": "101.0.*", + "magento/module-directory": "100.2.*", "magento/module-theme": "100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_billing.xml b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_billing.xml index 8d78bad7a9ecc..5fcca5d9214a6 100644 --- a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_billing.xml +++ b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_billing.xml @@ -15,6 +15,9 @@ + + Magento\Multishipping\Block\DataProviders\Billing + diff --git a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_overview.xml b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_overview.xml index f6584d2dcb2fd..376bc7b7d8ca8 100644 --- a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_overview.xml +++ b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_overview.xml @@ -17,6 +17,7 @@ + Magento\Multishipping\Block\DataProviders\Overview Magento_Multishipping::checkout/item/default.phtml Magento_Multishipping::checkout/overview/item.phtml diff --git a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_results.xml b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_results.xml new file mode 100644 index 0000000000000..90f13ea28e02f --- /dev/null +++ b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_results.xml @@ -0,0 +1,23 @@ + + + + + Order results + + + + + We could only complete part of your order. + We were unable to complete your order. + + + + + + + diff --git a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml index 98dd6e21910f8..d03282e551b9e 100644 --- a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml +++ b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml @@ -12,11 +12,15 @@ - We received your order! + Thank you for your purchase! - + + + Magento\Multishipping\Block\DataProviders\Success + + diff --git a/app/code/Magento/Multishipping/view/frontend/requirejs-config.js b/app/code/Magento/Multishipping/view/frontend/requirejs-config.js index c00005138eee4..f14159ba0a85a 100644 --- a/app/code/Magento/Multishipping/view/frontend/requirejs-config.js +++ b/app/code/Magento/Multishipping/view/frontend/requirejs-config.js @@ -8,7 +8,8 @@ var config = { '*': { multiShipping: 'Magento_Multishipping/js/multi-shipping', orderOverview: 'Magento_Multishipping/js/overview', - payment: 'Magento_Multishipping/js/payment' + payment: 'Magento_Multishipping/js/payment', + billingLoader: 'Magento_Checkout/js/checkout-loader' } } }; diff --git a/app/code/Magento/Multishipping/view/frontend/templates/checkout/billing.phtml b/app/code/Magento/Multishipping/view/frontend/templates/checkout/billing.phtml index 277328c1b5b2a..d8514ca77f9c2 100644 --- a/app/code/Magento/Multishipping/view/frontend/templates/checkout/billing.phtml +++ b/app/code/Magento/Multishipping/view/frontend/templates/checkout/billing.phtml @@ -4,52 +4,109 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - -?> - -
      +
      +
      + <?= $block->escapeHtml(__('Loading...')); ?> +
      +
      + +
      + + +
      +
      - - + escapeHtml(__('Billing Address')); ?> + + escapeHtml(__('Change')); ?> +
      - getAddress() ?> -
      format('html') ?>
      +
      + getCheckoutData()->getAddressHtml($block->getAddress()); ?> +
      -
      + + escapeHtml(__('Payment Method')); ?> +
      getChildHtml('payment_methods_before') ?> -
      +
      getMethods(); - $_methodsCount = count($_methods); + $methods = $block->getMethods(); + $methodsCount = count($methods); + $methodsForms = $block->hasFormTemplates() ? $block->getFormTemplates(): []; + + foreach ($methods as $_method) : + $code = $_method->getCode(); + $checked = $block->getSelectedMethodCode() === $code; + + if (isset($methodsForms[$code])) { + $block->setMethodFormTemplate($code, $methodsForms[$code]); + } ?> - getCode() ?> -
      - 1): ?> - getSelectedMethodCode() == $_code): ?> checked="checked" class="radio"/> - - - - -
      - getChildHtml('payment.method.' . $_code)) : ?> -
      - +
      + 1) : ?> + + checked="checked" + + class="radio"/> + + + + +
      + getChildHtml('payment.method.' . $code)) : ?> +
      +
      @@ -63,29 +120,35 @@
      - +
      diff --git a/app/code/Magento/Multishipping/view/frontend/templates/checkout/overview.phtml b/app/code/Magento/Multishipping/view/frontend/templates/checkout/overview.phtml index 2549eff3aca7d..d4d446a7567db 100644 --- a/app/code/Magento/Multishipping/view/frontend/templates/checkout/overview.phtml +++ b/app/code/Magento/Multishipping/view/frontend/templates/checkout/overview.phtml @@ -4,105 +4,146 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - /** @var \Magento\Multishipping\Block\Checkout\Overview $block */ ?> -
      - getBlockHtml('formkey') ?> +getCheckoutData()->getAddressErrors(); ?> + $error) : ?> +
      + escapeHtml($error); ?> + escapeHtml(__('Please see')); ?> + + escapeHtml(__('details below')); ?>. +
      + + + getBlockHtml('formkey'); ?>
      -
      +
      escapeHtml(__('Billing Information')); ?>
      - getBillingAddress() ?> + getBillingAddress() ?> - - + escapeHtml(__('Billing Address')); ?> + escapeHtml(__('Change')); ?>
      - format('html') ?> + format('html') ?>
      - - + escapeHtml(__('Payment Method')); ?> + escapeHtml(__('Change')); ?>
      - - - getPaymentHtml() ?> + + + getPaymentHtml() ?>
      -
      - helper('Magento\Tax\Helper\Data')->displayCartBothPrices() ? 2 : 1); ?> - getShippingAddresses() as $_index => $_address): ?> +
      escapeHtml(__('Shipping Information')); ?>
      + helper(Magento\Tax\Helper\Data::class)->displayCartBothPrices() ? 2 : 1); ?> + getShippingAddresses() as $index => $address) : ?>
      +
      - of %2', ($_index+1), $block->getShippingAddressCount()) ?> + escapeHtml(__('Address')); ?> escapeHtml($index + 1); ?> + + escapeHtml(__('of')); ?> + escapeHtml($block->getShippingAddressCount())?> + +
      + getCheckoutData()->getAddressError($address)) : ?> +
      escapeHtml($error); ?>
      +
      - - + escapeHtml(__('Shipping To')); ?> + escapeHtml(__('Change')); ?>
      - format('html') ?> + format('html') ?>
      - - + escapeHtml(__('Shipping Method')); ?> + escapeHtml(__('Change')); ?> - getShippingAddressRate($_address)): ?> + getShippingAddressRate($address)) : ?>
      - escapeHtml($_rate->getCarrierTitle()) ?> (escapeHtml($_rate->getMethodTitle()) ?>) - getShippingPriceExclTax($_address); ?> - getShippingPriceInclTax($_address); ?> - - helper('Magento\Tax\Helper\Data')->displayShippingBothPrices() && $_incl != $_excl): ?> - - - - helper('Magento\Tax\Helper\Data')->displayShippingBothPrices() && $_incl != $_excl): ?> - - - helper('Magento\Tax\Helper\Data')->displayShippingBothPrices() && $_incl != $_excl): ?> - - + escapeHtml($_rate->getCarrierTitle()) ?> + (escapeHtml($_rate->getMethodTitle()) ?>) + getShippingPriceExclTax($address); + $inclTax = $block->getShippingPriceInclTax($address); + $displayBothPrices = $this->helper(Magento\Tax\Helper\Data::class) + ->displayShippingBothPrices() && $inclTax !== $exclTax; + ?> + + + + + + + + + +
      - - +
      + - - - - + + + - getShippingAddressItems($_address) as $_item): ?> - getRowItemHtml($_item) ?> + getShippingAddressItems($address) as $item) : ?> + getRowItemHtml($item) ?> - renderTotals($block->getShippingAddressTotals($_address)) ?> + renderTotals( + $block->getShippingAddressTotals($address) + ); ?>
      escapeHtml(__('Order Review')); ?>
      - + escapeHtml(__('Item')); ?> + + escapeHtml(__('Edit')); ?> + escapeHtml(__('Price')); ?>escapeHtml(__('Qty')); ?>escapeHtml(__('Subtotal')); ?>
      @@ -112,33 +153,40 @@
      - getQuote()->hasVirtualItems()): ?> + getQuote()->hasVirtualItems()) : ?>
      -
      + getQuote()->getBillingAddress(); ?> + +
      escapeHtml(__('Other items in your order')); ?>
      + getCheckoutData()->getAddressError($billingAddress)) :?> +
      escapeHtml($error); ?>
      +
      - - + escapeHtml(__('Items')); ?> + escapeHtml(__('Edit Items')); ?> - helper('Magento\Tax\Helper\Data')->displayCartBothPrices() ? 2 : 1); ?> + helper(Magento\Tax\Helper\Data::class)->displayCartBothPrices() ? 2 : 1); ?>
      - + - - - - + + + + - getVirtualItems() as $_item): ?> - getRowItemHtml($_item) ?> + getVirtualItems() as $_item) : ?> + getRowItemHtml($_item) ?> - renderTotals($block->getBillinAddressTotals()) ?> + renderTotals($block->getBillinAddressTotals()); ?>
      escapeHtml(__('Items')); ?>
      escapeHtml(__('Product Name')); ?>escapeHtml(__('Price')); ?>escapeHtml(__('Qty')); ?>escapeHtml(__('Subtotal')); ?>
      @@ -146,23 +194,34 @@
      - getChildHtml('items_after') ?> + getChildHtml('items_after') ?>
      - getChildHtml('agreements') ?> + getChildHtml('agreements') ?>
      - - helper('Magento\Checkout\Helper\Data')->formatPrice($block->getTotal()) ?> + escapeHtml(__('Grand Total:')); ?> + + helper(Magento\Checkout\Helper\Data::class) + ->formatPrice($block->getTotal()); ?> +
      - +
      -
      diff --git a/app/code/Magento/Multishipping/view/frontend/templates/checkout/results.phtml b/app/code/Magento/Multishipping/view/frontend/templates/checkout/results.phtml new file mode 100644 index 0000000000000..d6fdef6ae5f9a --- /dev/null +++ b/app/code/Magento/Multishipping/view/frontend/templates/checkout/results.phtml @@ -0,0 +1,90 @@ +getOrderIds(); +?> +
      +

      + + escapeHtml(__('Not all items were included.')); ?> + + escapeHtml(__('For details, see')); ?> + escapeHtml(__('Failed to Order')); ?> + escapeHtml(__('section below')); ?> +

      + +

      + escapeHtml(__('For successfully ordered items, you\'ll receive a confirmation email '. + 'including order numbers, tracking information, and more details.')); ?> +

      +
      +

      escapeHtml(__('Successfully Ordered')); ?>

      +
        + $incrementId) : ?> +
      • + + getOrderShippingAddress($orderId); ?> +
        + + escapeHtml('Ship to:'); ?> + + escapeHtml($block->formatOrderShippingAddress($shippingAddress)); ?> + + + + escapeHtml(__('No shipping required.')); ?> + + +
        +
      • + +
      +
      + +
      +

      escapeHtml(__('Failed to Order')); ?>

      +
      +
      + escapeHtml(__('To purchase these items: Return to the')); ?> + + escapeHtml(__('Review page in Checkout')); ?>, + escapeHtml(__('resolve any errors, and place a new order.'))?> +
      +
      + getFailedAddresses() ?> + +
        + +
      1. +
        +
        + isShippingAddress($address)) : ?> + escapeHtml('Ship to:'); ?> + + escapeHtml($block->formatQuoteShippingAddress($address)); ?> + + + + escapeHtml(__('No shipping required.')); ?> + + +
        +
        + escapeHtml('Error:'); ?> + + getAddressError($address); ?> + +
        +
        +
      2. + +
      + +
      +
      diff --git a/app/code/Magento/Multishipping/view/frontend/templates/checkout/success.phtml b/app/code/Magento/Multishipping/view/frontend/templates/checkout/success.phtml index 3403c745e6495..c8e7c375089cd 100644 --- a/app/code/Magento/Multishipping/view/frontend/templates/checkout/success.phtml +++ b/app/code/Magento/Multishipping/view/frontend/templates/checkout/success.phtml @@ -4,27 +4,48 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - +/** @var \Magento\Multishipping\Block\Checkout\Success $block */ ?> -
      -

      escapeHtml(__('Thank you for your purchase!')) ?>

      -

      escapeHtml(__('Thanks for your order. We\'ll email you order details and tracking information.')) ?>

      - getOrderIds()): ?> -

      - - - 1): ?> - escapeHtml(__('Your order numbers are: ')) ?> - - escapeHtml(__('Your order number is: ')) ?> - - - $incrementId): ?> -

      - - getChildHtml() ?> -
      - escapeHtml(__('Continue Shopping')) ?> + +
      +

      escapeHtml(__('For successfully order items, you\'ll receive a confirmation email including '. + 'order numbers, tracking information and more details.')) ?>

      + getOrderIds()) : ?> +

      escapeHtml(__('Successfully ordered'))?>

      +
      +
        + $incrementId) : ?> +
      • + + getCheckoutData()->getOrderShippingAddress($orderId); ?> +
        + + escapeHtml('Ship to:'); ?> + + escapeHtml( + $block->getCheckoutData()->formatOrderShippingAddress($shippingAddress) + ); ?> + + + + escapeHtml(__('No shipping required.')); ?> + + +
        +
      • + +
      +
      + + getChildHtml() ?> +
      +
      + +
      +
      -
      + diff --git a/app/code/Magento/Multishipping/view/frontend/web/js/payment.js b/app/code/Magento/Multishipping/view/frontend/web/js/payment.js index 94987328bb278..da24b99597d42 100644 --- a/app/code/Magento/Multishipping/view/frontend/web/js/payment.js +++ b/app/code/Magento/Multishipping/view/frontend/web/js/payment.js @@ -63,9 +63,12 @@ define([ parentsDl = element.closest('dl'); parentsDl.find('dt input:radio').prop('checked', false); - parentsDl.find('.items').hide().find('[name^="payment["]').prop('disabled', true); + parentsDl.find('dd').addClass('no-display').end() + .find('.items').hide() + .find('[name^="payment["]').prop('disabled', true); element.prop('checked', true).parent() - .nextUntil('dt').find('.items').show().find('[name^="payment["]').prop('disabled', false); + .next('dd').removeClass('no-display') + .find('.items').show().find('[name^="payment["]').prop('disabled', false); }, /** @@ -122,16 +125,35 @@ define([ this.element.find(this.options.methodsContainer).show(); }, + /** + * Returns checked payment method. + * + * @private + */ + _getSelectedPaymentMethod: function () { + return this.element.find('input[name=\'payment[method]\']:checked'); + }, + /** * Validate before form submit * @private * @param {EventObject} e */ _submitHandler: function (e) { + var currentMethod, + submitButton; + e.preventDefault(); if (this._validatePaymentMethod()) { - this.element.submit(); + currentMethod = this._getSelectedPaymentMethod(); + submitButton = currentMethod.parent().next('dd').find('button[type=submit]'); + + if (submitButton.length) { + submitButton.first().trigger('click'); + } else { + this.element.submit(); + } } } }); diff --git a/app/code/Magento/NewRelicReporting/Console/Command/DeployMarker.php b/app/code/Magento/NewRelicReporting/Console/Command/DeployMarker.php new file mode 100644 index 0000000000000..92231dae69fbe --- /dev/null +++ b/app/code/Magento/NewRelicReporting/Console/Command/DeployMarker.php @@ -0,0 +1,81 @@ +deploymentsFactory = $deploymentsFactory; + $this->serviceShellUser = $serviceShellUser; + parent::__construct($name); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName("newrelic:create:deploy-marker"); + $this->setDescription("Check the deploy queue for entries and create an appropriate deploy marker.") + ->addArgument( + 'message', + InputArgument::REQUIRED, + 'Deploy Message?' + ) + ->addArgument( + 'changelog', + InputArgument::REQUIRED, + 'Change Log?' + ) + ->addArgument( + 'user', + InputArgument::OPTIONAL, + 'Deployment User' + ); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->deploymentsFactory->create()->setDeployment( + $input->getArgument('message'), + $input->getArgument('changelog'), + $this->serviceShellUser->get($input->getArgument('user')) + ); + $output->writeln('NewRelic deployment information sent'); + } +} diff --git a/app/code/Magento/NewRelicReporting/Model/Cron/ReportNewRelicCron.php b/app/code/Magento/NewRelicReporting/Model/Cron/ReportNewRelicCron.php index a4a7d30b44f5b..6b2bd50dc456b 100644 --- a/app/code/Magento/NewRelicReporting/Model/Cron/ReportNewRelicCron.php +++ b/app/code/Magento/NewRelicReporting/Model/Cron/ReportNewRelicCron.php @@ -175,7 +175,6 @@ protected function reportCounts() public function report() { if ($this->config->isNewRelicEnabled()) { - $this->reportModules(); $this->reportCounts(); } diff --git a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php index c4818c38cd9c6..845ed0429d2c3 100644 --- a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php +++ b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php @@ -28,6 +28,19 @@ public function addCustomParameter($param, $value) return false; } + /** + * Wrapper for 'newrelic_notice_error' function + * + * @param Exception $exception + * @return void + */ + public function reportError($exception) + { + if (extension_loaded('newrelic')) { + newrelic_notice_error($exception->getMessage(), $exception); + } + } + /** * Checks whether newrelic-php5 agent is installed * diff --git a/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdmins.php b/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdmins.php index 615c80633cb0f..9dfd0e1e3319a 100644 --- a/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdmins.php +++ b/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdmins.php @@ -66,8 +66,8 @@ public function execute(Observer $observer) $user = $this->backendAuthSession->getUser(); $jsonData = [ 'id' => $user->getId(), - 'username' => $user->getUsername(), - 'name' => $user->getFirstname() . ' ' . $user->getLastname(), + 'username' => $user->getUserName(), + 'name' => $user->getFirstName() . ' ' . $user->getLastName(), ]; $modelData = [ diff --git a/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdminsToNewRelic.php b/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdminsToNewRelic.php index cff1b159d481d..2f142f6ac8124 100644 --- a/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdminsToNewRelic.php +++ b/app/code/Magento/NewRelicReporting/Model/Observer/ReportConcurrentAdminsToNewRelic.php @@ -58,10 +58,10 @@ public function execute(Observer $observer) if ($this->backendAuthSession->isLoggedIn()) { $user = $this->backendAuthSession->getUser(); $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER_ID, $user->getId()); - $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER, $user->getUsername()); + $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER, $user->getUserName()); $this->newRelicWrapper->addCustomParameter( Config::ADMIN_NAME, - $user->getFirstname() . ' ' . $user->getLastname() + $user->getFirstName() . ' ' . $user->getLastName() ); } } diff --git a/app/code/Magento/NewRelicReporting/Model/Observer/ReportSystemCacheFlushToNewRelic.php b/app/code/Magento/NewRelicReporting/Model/Observer/ReportSystemCacheFlushToNewRelic.php index 0e3ad1605f948..5500aba195936 100644 --- a/app/code/Magento/NewRelicReporting/Model/Observer/ReportSystemCacheFlushToNewRelic.php +++ b/app/code/Magento/NewRelicReporting/Model/Observer/ReportSystemCacheFlushToNewRelic.php @@ -58,8 +58,8 @@ public function execute(Observer $observer) if ($user->getId()) { $this->deploymentsFactory->create()->setDeployment( 'Cache Flush', - $user->getUsername() . ' flushed the cache.', - $user->getUsername() + $user->getUserName() . ' flushed the cache.', + $user->getUserName() ); } } diff --git a/app/code/Magento/NewRelicReporting/Model/ServiceShellUser.php b/app/code/Magento/NewRelicReporting/Model/ServiceShellUser.php new file mode 100644 index 0000000000000..c038be4fb2a76 --- /dev/null +++ b/app/code/Magento/NewRelicReporting/Model/ServiceShellUser.php @@ -0,0 +1,34 @@ +config = $config; + $this->newRelicWrapper = $newRelicWrapper; + } + + /** + * Report exception to New Relic + * + * @param Http $subject + * @param Bootstrap $bootstrap + * @param \Exception $exception + * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function beforeCatchException(Http $subject, Bootstrap $bootstrap, \Exception $exception) + { + if ($this->config->isNewRelicEnabled()) { + $this->newRelicWrapper->reportError($exception); + } + } +} diff --git a/app/code/Magento/NewRelicReporting/Test/Unit/Model/Cron/ReportNewRelicCronTest.php b/app/code/Magento/NewRelicReporting/Test/Unit/Model/Cron/ReportNewRelicCronTest.php index 70fdcd0b6191c..400bcefa9828b 100644 --- a/app/code/Magento/NewRelicReporting/Test/Unit/Model/Cron/ReportNewRelicCronTest.php +++ b/app/code/Magento/NewRelicReporting/Test/Unit/Model/Cron/ReportNewRelicCronTest.php @@ -144,24 +144,10 @@ public function testReportNewRelicCronModuleDisabledFromConfig() */ public function testReportNewRelicCron() { - $testModuleData = [ - 'changes' => [ - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'], - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'], - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'], - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'], - ], - 'enabled' => 1, - 'disabled' => 1, - 'installed' => 1, - ]; $this->config->expects($this->once()) ->method('isNewRelicEnabled') ->willReturn(true); - $this->collect->expects($this->once()) - ->method('getModuleData') - ->willReturn($testModuleData); $this->counter->expects($this->once()) ->method('getAllProductsCount'); $this->counter->expects($this->once()) @@ -198,24 +184,10 @@ public function testReportNewRelicCron() */ public function testReportNewRelicCronRequestFailed() { - $testModuleData = [ - 'changes' => [ - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'], - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'], - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'], - ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'], - ], - 'enabled' => 1, - 'disabled' => 1, - 'installed' => 1, - ]; $this->config->expects($this->once()) ->method('isNewRelicEnabled') ->willReturn(true); - $this->collect->expects($this->once()) - ->method('getModuleData') - ->willReturn($testModuleData); $this->counter->expects($this->once()) ->method('getAllProductsCount'); $this->counter->expects($this->once()) diff --git a/app/code/Magento/NewRelicReporting/composer.json b/app/code/Magento/NewRelicReporting/composer.json index 63ecfc277e42a..4a02d673a54f6 100644 --- a/app/code/Magento/NewRelicReporting/composer.json +++ b/app/code/Magento/NewRelicReporting/composer.json @@ -5,15 +5,15 @@ "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", "magento/module-backend": "100.2.*", - "magento/module-customer": "100.2.*", + "magento/module-customer": "101.0.*", "magento/module-configurable-product": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-config": "100.2.*", - "magento/framework": "100.2.*", + "magento/module-catalog": "102.0.*", + "magento/module-config": "101.0.*", + "magento/framework": "101.0.*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/NewRelicReporting/etc/di.xml b/app/code/Magento/NewRelicReporting/etc/di.xml index a0d06105dd3fe..2dccc45c1129b 100644 --- a/app/code/Magento/NewRelicReporting/etc/di.xml +++ b/app/code/Magento/NewRelicReporting/etc/di.xml @@ -27,4 +27,14 @@ + + + + + + + Magento\NewRelicReporting\Console\Command\DeployMarker + + + diff --git a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid/Renderer/Sender.php b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid/Renderer/Sender.php index fcad9a10a0526..9905ce25e1664 100644 --- a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid/Renderer/Sender.php +++ b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid/Renderer/Sender.php @@ -26,7 +26,7 @@ public function render(\Magento\Framework\DataObject $row) $str .= htmlspecialchars($row->getTemplateSenderName()) . ' '; } if ($row->getTemplateSenderEmail()) { - $str .= '[' . $row->getTemplateSenderEmail() . ']'; + $str .= '[' . htmlspecialchars($row->getTemplateSenderEmail()) . ']'; } if ($str == '') { $str .= '---'; diff --git a/app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php b/app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php index b82d6fe06918f..58b51009c205a 100644 --- a/app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php +++ b/app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php @@ -8,6 +8,10 @@ use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Newsletter\Model\SubscriberFactory; +use Magento\Framework\Api\ExtensionAttributesFactory; +use Magento\Newsletter\Model\ResourceModel\Subscriber; +use Magento\Customer\Api\Data\CustomerExtensionInterface; +use Magento\Framework\App\ObjectManager; class CustomerPlugin { @@ -18,14 +22,37 @@ class CustomerPlugin */ private $subscriberFactory; + /** + * @var ExtensionAttributesFactory + */ + private $extensionFactory; + + /** + * @var Subscriber + */ + private $subscriberResource; + + /** + * @var array + */ + private $customerSubscriptionStatus = []; + /** * Initialize dependencies. * * @param SubscriberFactory $subscriberFactory + * @param ExtensionAttributesFactory|null $extensionFactory + * @param Subscriber|null $subscriberResource */ - public function __construct(SubscriberFactory $subscriberFactory) - { + public function __construct( + SubscriberFactory $subscriberFactory, + ExtensionAttributesFactory $extensionFactory = null, + Subscriber $subscriberResource = null + ) { $this->subscriberFactory = $subscriberFactory; + $this->extensionFactory = $extensionFactory + ?: ObjectManager::getInstance()->get(ExtensionAttributesFactory::class); + $this->subscriberResource = $subscriberResource ?: ObjectManager::getInstance()->get(Subscriber::class); } /** @@ -41,14 +68,30 @@ public function __construct(SubscriberFactory $subscriberFactory) */ public function afterSave(CustomerRepository $subject, CustomerInterface $result, CustomerInterface $customer) { - $this->subscriberFactory->create()->updateSubscription($result->getId()); - if ($result->getId() && $customer->getExtensionAttributes()) { - if ($customer->getExtensionAttributes()->getIsSubscribed() === true) { - $this->subscriberFactory->create()->subscribeCustomerById($result->getId()); - } elseif ($customer->getExtensionAttributes()->getIsSubscribed() === false) { - $this->subscriberFactory->create()->unsubscribeCustomerById($result->getId()); + $resultId = $result->getId(); + /** @var \Magento\Newsletter\Model\Subscriber $subscriber */ + $subscriber = $this->subscriberFactory->create(); + $subscriber->updateSubscription($resultId); + // update the result only if the original customer instance had different value. + $initialExtensionAttributes = $result->getExtensionAttributes(); + if ($initialExtensionAttributes === null) { + /** @var CustomerExtensionInterface $initialExtensionAttributes */ + $initialExtensionAttributes = $this->extensionFactory->create(CustomerInterface::class); + $result->setExtensionAttributes($initialExtensionAttributes); + } + $newExtensionAttributes = $customer->getExtensionAttributes(); + if ($newExtensionAttributes + && $initialExtensionAttributes->getIsSubscribed() !== $newExtensionAttributes->getIsSubscribed() + ) { + if ($newExtensionAttributes->getIsSubscribed() === true) { + $subscriber->subscribeCustomerById($resultId); + } elseif ($newExtensionAttributes->getIsSubscribed() === false) { + $subscriber->unsubscribeCustomerById($resultId); } } + $isSubscribed = $subscriber->isSubscribed(); + $this->customerSubscriptionStatus[$resultId] = $isSubscribed; + $initialExtensionAttributes->setIsSubscribed($isSubscribed); return $result; } @@ -94,4 +137,44 @@ public function afterDelete(CustomerRepository $subject, $result, CustomerInterf } return $result; } + + /** + * Plugin after getById customer that obtains newsletter subscription status for given customer. + * + * @param CustomerRepository $subject + * @param CustomerInterface $customer + * @return CustomerInterface + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterGetById(CustomerRepository $subject, CustomerInterface $customer) + { + $extensionAttributes = $customer->getExtensionAttributes(); + if ($extensionAttributes === null) { + /** @var CustomerExtensionInterface $extensionAttributes */ + $extensionAttributes = $this->extensionFactory->create(CustomerInterface::class); + $customer->setExtensionAttributes($extensionAttributes); + } + if ($extensionAttributes->getIsSubscribed() === null) { + $isSubscribed = $this->isSubscribed($customer); + $extensionAttributes->setIsSubscribed($isSubscribed); + } + return $customer; + } + + /** + * This method returns newsletters subscription status for given customer. + * + * @param CustomerInterface $customer + * @return mixed + */ + private function isSubscribed(CustomerInterface $customer) + { + $customerId = $customer->getId(); + if (!isset($this->customerSubscriptionStatus[$customerId])) { + $subscriber = $this->subscriberResource->loadByCustomerData($customer); + $this->customerSubscriptionStatus[$customerId] = isset($subscriber['subscriber_status']) + && $subscriber['subscriber_status'] == 1; + } + return $this->customerSubscriptionStatus[$customerId]; + } } diff --git a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php index c72ae42031001..c7ce4b2f2f11b 100644 --- a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php @@ -118,17 +118,37 @@ public function loadByEmail($subscriberEmail) */ public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer) { - $select = $this->connection->select()->from($this->getMainTable())->where('customer_id=:customer_id'); - - $result = $this->connection->fetchRow($select, ['customer_id' => $customer->getId()]); + $select = $this->connection + ->select() + ->from($this->getMainTable()) + ->where('customer_id=:customer_id and store_id=:store_id'); + + $result = $this->connection + ->fetchRow( + $select, + [ + 'customer_id' => $customer->getId(), + 'store_id' => $customer->getStoreId() + ] + ); if ($result) { return $result; } - $select = $this->connection->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email'); - - $result = $this->connection->fetchRow($select, ['subscriber_email' => $customer->getEmail()]); + $select = $this->connection + ->select() + ->from($this->getMainTable()) + ->where('subscriber_email=:subscriber_email and store_id=:store_id'); + + $result = $this->connection + ->fetchRow( + $select, + [ + 'subscriber_email' => $customer->getEmail(), + 'store_id' => $customer->getStoreId() + ] + ); if ($result) { return $result; diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index 7847098083949..8f29798472f19 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -7,8 +7,10 @@ use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\MailException; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Stdlib\DateTime\DateTime; /** * Subscriber model @@ -94,6 +96,12 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel */ protected $_customerSession; + /** + * Date + * @var DateTime + */ + private $dateTime; + /** * Store manager * @@ -134,9 +142,10 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel * @param CustomerRepositoryInterface $customerRepository * @param AccountManagementInterface $customerAccountManagement * @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource + * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data + * @param DateTime|null $dateTime * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -152,7 +161,8 @@ public function __construct( \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + DateTime $dateTime = null ) { $this->_newsletterData = $newsletterData; $this->_scopeConfig = $scopeConfig; @@ -162,6 +172,7 @@ public function __construct( $this->customerRepository = $customerRepository; $this->customerAccountManagement = $customerAccountManagement; $this->inlineTranslation = $inlineTranslation; + $this->dateTime = $dateTime ?: ObjectManager::getInstance()->get(DateTime::class); parent::__construct($context, $registry, $resource, $resourceCollection, $data); } @@ -349,6 +360,7 @@ public function loadByCustomerId($customerId) { try { $customerData = $this->customerRepository->getById($customerId); + $customerData->setStoreId($this->_storeManager->getStore()->getId()); $data = $this->getResource()->loadByCustomerData($customerData); $this->addData($data); if (!empty($data) && $customerData->getId() && !$this->getCustomerId()) { @@ -395,6 +407,10 @@ public function subscribe($email) { $this->loadByEmail($email); + if ($this->getId() && $this->getStatus() == self::STATUS_SUBSCRIBED) { + return $this->getStatus(); + } + if (!$this->getId()) { $this->setSubscriberConfirmCode($this->randomSequence()); } @@ -588,14 +604,20 @@ protected function _updateCustomerSubscription($customerId, $subscribe) $this->save(); $sendSubscription = $sendInformationEmail; - if ($sendSubscription === null xor $sendSubscription) { + if ($sendSubscription === null xor $sendSubscription && $this->isStatusChanged()) { try { - if ($isConfirmNeed) { - $this->sendConfirmationRequestEmail(); - } elseif ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) { - $this->sendUnsubscriptionEmail(); - } elseif ($this->isStatusChanged() && $status == self::STATUS_SUBSCRIBED) { - $this->sendConfirmationSuccessEmail(); + switch ($status) { + case self::STATUS_UNSUBSCRIBED: + $this->sendUnsubscriptionEmail(); + break; + case self::STATUS_SUBSCRIBED: + $this->sendConfirmationSuccessEmail(); + break; + case self::STATUS_NOT_ACTIVE: + if ($isConfirmNeed) { + $this->sendConfirmationRequestEmail(); + } + break; } } catch (MailException $e) { // If we are not able to send a new account email, this should be ignored @@ -617,6 +639,8 @@ public function confirm($code) $this->setStatus(self::STATUS_SUBSCRIBED) ->setStatusChanged(true) ->save(); + + $this->sendConfirmationSuccessEmail(); return true; } @@ -806,4 +830,18 @@ public function getSubscriberFullName() } return $name; } + + /** + * Set date of last changed status + * + * @return $this + */ + public function beforeSave() + { + parent::beforeSave(); + if ($this->dataHasChangedFor('subscriber_status')) { + $this->setChangeStatusAt($this->dateTime->gmtDate()); + } + return $this; + } } diff --git a/app/code/Magento/Newsletter/Setup/UpgradeSchema.php b/app/code/Magento/Newsletter/Setup/UpgradeSchema.php new file mode 100644 index 0000000000000..e7ce898de83a3 --- /dev/null +++ b/app/code/Magento/Newsletter/Setup/UpgradeSchema.php @@ -0,0 +1,36 @@ +startSetup(); + + if (version_compare($context->getVersion(), '2.0.1', '<')) { + $connection = $setup->getConnection(); + + $connection->addIndex( + $setup->getTable('newsletter_subscriber'), + $setup->getIdxName('newsletter_subscriber', ['subscriber_email']), + ['subscriber_email'] + ); + } + + $setup->endSetup(); + } +} diff --git a/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/Grid/Renderer/SenderTest.php b/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/Grid/Renderer/SenderTest.php new file mode 100644 index 0000000000000..baa80759314cb --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Template/Grid/Renderer/SenderTest.php @@ -0,0 +1,92 @@ +objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->sender = $this->objectManagerHelper->getObject( + \Magento\Newsletter\Block\Adminhtml\Template\Grid\Renderer\Sender::class + ); + } + + /** + * @dataProvider rendererDataProvider + * @param array $expectedSender + * @param array $passedSender + */ + public function testRender(array $passedSender, array $expectedSender) + { + $row = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['getTemplateSenderName', 'getTemplateSenderEmail']) + ->getMock(); + $row->expects($this->atLeastOnce())->method('getTemplateSenderName') + ->willReturn($passedSender['sender']); + $row->expects($this->atLeastOnce())->method('getTemplateSenderEmail') + ->willReturn($passedSender['sender_email']); + $this->assertEquals( + $expectedSender['sender'] . ' [' . $expectedSender['sender_email'] . ']', + $this->sender->render($row) + ); + } + + /** + * @return array + */ + public function rendererDataProvider() + { + return [ + [ + [ + 'sender' => 'Sender', + 'sender_email' => 'sender@example.com', + ], + [ + 'sender' => 'Sender', + 'sender_email' => 'sender@example.com', + ], + ], + [ + [ + 'sender' => "
      'Sender'
      ", + 'sender_email' => "
      'email@example.com'
      ", + ], + [ + 'sender' => "<br>'Sender'</br>", + 'sender_email' => "<br>'email@example.com'</br>", + ], + ], + [ + [ + 'sender' => '""@example.com', + 'sender_email' => '""@example.com', + ], + [ + 'sender' => '"<script>alert(document.domain)</script>"@example.com', + 'sender_email' => '"<script>alert(document.domain)</script>"@example.com', + ], + ], + ]; + } +} diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php index 47d4584857bde..39a9c2a0d95d2 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php @@ -7,13 +7,16 @@ use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Model\ResourceModel\CustomerRepository; +use Magento\Customer\Api\Data\CustomerExtensionInterface; +use Magento\Framework\Api\ExtensionAttributesFactory; +use Magento\Newsletter\Model\ResourceModel\Subscriber; class CustomerPluginTest extends \PHPUnit\Framework\TestCase { /** * @var \Magento\Newsletter\Model\Plugin\CustomerPlugin */ - protected $plugin; + private $plugin; /** * @var \Magento\Newsletter\Model\SubscriberFactory|\PHPUnit_Framework_MockObject_MockObject @@ -28,7 +31,27 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase /** * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ - protected $objectManager; + private $objectManager; + + /** + * @var ExtensionAttributesFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $extensionFactoryMock; + + /** + * @var CustomerExtensionInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $customerExtensionMock; + + /** + * @var Subscriber|\PHPUnit_Framework_MockObject_MockObject + */ + private $subscriberResourceMock; + + /** + * @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $customerMock; protected function setUp() { @@ -44,92 +67,97 @@ protected function setUp() 'delete', 'updateSubscription', 'subscribeCustomerById', - 'unsubscribeCustomerById' + 'unsubscribeCustomerById', + 'isSubscribed' ] )->disableOriginalConstructor() ->getMock(); + $this->extensionFactoryMock = $this->getMockBuilder(ExtensionAttributesFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->customerExtensionMock = $this->getMockBuilder(CustomerExtensionInterface::class) + ->setMethods(["getIsSubscribed", "setIsSubscribed"]) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->subscriberResourceMock = $this->getMockBuilder(Subscriber::class) + ->disableOriginalConstructor() + ->getMock(); + $this->customerMock = $this->getMockBuilder(CustomerInterface::class) + ->setMethods(["getExtensionAttributes"]) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); $this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber); - $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->plugin = $this->objectManager->getObject( \Magento\Newsletter\Model\Plugin\CustomerPlugin::class, [ - 'subscriberFactory' => $this->subscriberFactory + 'subscriberFactory' => $this->subscriberFactory, + 'extensionFactory' => $this->extensionFactoryMock, + 'subscriberResource' => $this->subscriberResourceMock ] ); } - public function testAfterSaveWithoutIsSubscribed() + /** + * @param bool $subscriptionOriginalValue + * @param bool $subscriptionNewValue + * @dataProvider afterSaveDataProvider + */ + public function testAfterSave($subscriptionOriginalValue, $subscriptionNewValue) { $customerId = 1; - /** @var CustomerInterface | \PHPUnit_Framework_MockObject_MockObject $customer */ - $customer = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class); - /** @var CustomerRepository | \PHPUnit_Framework_MockObject_MockObject $subject */ + /** @var CustomerInterface | \PHPUnit_Framework_MockObject_MockObject $result */ + $result = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class); + /** @var CustomerRepository |\PHPUnit_Framework_MockObject_MockObject $subject */ $subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class); - - $customer->expects($this->atLeastOnce()) - ->method("getId") - ->willReturn($customerId); - - $this->assertEquals($customer, $this->plugin->afterSave($subject, $customer, $customer)); + /** @var CustomerExtensionInterface|\PHPUnit_Framework_MockObject_MockObject $resultExtensionAttributes */ + $resultExtensionAttributes = $this->getMockBuilder(CustomerExtensionInterface::class) + ->setMethods(['getIsSubscribed', 'setIsSubscribed']) + ->getMockForAbstractClass(); + $result->expects($this->atLeastOnce())->method('getId')->willReturn($customerId); + $result->expects($this->any())->method('getExtensionAttributes')->willReturn(null); + $this->extensionFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($resultExtensionAttributes); + $result->expects($this->once()) + ->method('setExtensionAttributes') + ->with($resultExtensionAttributes) + ->willReturnSelf(); + $this->customerMock->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($this->customerExtensionMock); + $resultExtensionAttributes->expects($this->any()) + ->method('getIsSubscribed') + ->willReturn($subscriptionOriginalValue); + $this->customerExtensionMock->expects($this->any()) + ->method('getIsSubscribed') + ->willReturn($subscriptionNewValue); + if ($subscriptionOriginalValue !== $subscriptionNewValue) { + if ($subscriptionNewValue === true) { + $this->subscriber->expects($this->once())->method('subscribeCustomerById')->with($customerId); + } elseif ($subscriptionNewValue === false) { + $this->subscriber->expects($this->once())->method('unsubscribeCustomerById')->with($customerId); + } + $this->subscriber->expects($this->once())->method('isSubscribed')->willReturn($subscriptionNewValue); + $resultExtensionAttributes->expects($this->once())->method('setIsSubscribed')->with($subscriptionNewValue); + } + $this->assertEquals($result, $this->plugin->afterSave($subject, $result, $this->customerMock)); } /** * @return array */ - public function afterSaveExtensionAttributeDataProvider() + public function afterSaveDataProvider() { return [ [true, true], - [false, false] + [false, false], + [true, false], + [false, true], ]; } - /** - * @param boolean $isSubscribed - * @param boolean $subscribeIsCreated - * @dataProvider afterSaveExtensionAttributeDataProvider - */ - public function testAfterSaveWithIsSubscribed($isSubscribed, $subscribeIsCreated) - { - $customerId = 1; - /** @var CustomerInterface | \PHPUnit_Framework_MockObject_MockObject $customer */ - $customer = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class); - $extensionAttributes = $this - ->getMockBuilder(\Magento\Customer\Api\Data\CustomerExtensionInterface::class) - ->setMethods(["getIsSubscribed", "setIsSubscribed"]) - ->getMockForAbstractClass(); - - $extensionAttributes - ->expects($this->atLeastOnce()) - ->method("getIsSubscribed") - ->willReturn($isSubscribed); - - $customer->expects($this->atLeastOnce()) - ->method("getExtensionAttributes") - ->willReturn($extensionAttributes); - - if ($subscribeIsCreated) { - $this->subscriber->expects($this->once()) - ->method("subscribeCustomerById") - ->with($customerId); - } else { - $this->subscriber->expects($this->once()) - ->method("unsubscribeCustomerById") - ->with($customerId); - } - - /** @var CustomerRepository | \PHPUnit_Framework_MockObject_MockObject $subject */ - $subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class); - - $customer->expects($this->atLeastOnce()) - ->method("getId") - ->willReturn($customerId); - - $this->assertEquals($customer, $this->plugin->afterSave($subject, $customer, $customer)); - } - public function testAfterDelete() { $subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class); @@ -138,7 +166,6 @@ public function testAfterDelete() $this->subscriber->expects($this->once())->method('loadByEmail')->with('test@test.com')->willReturnSelf(); $this->subscriber->expects($this->once())->method('getId')->willReturn(1); $this->subscriber->expects($this->once())->method('delete')->willReturnSelf(); - $this->assertEquals(true, $this->plugin->afterDelete($subject, true, $customer)); } @@ -155,7 +182,77 @@ public function testAroundDeleteById() $this->subscriber->expects($this->once())->method('loadByEmail')->with('test@test.com')->willReturnSelf(); $this->subscriber->expects($this->once())->method('getId')->willReturn(1); $this->subscriber->expects($this->once())->method('delete')->willReturnSelf(); - $this->assertEquals(true, $this->plugin->aroundDeleteById($subject, $deleteCustomerById, $customerId)); } + + /** + * @param int|null $subscriberStatusKey + * @param int|null $subscriberStatusValue + * @param bool $isSubscribed + * @dataProvider afterGetByIdDataProvider + */ + public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet( + $subscriberStatusKey, + $subscriberStatusValue, + $isSubscribed + ) { + $subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class); + $subscriber = [$subscriberStatusKey => $subscriberStatusValue]; + $this->extensionFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->customerExtensionMock); + $this->customerMock->expects($this->once()) + ->method('setExtensionAttributes') + ->with($this->customerExtensionMock) + ->willReturnSelf(); + $this->customerMock->expects($this->any()) + ->method('getId') + ->willReturn(1); + $this->subscriberResourceMock->expects($this->once()) + ->method('loadByCustomerData') + ->with($this->customerMock) + ->willReturn($subscriber); + $this->customerExtensionMock->expects($this->once())->method('setIsSubscribed')->with($isSubscribed); + $this->assertEquals( + $this->customerMock, + $this->plugin->afterGetById($subject, $this->customerMock) + ); + } + + public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet() + { + $subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class); + $subscriber = ['subscriber_id' => 1, 'subscriber_status' => 1]; + $this->customerMock->expects($this->any()) + ->method('getExtensionAttributes') + ->willReturn($this->customerExtensionMock); + $this->customerExtensionMock->expects($this->any()) + ->method('getIsSubscribed') + ->willReturn(null); + $this->subscriberResourceMock->expects($this->once()) + ->method('loadByCustomerData') + ->with($this->customerMock) + ->willReturn($subscriber); + $this->customerExtensionMock->expects($this->once()) + ->method('setIsSubscribed') + ->willReturnSelf(); + $this->assertEquals( + $this->customerMock, + $this->plugin->afterGetById($subject, $this->customerMock) + ); + } + + /** + * @return array + */ + public function afterGetByIdDataProvider() + { + return [ + ['subscriber_status', 1, true], + ['subscriber_status', 2, false], + ['subscriber_status', 3, false], + ['subscriber_status', 4, false], + [null, null, false] + ]; + } } diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php index 7716f4744a922..7dd96be11bcbe 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php @@ -187,6 +187,12 @@ public function testUpdateSubscription() $customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id'); $customerDataMock->expects($this->once())->method('getEmail')->willReturn('email'); + $storeModel = $this->getMockBuilder(\Magento\Store\Model\Store::class) + ->disableOriginalConstructor() + ->setMethods(['getId']) + ->getMock(); + $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); + $this->assertEquals($this->subscriber, $this->subscriber->updateSubscription($customerId)); } @@ -335,6 +341,21 @@ public function testConfirm() $code = 111; $this->subscriber->setCode($code); $this->resource->expects($this->once())->method('save')->willReturnSelf(); + $storeModel = $this->getMockBuilder(\Magento\Store\Model\Store::class) + ->disableOriginalConstructor() + ->setMethods(['getId']) + ->getMock(); + $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class); + $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); + $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->willReturnSelf(); + $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->willReturnSelf(); + $this->transportBuilder->expects($this->once())->method('setTemplateVars')->willReturnSelf(); + $this->transportBuilder->expects($this->once())->method('setFrom')->willReturnSelf(); + $this->transportBuilder->expects($this->once())->method('addTo')->willReturnSelf(); + $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); + $storeModel->expects($this->any())->method('getId')->willReturn(1); + $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport); + $transport->expects($this->once())->method('sendMessage')->willReturnSelf(); $this->assertTrue($this->subscriber->confirm($code)); } diff --git a/app/code/Magento/Newsletter/composer.json b/app/code/Magento/Newsletter/composer.json index 04d75de1f6f5c..eacbf9c6a4502 100644 --- a/app/code/Magento/Newsletter/composer.json +++ b/app/code/Magento/Newsletter/composer.json @@ -4,17 +4,17 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-customer": "100.2.*", - "magento/module-widget": "100.2.*", + "magento/module-customer": "101.0.*", + "magento/module-widget": "101.0.*", "magento/module-backend": "100.2.*", - "magento/module-cms": "101.1.*", + "magento/module-cms": "102.0.*", "magento/module-email": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-require-js": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.2", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Newsletter/etc/module.xml b/app/code/Magento/Newsletter/etc/module.xml index f338445225222..5da16a9a3e9ba 100644 --- a/app/code/Magento/Newsletter/etc/module.xml +++ b/app/code/Magento/Newsletter/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_problem_block.xml b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_problem_block.xml index 2e2effa496b2f..3eb7de194d242 100644 --- a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_problem_block.xml +++ b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_problem_block.xml @@ -21,7 +21,7 @@ problemGrid We found no problems. - + 0 Magento\Newsletter\Block\Adminhtml\Problem\Grid\Filter\Checkbox @@ -30,7 +30,7 @@ col-select - + ID problem_id @@ -38,7 +38,7 @@ col-id - + Subscriber #$subscriber_id $customer_name ($subscriber_email) @@ -47,7 +47,7 @@ col-subscriber col-name - + Queue Start Date queue_start_at @@ -57,7 +57,7 @@ col-start col-date - + Queue Subject template_subject @@ -65,7 +65,7 @@ col-subject - + Error Code problem_error_code @@ -74,7 +74,7 @@ col-error-code - + Error Text problem_error_text diff --git a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_grid_block.xml b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_grid_block.xml index 2c2ac7d32d71c..3bfb52157bb99 100644 --- a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_grid_block.xml +++ b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_queue_grid_block.xml @@ -26,7 +26,7 @@ - + ID queue_id @@ -34,7 +34,7 @@ col-id - + Queue Start datetime @@ -45,7 +45,7 @@ col-start - + Queue End datetime @@ -56,7 +56,7 @@ col-finish - + Subject newsletter_subject @@ -64,7 +64,7 @@ col-subject - + Status queue_status @@ -74,7 +74,7 @@ col-status - + Processed number @@ -83,7 +83,7 @@ col-processed - + Recipients number @@ -92,7 +92,7 @@ col-recipients - + Action 0 diff --git a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_subscriber_block.xml b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_subscriber_block.xml index 0dd1c6d744a8f..9de1807af18ec 100644 --- a/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_subscriber_block.xml +++ b/app/code/Magento/Newsletter/view/adminhtml/layout/newsletter_subscriber_block.xml @@ -51,7 +51,7 @@ problemGrid - + ID subscriber_id @@ -59,7 +59,7 @@ col-id - + Email subscriber_email @@ -67,7 +67,7 @@ ccol-email - + Type type @@ -86,7 +86,7 @@ col-type - + Customer First Name firstname @@ -95,7 +95,7 @@ col-first-name - + Customer Last Name lastname @@ -104,7 +104,7 @@ col-last-name - + Status subscriber_status @@ -131,7 +131,7 @@ col-status - + Web Site website_id @@ -141,7 +141,7 @@ col-website - + Store group_id @@ -151,7 +151,7 @@ col-store - + Store View store_id diff --git a/app/code/Magento/OfflinePayments/composer.json b/app/code/Magento/OfflinePayments/composer.json index 1296d5742199d..f03333a976f17 100644 --- a/app/code/Magento/OfflinePayments/composer.json +++ b/app/code/Magento/OfflinePayments/composer.json @@ -5,13 +5,13 @@ "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-checkout": "100.2.*", "magento/module-payment": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "suggest": { - "magento/module-config": "100.2.*" + "magento/module-config": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php index b12691ad16245..87d4b984cf933 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php @@ -113,8 +113,9 @@ public function collectRates(RateRequest $request) // Free shipping by qty $freeQty = 0; + $freePackageValue = 0; + if ($request->getAllItems()) { - $freePackageValue = 0; foreach ($request->getAllItems() as $item) { if ($item->getProduct()->isVirtual() || $item->getParentItem()) { continue; diff --git a/app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate.php b/app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate.php index 500ab253f2a18..961958a54ac1b 100644 --- a/app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate.php +++ b/app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate.php @@ -232,10 +232,10 @@ private function importData(array $fields, array $values) $this->_importedRows += count($values); } } catch (\Magento\Framework\Exception\LocalizedException $e) { - $connection->rollback(); + $connection->rollBack(); throw new \Magento\Framework\Exception\LocalizedException(__('Unable to import data'), $e); } catch (\Exception $e) { - $connection->rollback(); + $connection->rollBack(); $this->logger->critical($e); throw new \Magento\Framework\Exception\LocalizedException( __('Something went wrong while importing table rates.') diff --git a/app/code/Magento/OfflineShipping/Test/Unit/Block/Adminhtml/Form/Field/ExportTest.php b/app/code/Magento/OfflineShipping/Test/Unit/Block/Adminhtml/Form/Field/ExportTest.php index cc164e504b665..3e2c7df9087da 100644 --- a/app/code/Magento/OfflineShipping/Test/Unit/Block/Adminhtml/Form/Field/ExportTest.php +++ b/app/code/Magento/OfflineShipping/Test/Unit/Block/Adminhtml/Form/Field/ExportTest.php @@ -37,7 +37,7 @@ public function testGetElementHtml() $requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class); $requestMock->expects($this->once())->method('getParam')->with('website')->will($this->returnValue(1)); - $mockData = $this->createPartialMock(\StdClass::class, ['toHtml']); + $mockData = $this->createPartialMock(\stdClass::class, ['toHtml']); $mockData->expects($this->once())->method('toHtml')->will($this->returnValue($expected)); $blockMock->expects($this->once())->method('getRequest')->will($this->returnValue($requestMock)); diff --git a/app/code/Magento/OfflineShipping/composer.json b/app/code/Magento/OfflineShipping/composer.json index e3f374c5d42a2..2ce66fa368d01 100644 --- a/app/code/Magento/OfflineShipping/composer.json +++ b/app/code/Magento/OfflineShipping/composer.json @@ -3,23 +3,23 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-config": "100.2.*", + "magento/module-config": "101.0.*", "magento/module-store": "100.2.*", "magento/module-backend": "100.2.*", "magento/module-shipping": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-sales": "100.2.*", - "magento/module-sales-rule": "100.2.*", + "magento/module-catalog": "102.0.*", + "magento/module-sales": "101.0.*", + "magento/module-sales-rule": "101.0.*", "magento/module-directory": "100.2.*", - "magento/module-quote": "100.2.*", - "magento/framework": "100.2.*" + "magento/module-quote": "101.0.*", + "magento/framework": "101.0.*" }, "suggest": { "magento/module-checkout": "100.2.*", "magento/module-offline-shipping-sample-data": "Sample Data version:100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/PageCache/composer.json b/app/code/Magento/PageCache/composer.json index 8d4b988a77aa7..cdbd8327b9cdd 100644 --- a/app/code/Magento/PageCache/composer.json +++ b/app/code/Magento/PageCache/composer.json @@ -3,13 +3,13 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-config": "100.2.*", + "magento/module-config": "101.0.*", "magento/module-store": "100.2.*", "magento/module-backend": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/PageCache/etc/varnish4.vcl b/app/code/Magento/PageCache/etc/varnish4.vcl index 3e8acfba18762..793f8f81a03f9 100644 --- a/app/code/Magento/PageCache/etc/varnish4.vcl +++ b/app/code/Magento/PageCache/etc/varnish4.vcl @@ -141,6 +141,10 @@ sub vcl_backend_response { set beresp.do_gzip = true; } + if (beresp.http.X-Magento-Debug) { + set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; + } + # cache only successfully responses and 404s if (beresp.status != 200 && beresp.status != 404) { set beresp.ttl = 0s; @@ -152,23 +156,23 @@ sub vcl_backend_response { return (deliver); } - if (beresp.http.X-Magento-Debug) { - set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; - } - # validate if we need to cache it and prevent from setting cookie + # images, css and js are cacheable by default so we have to remove cookie also if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { unset beresp.http.set-cookie; } # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass if (beresp.ttl <= 0s || - beresp.http.Surrogate-control ~ "no-store" || - (!beresp.http.Surrogate-Control && beresp.http.Vary == "*")) { - # Mark as Hit-For-Pass for the next 2 minutes + beresp.http.Surrogate-control ~ "no-store" || + (!beresp.http.Surrogate-Control && + beresp.http.Cache-Control ~ "no-cache|no-store") || + beresp.http.Vary == "*") { + # Mark as Hit-For-Pass for the next 2 minutes set beresp.ttl = 120s; set beresp.uncacheable = true; } + return (deliver); } @@ -184,6 +188,13 @@ sub vcl_deliver { unset resp.http.Age; } + # Not letting browser to cache non-static files. + if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") { + set resp.http.Pragma = "no-cache"; + set resp.http.Expires = "-1"; + set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; + } + unset resp.http.X-Magento-Debug; unset resp.http.X-Magento-Tags; unset resp.http.X-Powered-By; diff --git a/app/code/Magento/PageCache/etc/varnish5.vcl b/app/code/Magento/PageCache/etc/varnish5.vcl index c060090aa91ed..4dce6356d1e73 100644 --- a/app/code/Magento/PageCache/etc/varnish5.vcl +++ b/app/code/Magento/PageCache/etc/varnish5.vcl @@ -142,6 +142,10 @@ sub vcl_backend_response { set beresp.do_gzip = true; } + if (beresp.http.X-Magento-Debug) { + set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; + } + # cache only successfully responses and 404s if (beresp.status != 200 && beresp.status != 404) { set beresp.ttl = 0s; @@ -153,23 +157,23 @@ sub vcl_backend_response { return (deliver); } - if (beresp.http.X-Magento-Debug) { - set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; - } - # validate if we need to cache it and prevent from setting cookie + # images, css and js are cacheable by default so we have to remove cookie also if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { unset beresp.http.set-cookie; } # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass if (beresp.ttl <= 0s || - beresp.http.Surrogate-control ~ "no-store" || - (!beresp.http.Surrogate-Control && beresp.http.Vary == "*")) { + beresp.http.Surrogate-control ~ "no-store" || + (!beresp.http.Surrogate-Control && + beresp.http.Cache-Control ~ "no-cache|no-store") || + beresp.http.Vary == "*") { # Mark as Hit-For-Pass for the next 2 minutes set beresp.ttl = 120s; set beresp.uncacheable = true; } + return (deliver); } @@ -185,6 +189,13 @@ sub vcl_deliver { unset resp.http.Age; } + # Not letting browser to cache non-static files. + if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") { + set resp.http.Pragma = "no-cache"; + set resp.http.Expires = "-1"; + set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; + } + unset resp.http.X-Magento-Debug; unset resp.http.X-Magento-Tags; unset resp.http.X-Powered-By; diff --git a/app/code/Magento/PageCache/view/adminhtml/layout/adminhtml_system_config_edit.xml b/app/code/Magento/PageCache/view/adminhtml/layout/adminhtml_system_config_edit.xml index ac0271434bc62..2938e1bc961d7 100644 --- a/app/code/Magento/PageCache/view/adminhtml/layout/adminhtml_system_config_edit.xml +++ b/app/code/Magento/PageCache/view/adminhtml/layout/adminhtml_system_config_edit.xml @@ -8,7 +8,7 @@ - + diff --git a/app/code/Magento/Payment/Gateway/Command/GatewayCommand.php b/app/code/Magento/Payment/Gateway/Command/GatewayCommand.php index a6f9d4383918c..bb07408ad0e06 100644 --- a/app/code/Magento/Payment/Gateway/Command/GatewayCommand.php +++ b/app/code/Magento/Payment/Gateway/Command/GatewayCommand.php @@ -5,14 +5,13 @@ */ namespace Magento\Payment\Gateway\Command; -use Magento\Framework\Phrase; use Magento\Payment\Gateway\CommandInterface; +use Magento\Payment\Gateway\ErrorMapper\ErrorMessageMapperInterface; use Magento\Payment\Gateway\Http\ClientInterface; use Magento\Payment\Gateway\Http\TransferFactoryInterface; -use Magento\Payment\Gateway\Request; use Magento\Payment\Gateway\Request\BuilderInterface; -use Magento\Payment\Gateway\Response; use Magento\Payment\Gateway\Response\HandlerInterface; +use Magento\Payment\Gateway\Validator\ResultInterface; use Magento\Payment\Gateway\Validator\ValidatorInterface; use Psr\Log\LoggerInterface; @@ -54,6 +53,11 @@ class GatewayCommand implements CommandInterface */ private $logger; + /** + * @var ErrorMessageMapperInterface + */ + private $errorMessageMapper; + /** * @param BuilderInterface $requestBuilder * @param TransferFactoryInterface $transferFactory @@ -61,6 +65,7 @@ class GatewayCommand implements CommandInterface * @param LoggerInterface $logger * @param HandlerInterface $handler * @param ValidatorInterface $validator + * @param ErrorMessageMapperInterface|null $errorMessageMapper */ public function __construct( BuilderInterface $requestBuilder, @@ -68,7 +73,8 @@ public function __construct( ClientInterface $client, LoggerInterface $logger, HandlerInterface $handler = null, - ValidatorInterface $validator = null + ValidatorInterface $validator = null, + ErrorMessageMapperInterface $errorMessageMapper = null ) { $this->requestBuilder = $requestBuilder; $this->transferFactory = $transferFactory; @@ -76,6 +82,7 @@ public function __construct( $this->handler = $handler; $this->validator = $validator; $this->logger = $logger; + $this->errorMessageMapper = $errorMessageMapper; } /** @@ -98,10 +105,7 @@ public function execute(array $commandSubject) array_merge($commandSubject, ['response' => $response]) ); if (!$result->isValid()) { - $this->logExceptions($result->getFailsDescription()); - throw new CommandException( - __('Transaction has been declined. Please try again later.') - ); + $this->processErrors($result); } } @@ -114,13 +118,33 @@ public function execute(array $commandSubject) } /** - * @param Phrase[] $fails - * @return void + * Tries to map error messages from validation result and logs processed message. + * Throws an exception with mapped message or default error. + * + * @param ResultInterface $result + * @throws CommandException */ - private function logExceptions(array $fails) + private function processErrors(ResultInterface $result) { - foreach ($fails as $failPhrase) { - $this->logger->critical((string) $failPhrase); + $messages = []; + foreach ($result->getFailsDescription() as $failPhrase) { + $message = (string) $failPhrase; + + // error messages mapper can be not configured if payment method doesn't have custom error messages. + if ($this->errorMessageMapper !== null) { + $mapped = (string) $this->errorMessageMapper->getMessage($message); + if (!empty($mapped)) { + $messages[] = $mapped; + $message = $mapped; + } + } + $this->logger->critical('Payment Error: ' . $message); } + + throw new CommandException( + !empty($messages) + ? __(implode(PHP_EOL, $messages)) + : __('Transaction has been declined. Please try again later.') + ); } } diff --git a/app/code/Magento/Payment/Gateway/ErrorMapper/ErrorMessageMapper.php b/app/code/Magento/Payment/Gateway/ErrorMapper/ErrorMessageMapper.php new file mode 100644 index 0000000000000..c5759d41bf4d7 --- /dev/null +++ b/app/code/Magento/Payment/Gateway/ErrorMapper/ErrorMessageMapper.php @@ -0,0 +1,40 @@ +messageMapping = $messageMapping; + } + + /** + * @inheritdoc + */ + public function getMessage(string $code) + { + $message = $this->messageMapping->get($code); + return $message ? __($message) : null; + } +} diff --git a/app/code/Magento/Payment/Gateway/ErrorMapper/ErrorMessageMapperInterface.php b/app/code/Magento/Payment/Gateway/ErrorMapper/ErrorMessageMapperInterface.php new file mode 100644 index 0000000000000..077226fd9a062 --- /dev/null +++ b/app/code/Magento/Payment/Gateway/ErrorMapper/ErrorMessageMapperInterface.php @@ -0,0 +1,23 @@ +message` format and converts it to [code => message] array format. + */ +class XmlToArrayConverter implements ConverterInterface +{ + /** + * @inheritdoc + */ + public function convert($source) + { + $result = []; + $messageList = $source->getElementsByTagName('message'); + foreach ($messageList as $messageNode) { + $result[(string) $messageNode->getAttribute('code')] = (string) $messageNode->nodeValue; + } + return $result; + } +} diff --git a/app/code/Magento/Payment/Helper/Data.php b/app/code/Magento/Payment/Helper/Data.php index e3122913d5dfa..f3565ea324290 100644 --- a/app/code/Magento/Payment/Helper/Data.php +++ b/app/code/Magento/Payment/Helper/Data.php @@ -293,6 +293,7 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit foreach ($methods as $code => $title) { if (isset($groups[$code])) { $labelValues[$code]['label'] = $title; + $labelValues[$code]['value'] = null; } elseif (isset($groupRelations[$code])) { unset($labelValues[$code]); $labelValues[$groupRelations[$code]]['value'][$code] = ['value' => $code, 'label' => $title]; diff --git a/app/code/Magento/Payment/Model/Method/AbstractMethod.php b/app/code/Magento/Payment/Model/Method/AbstractMethod.php index 5378aa3bf5379..1972bd0745d41 100644 --- a/app/code/Magento/Payment/Model/Method/AbstractMethod.php +++ b/app/code/Magento/Payment/Model/Method/AbstractMethod.php @@ -8,12 +8,14 @@ namespace Magento\Payment\Model\Method; +use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject; use Magento\Payment\Model\InfoInterface; use Magento\Payment\Model\MethodInterface; use Magento\Payment\Observer\AbstractDataAssignObserver; use Magento\Quote\Api\Data\PaymentMethodInterface; use Magento\Sales\Model\Order\Payment; +use Magento\Directory\Helper\Data as DirectoryHelper; /** * Payment method abstract model @@ -219,6 +221,11 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl */ protected $logger; + /** + * @var DirectoryHelper + */ + private $directory; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -230,6 +237,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param DirectoryHelper $directory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -242,7 +250,8 @@ public function __construct( \Magento\Payment\Model\Method\Logger $logger, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + DirectoryHelper $directory = null ) { parent::__construct( $context, @@ -256,6 +265,7 @@ public function __construct( $this->_paymentData = $paymentData; $this->_scopeConfig = $scopeConfig; $this->logger = $logger; + $this->directory = $directory ?: ObjectManager::getInstance()->get(DirectoryHelper::class); $this->initializeData($data); } @@ -605,6 +615,7 @@ public function validate() } else { $billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId(); } + $billingCountry = $billingCountry ?: $this->directory->getDefaultCountry(); if (!$this->canUseForCountry($billingCountry)) { throw new \Magento\Framework\Exception\LocalizedException( __('You can\'t use the payment type you selected to make payments to the billing country.') diff --git a/app/code/Magento/Payment/Model/Method/Adapter.php b/app/code/Magento/Payment/Model/Method/Adapter.php index 1d39ac1be187f..85c1584eb44f8 100644 --- a/app/code/Magento/Payment/Model/Method/Adapter.php +++ b/app/code/Magento/Payment/Model/Method/Adapter.php @@ -317,7 +317,7 @@ public function isAvailable(CartInterface $quote = null) */ public function isActive($storeId = null) { - return $this->getConfiguredValue('active', $storeId); + return (bool)$this->getConfiguredValue('active', $storeId); } /** diff --git a/app/code/Magento/Payment/Model/Method/Logger.php b/app/code/Magento/Payment/Model/Method/Logger.php index 74068c3b6fef0..90a2a94f92fc2 100644 --- a/app/code/Magento/Payment/Model/Method/Logger.php +++ b/app/code/Magento/Payment/Model/Method/Logger.php @@ -8,9 +8,7 @@ use Psr\Log\LoggerInterface; /** - * Class Logger for payment related information (request, response, etc.) which is used for debug - * - * @author Magento Core Team + * Class Logger for payment related information (request, response, etc.) which is used for debug. * * @api * @since 100.0.2 @@ -69,7 +67,7 @@ public function debug(array $data, array $maskKeys = null, $forceDebug = null) */ private function getDebugReplaceFields() { - if ($this->config and $this->config->getValue('debugReplaceKeys')) { + if ($this->config && $this->config->getValue('debugReplaceKeys')) { return explode(',', $this->config->getValue('debugReplaceKeys')); } return []; @@ -82,7 +80,7 @@ private function getDebugReplaceFields() */ private function isDebugOn() { - return $this->config and (bool)$this->config->getValue('debug'); + return $this->config && (bool)$this->config->getValue('debug'); } /** diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Command/GatewayCommandTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Command/GatewayCommandTest.php index df8bdc9bca54b..d17a7f302f31b 100644 --- a/app/code/Magento/Payment/Test/Unit/Gateway/Command/GatewayCommandTest.php +++ b/app/code/Magento/Payment/Test/Unit/Gateway/Command/GatewayCommandTest.php @@ -6,11 +6,15 @@ namespace Magento\Payment\Test\Unit\Gateway\Command; use Magento\Payment\Gateway\Command\GatewayCommand; +use Magento\Payment\Gateway\ErrorMapper\ErrorMessageMapperInterface; use Magento\Payment\Gateway\Http\ClientInterface; use Magento\Payment\Gateway\Http\TransferFactoryInterface; +use Magento\Payment\Gateway\Http\TransferInterface; use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Payment\Gateway\Response\HandlerInterface; +use Magento\Payment\Gateway\Validator\ResultInterface; use Magento\Payment\Gateway\Validator\ValidatorInterface; +use PHPUnit_Framework_MockObject_MockObject as MockObject; use Psr\Log\LoggerInterface; /** @@ -18,175 +22,176 @@ */ class GatewayCommandTest extends \PHPUnit\Framework\TestCase { - /** @var GatewayCommand */ - protected $command; + /** + * @var GatewayCommand + */ + private $command; /** - * @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject + * @var BuilderInterface|MockObject */ - protected $requestBuilderMock; + private $requestBuilder; /** - * @var TransferFactoryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var TransferFactoryInterface|MockObject */ - protected $transferFactoryMock; + private $transferFactory; /** - * @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ClientInterface|MockObject */ - protected $clientMock; + private $client; /** - * @var HandlerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var HandlerInterface|MockObject */ - protected $responseHandlerMock; + private $responseHandler; /** - * @var ValidatorInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ValidatorInterface|MockObject */ - protected $validatorMock; + private $validator; /** - * @var LoggerInterface |\PHPUnit_Framework_MockObject_MockObject + * @var LoggerInterface|MockObject */ private $logger; + /** + * @var ErrorMessageMapperInterface|MockObject + */ + private $errorMessageMapper; + protected function setUp() { - $this->requestBuilderMock = $this->createMock( - BuilderInterface::class - ); - $this->transferFactoryMock = $this->createMock( - TransferFactoryInterface::class - ); - $this->clientMock = $this->createMock( - ClientInterface::class - ); - $this->responseHandlerMock = $this->createMock( - HandlerInterface::class - ); - $this->validatorMock = $this->createMock( - ValidatorInterface::class - ); + $this->requestBuilder = $this->createMock(BuilderInterface::class); + $this->transferFactory = $this->createMock(TransferFactoryInterface::class); + $this->client = $this->createMock(ClientInterface::class); + $this->responseHandler = $this->createMock(HandlerInterface::class); + $this->validator = $this->createMock(ValidatorInterface::class); $this->logger = $this->createMock(LoggerInterface::class); + $this->errorMessageMapper = $this->createMock(ErrorMessageMapperInterface::class); $this->command = new GatewayCommand( - $this->requestBuilderMock, - $this->transferFactoryMock, - $this->clientMock, + $this->requestBuilder, + $this->transferFactory, + $this->client, $this->logger, - $this->responseHandlerMock, - $this->validatorMock + $this->responseHandler, + $this->validator, + $this->errorMessageMapper ); } public function testExecute() { $commandSubject = ['authorize']; - $request = [ - 'request_field1' => 'request_value1', - 'request_field2' => 'request_value2' - ]; - $response = ['response_field1' => 'response_value1']; - $validationResult = $this->getMockBuilder( - \Magento\Payment\Gateway\Validator\ResultInterface::class - ) - ->getMockForAbstractClass(); + $this->processRequest($commandSubject, true); - $transferO = $this->getMockBuilder( - \Magento\Payment\Gateway\Http\TransferInterface::class - ) - ->getMockForAbstractClass(); + $this->responseHandler->method('handle') + ->with($commandSubject, ['response_field1' => 'response_value1']); - $this->requestBuilderMock->expects(static::once()) - ->method('build') - ->with($commandSubject) - ->willReturn($request); + $this->command->execute($commandSubject); + } - $this->transferFactoryMock->expects(static::once()) - ->method('create') - ->with($request) - ->willReturn($transferO); + /** + * Checks a case when request fails. + * + * @expectedException \Magento\Payment\Gateway\Command\CommandException + * @expectedExceptionMessage Transaction has been declined. Please try again later. + */ + public function testExecuteValidationFail() + { + $commandSubject = ['authorize']; + $validationFailures = [ + __('Failure #1'), + __('Failure #2'), + ]; - $this->clientMock->expects(static::once()) - ->method('placeRequest') - ->with($transferO) - ->willReturn($response); - $this->validatorMock->expects(static::once()) - ->method('validate') - ->with(array_merge($commandSubject, ['response' =>$response])) - ->willReturn($validationResult); - $validationResult->expects(static::once()) - ->method('isValid') - ->willReturn(true); + $this->processRequest($commandSubject, false, $validationFailures); - $this->responseHandlerMock->expects(static::once()) - ->method('handle') - ->with($commandSubject, $response); + $this->logger->expects(self::exactly(count($validationFailures))) + ->method('critical') + ->withConsecutive( + [self::equalTo('Payment Error: ' . $validationFailures[0])], + [self::equalTo('Payment Error: ' . $validationFailures[1])] + ); $this->command->execute($commandSubject); } - public function testExecuteValidationFail() + /** + * Checks a case when request fails and response errors are mapped. + * + * @expectedException \Magento\Payment\Gateway\Command\CommandException + * @expectedExceptionMessage Failure Mapped + */ + public function testExecuteValidationFailWithMappedErrors() { - $this->expectException( - \Magento\Payment\Gateway\Command\CommandException::class - ); - $commandSubject = ['authorize']; - $request = [ - 'request_field1' => 'request_value1', - 'request_field2' => 'request_value2' - ]; - $response = ['response_field1' => 'response_value1']; $validationFailures = [ __('Failure #1'), __('Failure #2'), ]; - $validationResult = $this->getMockBuilder( - \Magento\Payment\Gateway\Validator\ResultInterface::class - ) - ->getMockForAbstractClass(); - $transferO = $this->getMockBuilder( - \Magento\Payment\Gateway\Http\TransferInterface::class - ) + $this->processRequest($commandSubject, false, $validationFailures); + + $this->errorMessageMapper->method('getMessage') + ->willReturnMap( + [ + ['Failure #1', 'Failure Mapped'], + ['Failure #2', null] + ] + ); + + $this->logger->expects(self::exactly(count($validationFailures))) + ->method('critical') + ->withConsecutive( + [self::equalTo('Payment Error: Failure Mapped')], + [self::equalTo('Payment Error: Failure #2')] + ); + + $this->command->execute($commandSubject); + } + + /** + * Performs command actions like request, response and validation. + * + * @param array $commandSubject + * @param bool $validationResult + * @param array $validationFailures + */ + private function processRequest(array $commandSubject, bool $validationResult, array $validationFailures = []) + { + $request = [ + 'request_field1' => 'request_value1', + 'request_field2' => 'request_value2' + ]; + $response = ['response_field1' => 'response_value1']; + $transferO = $this->getMockBuilder(TransferInterface::class) ->getMockForAbstractClass(); - $this->requestBuilderMock->expects(static::once()) - ->method('build') + $this->requestBuilder->method('build') ->with($commandSubject) ->willReturn($request); - $this->transferFactoryMock->expects(static::once()) - ->method('create') + $this->transferFactory->method('create') ->with($request) ->willReturn($transferO); - $this->clientMock->expects(static::once()) - ->method('placeRequest') + $this->client->method('placeRequest') ->with($transferO) ->willReturn($response); - $this->validatorMock->expects(static::once()) - ->method('validate') - ->with(array_merge($commandSubject, ['response' =>$response])) - ->willReturn($validationResult); - $validationResult->expects(static::once()) - ->method('isValid') - ->willReturn(false); - $validationResult->expects(static::once()) - ->method('getFailsDescription') - ->willReturn( - $validationFailures - ); - $this->logger->expects(static::exactly(count($validationFailures))) - ->method('critical') - ->withConsecutive( - [$validationFailures[0]], - [$validationFailures[1]] - ); + $result = $this->getMockBuilder(ResultInterface::class) + ->getMockForAbstractClass(); - $this->command->execute($commandSubject); + $this->validator->method('validate') + ->with(array_merge($commandSubject, ['response' => $response])) + ->willReturn($result); + $result->method('isValid') + ->willReturn($validationResult); + $result->method('getFailsDescription') + ->willReturn($validationFailures); } } diff --git a/app/code/Magento/Payment/Test/Unit/Model/Method/FactoryTest.php b/app/code/Magento/Payment/Test/Unit/Model/Method/FactoryTest.php deleted file mode 100644 index f0cb19ef0fa0f..0000000000000 --- a/app/code/Magento/Payment/Test/Unit/Model/Method/FactoryTest.php +++ /dev/null @@ -1,89 +0,0 @@ -_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class); - $this->_factory = $objectManagerHelper->getObject( - \Magento\Payment\Model\Method\Factory::class, - ['objectManager' => $this->_objectManagerMock] - ); - } - - public function testCreateMethod() - { - $className = \Magento\Payment\Model\Method\AbstractMethod::class; - $methodMock = $this->createMock($className); - $this->_objectManagerMock->expects( - $this->once() - )->method( - 'create' - )->with( - $className, - [] - )->will( - $this->returnValue($methodMock) - ); - - $this->assertEquals($methodMock, $this->_factory->create($className)); - } - - public function testCreateMethodWithArguments() - { - $className = \Magento\Payment\Model\Method\AbstractMethod::class; - $data = ['param1', 'param2']; - $methodMock = $this->createMock($className); - $this->_objectManagerMock->expects( - $this->once() - )->method( - 'create' - )->with( - $className, - $data - )->will( - $this->returnValue($methodMock) - ); - - $this->assertEquals($methodMock, $this->_factory->create($className, $data)); - } - - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage WrongClass class doesn't implement \Magento\Payment\Model\MethodInterface - */ - public function testWrongTypeException() - { - $className = 'WrongClass'; - $methodMock = $this->createMock($className); - $this->_objectManagerMock->expects( - $this->once() - )->method( - 'create' - )->with( - $className, - [] - )->will( - $this->returnValue($methodMock) - ); - - $this->_factory->create($className); - } -} diff --git a/app/code/Magento/Payment/Test/Unit/Model/Method/Specification/FactoryTest.php b/app/code/Magento/Payment/Test/Unit/Model/Method/Specification/FactoryTest.php deleted file mode 100644 index 9bdc90829f6fe..0000000000000 --- a/app/code/Magento/Payment/Test/Unit/Model/Method/Specification/FactoryTest.php +++ /dev/null @@ -1,71 +0,0 @@ -objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class); - - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->factory = $objectManagerHelper->getObject( - \Magento\Payment\Model\Method\Specification\Factory::class, - ['objectManager' => $this->objectManagerMock] - ); - } - - public function testCreateMethod() - { - $className = \Magento\Payment\Model\Method\SpecificationInterface::class; - $methodMock = $this->createMock($className); - $this->objectManagerMock->expects( - $this->once() - )->method( - 'get' - )->with( - $className - )->will( - $this->returnValue($methodMock) - ); - - $this->assertEquals($methodMock, $this->factory->create($className)); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Specification must implement SpecificationInterface - */ - public function testWrongTypeException() - { - $className = 'WrongClass'; - $methodMock = $this->createMock($className); - $this->objectManagerMock->expects( - $this->once() - )->method( - 'get' - )->with( - $className - )->will( - $this->returnValue($methodMock) - ); - - $this->factory->create($className); - } -} diff --git a/app/code/Magento/Payment/composer.json b/app/code/Magento/Payment/composer.json index ef58fc5c09ea7..b8dbf6cd7f16f 100644 --- a/app/code/Magento/Payment/composer.json +++ b/app/code/Magento/Payment/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-config": "100.2.*", + "magento/module-config": "101.0.*", "magento/module-store": "100.2.*", - "magento/module-sales": "100.2.*", + "magento/module-sales": "101.0.*", "magento/module-checkout": "100.2.*", - "magento/module-quote": "100.2.*", + "magento/module-quote": "101.0.*", "magento/module-directory": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Payment/etc/di.xml b/app/code/Magento/Payment/etc/di.xml index e2de2244bff89..74f553cc64094 100644 --- a/app/code/Magento/Payment/etc/di.xml +++ b/app/code/Magento/Payment/etc/di.xml @@ -12,6 +12,7 @@ + @@ -36,4 +37,47 @@ Magento\Payment\Gateway\Config\Config + + + + Magento_Payment + error_mapping.xsd + + + + + Magento\Payment\Gateway\ErrorMapper\XmlToArrayConverter + Magento\Payment\Gateway\ErrorMapper\VirtualSchemaLocator + error_mapping.xml + + + + + Magento\Payment\Gateway\ErrorMapper\VirtualConfigReader + payment_error_mapper + + + + + Magento\Payment\Gateway\ErrorMapper\NullMappingData + + + + + + /var/log/payment.log + + + + + + Magento\Payment\Model\Method\VirtualDebug + + + + + + Magento\Payment\Model\Method\VirtualLogger + + diff --git a/app/code/Magento/Payment/etc/error_mapping.xsd b/app/code/Magento/Payment/etc/error_mapping.xsd new file mode 100644 index 0000000000000..97f3c181beb37 --- /dev/null +++ b/app/code/Magento/Payment/etc/error_mapping.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Payment/view/adminhtml/templates/info/substitution.phtml b/app/code/Magento/Payment/view/adminhtml/templates/info/substitution.phtml index ad24b113ffdea..582b8ca8a24be 100644 --- a/app/code/Magento/Payment/view/adminhtml/templates/info/substitution.phtml +++ b/app/code/Magento/Payment/view/adminhtml/templates/info/substitution.phtml @@ -10,6 +10,8 @@ */ ?>
      - escapeHtml($block->getMethod()->getTitle());?> + getMethod()->getTitle() + ? $block->escapeHtml($block->getMethod()->getTitle()) + : $block->escapeHtml(__('Payment method')); ?> escapeHtml(__(' is not available. You still can process offline actions.')) ?>
      diff --git a/app/code/Magento/Payment/view/frontend/templates/transparent/iframe.phtml b/app/code/Magento/Payment/view/frontend/templates/transparent/iframe.phtml index cb28c0ed69bbb..ff1234cfecc2b 100644 --- a/app/code/Magento/Payment/view/frontend/templates/transparent/iframe.phtml +++ b/app/code/Magento/Payment/view/frontend/templates/transparent/iframe.phtml @@ -44,6 +44,18 @@ $params = $block->getParams(); }); } ); + + var require = window.top.require; + require( + [ + 'jquery' + ], + function($) { + var parent = window.top; + $(parent).trigger('clearTimeout'); + $(parent.document).find('#multishipping-billing-form').submit(); + } + ); window.top.location = "escapeUrl($params['order_success']) ?>"; diff --git a/app/code/Magento/Paypal/Block/Adminhtml/Order/View.php b/app/code/Magento/Paypal/Block/Adminhtml/Order/View.php new file mode 100644 index 0000000000000..db25a7c3d9c11 --- /dev/null +++ b/app/code/Magento/Paypal/Block/Adminhtml/Order/View.php @@ -0,0 +1,111 @@ +express = $express; + + parent::__construct( + $context, + $registry, + $salesConfig, + $reorderHelper, + $data + ); + } + + /** + * Constructor + * + * @return void + * @throws LocalizedException + */ + protected function _construct() + { + parent::_construct(); + + $order = $this->getOrder(); + if (!$order) { + return; + } + $message = __('Are you sure you want to authorize full order amount?'); + if ($this->_isAllowedAction('Magento_Paypal::authorization') && $this->canAuthorize($order)) { + $this->addButton( + 'order_authorize', + [ + 'label' => __('Authorize'), + 'class' => 'authorize', + 'onclick' => "confirmSetLocation('{$message}', '{$this->getPaymentAuthorizationUrl()}')" + ] + ); + } + } + + /** + * Returns URL for authorization of full order amount. + * + * @return string + */ + private function getPaymentAuthorizationUrl(): string + { + return $this->getUrl('paypal/express/authorization'); + } + + /** + * Checks if order available for payment authorization. + * + * @param Order $order + * @return bool + * @throws LocalizedException + */ + public function canAuthorize(Order $order): bool + { + if ($order->canUnhold() || $order->isPaymentReview()) { + return false; + } + + $state = $order->getState(); + if ($order->isCanceled() || $state === Order::STATE_COMPLETE || $state === Order::STATE_CLOSED) { + return false; + } + + return $this->express->isOrderAuthorizationAllowed($order->getPayment()); + } +} diff --git a/app/code/Magento/Paypal/Controller/Adminhtml/Express/Authorization.php b/app/code/Magento/Paypal/Controller/Adminhtml/Express/Authorization.php new file mode 100644 index 0000000000000..a4b44adabfaef --- /dev/null +++ b/app/code/Magento/Paypal/Controller/Adminhtml/Express/Authorization.php @@ -0,0 +1,115 @@ +express = $express; + + parent::__construct( + $context, + $coreRegistry, + $fileFactory, + $translateInline, + $resultPageFactory, + $resultJsonFactory, + $resultLayoutFactory, + $resultRawFactory, + $orderManagement, + $orderRepository, + $logger + ); + } + + /** + * Authorize full order payment amount. + * + * @return Redirect + */ + public function execute(): Redirect + { + $resultRedirect = $this->resultRedirectFactory->create(); + if ($order = $this->_initOrder()) { + try { + $this->express->authorizeOrder($order); + $this->orderRepository->save($order); + $this->messageManager->addSuccessMessage(__('Payment authorization has been successfully created.')); + } catch (LocalizedException $e) { + $this->messageManager->addErrorMessage($e->getMessage()); + } catch (\Exception $e) { + $this->messageManager->addErrorMessage(__('Unable to make payment authorization.')); + } + + $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); + } else { + $resultRedirect->setPath('sales/order/index'); + } + + return $resultRedirect; + } +} diff --git a/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php b/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php index 1222679593f36..16b2e761c1722 100644 --- a/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php +++ b/app/code/Magento/Paypal/Controller/Express/AbstractExpress/PlaceOrder.php @@ -6,6 +6,7 @@ */ namespace Magento\Paypal\Controller\Express\AbstractExpress; +use Magento\Framework\Exception\LocalizedException; use Magento\Paypal\Model\Api\ProcessableException as ApiProcessableException; /** @@ -114,15 +115,27 @@ public function execute() return; } catch (ApiProcessableException $e) { $this->_processPaypalApiError($e); + } catch (LocalizedException $e) { + $this->processException($e, $e->getRawMessage()); } catch (\Exception $e) { - $this->messageManager->addExceptionMessage( - $e, - __('We can\'t place the order.') - ); - $this->_redirect('*/*/review'); + $this->processException($e, 'We can\'t place the order.'); } } + /** + * Process exception. + * + * @param \Exception $exception + * @param string $message + * + * @return void + */ + private function processException(\Exception $exception, string $message) + { + $this->messageManager->addExceptionMessage($exception, __($message)); + $this->_redirect('*/*/review'); + } + /** * Process PayPal API's processable errors * diff --git a/app/code/Magento/Paypal/Model/Adminhtml/Express.php b/app/code/Magento/Paypal/Model/Adminhtml/Express.php new file mode 100644 index 0000000000000..0881e72abbed0 --- /dev/null +++ b/app/code/Magento/Paypal/Model/Adminhtml/Express.php @@ -0,0 +1,178 @@ +authCommand = $authCommand; + + parent::__construct( + $context, + $registry, + $extensionFactory, + $customAttributeFactory, + $paymentData, + $scopeConfig, + $logger, + $proFactory, + $storeManager, + $urlBuilder, + $cartFactory, + $checkoutSession, + $exception, + $transactionRepository, + $transactionBuilder, + $resource, + $resourceCollection, + $data + ); + } + + /** + * Creates an authorization of requested amount. + * + * @param OrderInterface $order + * @return $this + * @throws LocalizedException + */ + public function authorizeOrder(OrderInterface $order) + { + $baseTotalDue = $order->getBaseTotalDue(); + + /** @var $payment Payment */ + $payment = $order->getPayment(); + if (!$payment || !$this->isOrderAuthorizationAllowed($payment)) { + throw new LocalizedException(__('Authorization is not allowed.')); + } + + $orderTransaction = $this->getOrderTransaction($payment); + + $api = $this->_callDoAuthorize($baseTotalDue, $payment, $orderTransaction->getTxnId()); + $this->_pro->importPaymentInfo($api, $payment); + + $payment->resetTransactionAdditionalInfo() + ->setIsTransactionClosed(false) + ->setTransactionId($api->getTransactionId()) + ->setParentTransactionId($orderTransaction->getTxnId()); + + $transaction = $payment->addTransaction(Transaction::TYPE_AUTH, null, true); + $message = $this->authCommand->execute($payment, $baseTotalDue, $payment->getOrder()); + $message = $payment->prependMessage($message); + + $payment->addTransactionCommentsToOrder($transaction, $message); + $payment->setAmountAuthorized($order->getTotalDue()); + $payment->setBaseAmountAuthorized($baseTotalDue); + + return $this; + } + + /** + * Checks if payment has authorization transactions. + * + * @param Payment $payment + * @return bool + */ + private function hasAuthorization(Payment $payment): bool + { + return (bool) ($payment->getAmountAuthorized() ?? 0); + } + + /** + * Checks if payment authorization allowed + * + * @param Payment $payment + * @return bool + * @throws LocalizedException + */ + public function isOrderAuthorizationAllowed(Payment $payment): bool + { + if ($payment->getMethod() === Config::METHOD_EXPRESS && + $payment->getMethodInstance()->getConfigPaymentAction() === AbstractMethod::ACTION_ORDER) { + return !$this->hasAuthorization($payment); + } + + return false; + } +} diff --git a/app/code/Magento/Paypal/Model/Config.php b/app/code/Magento/Paypal/Model/Config.php index acb0444d50803..08b646a661898 100644 --- a/app/code/Magento/Paypal/Model/Config.php +++ b/app/code/Magento/Paypal/Model/Config.php @@ -226,6 +226,7 @@ class Config extends AbstractConfig 'TWD', 'THB', 'USD', + 'INR', ]; /** diff --git a/app/code/Magento/Paypal/Model/Express.php b/app/code/Magento/Paypal/Model/Express.php index 8ba8adcede511..4684abdc9be6d 100644 --- a/app/code/Magento/Paypal/Model/Express.php +++ b/app/code/Magento/Paypal/Model/Express.php @@ -10,6 +10,7 @@ use Magento\Paypal\Model\Express\Checkout as ExpressCheckout; use Magento\Quote\Api\Data\PaymentInterface; use Magento\Sales\Api\Data\OrderPaymentInterface; +use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Payment; use Magento\Sales\Model\Order\Payment\Transaction; use Magento\Quote\Model\Quote; @@ -363,7 +364,6 @@ public function getConfigData($field, $storeId = null) * @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface|Payment $payment * @param float $amount * @return $this - * @throws \Magento\Framework\Exception\LocalizedException */ public function order(\Magento\Payment\Model\InfoInterface $payment, $amount) { @@ -375,63 +375,12 @@ public function order(\Magento\Payment\Model\InfoInterface $payment, $amount) } $payment->setAdditionalInformation($this->_isOrderPaymentActionKey, true); - if ($payment->getIsFraudDetected()) { return $this; } - $order = $payment->getOrder(); - $orderTransactionId = $payment->getTransactionId(); - - $api = $this->_callDoAuthorize($amount, $payment, $orderTransactionId); - - $state = \Magento\Sales\Model\Order::STATE_PROCESSING; - $status = true; - - $formattedPrice = $order->getBaseCurrency()->formatTxt($amount); - if ($payment->getIsTransactionPending()) { - $message = __('The ordering amount of %1 is pending approval on the payment gateway.', $formattedPrice); - $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW; - } else { - $message = __('Ordered amount of %1', $formattedPrice); - } - - $transaction = $this->transactionBuilder->setPayment($payment) - ->setOrder($order) - ->setTransactionId($payment->getTransactionId()) - ->build(Transaction::TYPE_ORDER); - $payment->addTransactionCommentsToOrder($transaction, $message); + $payment->getOrder()->setActionFlag(Order::ACTION_FLAG_INVOICE, false); - $this->_pro->importPaymentInfo($api, $payment); - - if ($payment->getIsTransactionPending()) { - $message = __( - 'We\'ll authorize the amount of %1 as soon as the payment gateway approves it.', - $formattedPrice - ); - $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW; - if ($payment->getIsFraudDetected()) { - $status = \Magento\Sales\Model\Order::STATUS_FRAUD; - } - } else { - $message = __('The authorized amount is %1.', $formattedPrice); - } - - $payment->resetTransactionAdditionalInfo(); - - $payment->setTransactionId($api->getTransactionId()); - $payment->setParentTransactionId($orderTransactionId); - - $transaction = $this->transactionBuilder->setPayment($payment) - ->setOrder($order) - ->setTransactionId($payment->getTransactionId()) - ->build(Transaction::TYPE_AUTH); - $payment->addTransactionCommentsToOrder($transaction, $message); - - $order->setState($state) - ->setStatus($status); - - $payment->setSkipOrderProcessing(true); return $this; } @@ -669,7 +618,7 @@ public function getApi() public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); - + $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA); if (!is_array($additionalData)) { @@ -677,6 +626,11 @@ public function assignData(\Magento\Framework\DataObject $data) } foreach ($additionalData as $key => $value) { + // Skip extension attributes + if ($key === \Magento\Framework\Api\ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY) { + continue; + } + $this->getInfoInstance()->setAdditionalInformation($key, $value); } return $this; diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index e9f2c1b8415a8..649c653ef1a65 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -897,7 +897,12 @@ protected function _setExportedAddressData($address, $exportedAddress) { // Exported data is more priority if we came from Express Checkout button $isButton = (bool)$this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON); - if (!$isButton) { + + // Since country is required field for billing and shipping address, + // we consider the address information to be empty if country is empty. + $isEmptyAddress = ($address->getCountryId() === null); + + if (!$isButton && !$isEmptyAddress) { return; } diff --git a/app/code/Magento/Paypal/Model/InstantPurchase/Payflow/Pro/TokenFormatter.php b/app/code/Magento/Paypal/Model/InstantPurchase/Payflow/Pro/TokenFormatter.php new file mode 100644 index 0000000000000..8fea23317098b --- /dev/null +++ b/app/code/Magento/Paypal/Model/InstantPurchase/Payflow/Pro/TokenFormatter.php @@ -0,0 +1,59 @@ + 'American Express', + 'VI' => 'Visa', + 'MC' => 'MasterCard', + 'DI' => 'Discover', + 'JBC' => 'JBC', + 'CUP' => 'China Union Pay', + 'MI' => 'Maestro', + ]; + + /** + * @inheritdoc + */ + public function formatPaymentToken(PaymentTokenInterface $paymentToken): string + { + $details = json_decode($paymentToken->getTokenDetails() ?: '{}', true); + if (!isset($details['cc_type'], $details['cc_last_4'], $details['cc_exp_month'], $details['cc_exp_year'])) { + throw new \InvalidArgumentException('Invalid PayPal Payflow Pro credit card token details.'); + } + + if (isset(self::$baseCardTypes[$details['cc_type']])) { + $ccType = self::$baseCardTypes[$details['cc_type']]; + } else { + $ccType = $details['cc_type']; + } + + $formatted = sprintf( + '%s: %s, %s: %s (%s: %02d/%04d)', + __('Credit Card'), + $ccType, + __('ending'), + $details['cc_last_4'], + __('expires'), + $details['cc_exp_month'], + $details['cc_exp_year'] + ); + + return $formatted; + } +} diff --git a/app/code/Magento/Paypal/Model/Ipn.php b/app/code/Magento/Paypal/Model/Ipn.php index aa019ce276d3b..cd4e4bbf78e4f 100644 --- a/app/code/Magento/Paypal/Model/Ipn.php +++ b/app/code/Magento/Paypal/Model/Ipn.php @@ -370,9 +370,7 @@ public function _registerPaymentPending() $this->_registerPaymentAuthorization(); return; } - if ('order' === $reason) { - throw new Exception('The "order" authorizations are not implemented.'); - } + // case when was placed using PayPal standard if (\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT == $this->_order->getState() && !$this->getRequestData('transaction_entity') diff --git a/app/code/Magento/Paypal/Model/Pro.php b/app/code/Magento/Paypal/Model/Pro.php index 1bb6c48f6ba94..698ed87f26c09 100644 --- a/app/code/Magento/Paypal/Model/Pro.php +++ b/app/code/Magento/Paypal/Model/Pro.php @@ -258,7 +258,7 @@ public function capture(\Magento\Framework\DataObject $payment, $amount) } $api = $this->getApi() ->setAuthorizationId($authTransactionId) - ->setIsCaptureComplete($payment->getShouldCloseParentTransaction()) + ->setIsCaptureComplete($payment->isCaptureFinal($amount)) ->setAmount($amount); $order = $payment->getOrder(); diff --git a/app/code/Magento/Paypal/Model/Report/Settlement.php b/app/code/Magento/Paypal/Model/Report/Settlement.php index cca58e1770791..79d473633c611 100644 --- a/app/code/Magento/Paypal/Model/Report/Settlement.php +++ b/app/code/Magento/Paypal/Model/Report/Settlement.php @@ -376,7 +376,8 @@ public function parseCsv($localCsv, $format = 'new') // Section columns. // In case ever the column order is changed, we will have the items recorded properly // anyway. We have named, not numbered columns. - for ($i = 1; $i < count($line); $i++) { + $count = count($line); + for ($i = 1; $i < $count; $i++) { $sectionColumns[$line[$i]] = $i; } $flippedSectionColumns = array_flip($sectionColumns); diff --git a/app/code/Magento/Paypal/Model/ResourceModel/Report/Settlement.php b/app/code/Magento/Paypal/Model/ResourceModel/Report/Settlement.php index 0796c22db98bf..d4019c6c4a7e0 100644 --- a/app/code/Magento/Paypal/Model/ResourceModel/Report/Settlement.php +++ b/app/code/Magento/Paypal/Model/ResourceModel/Report/Settlement.php @@ -90,7 +90,7 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) } $connection->commit(); } catch (\Exception $e) { - $connection->rollback(); + $connection->rollBack(); } } diff --git a/app/code/Magento/Paypal/Plugin/OrderCanInvoice.php b/app/code/Magento/Paypal/Plugin/OrderCanInvoice.php new file mode 100644 index 0000000000000..8393b756be364 --- /dev/null +++ b/app/code/Magento/Paypal/Plugin/OrderCanInvoice.php @@ -0,0 +1,47 @@ +express = $express; + } + + /** + * Checks a possibility to invoice of PayPal Express payments when payment action is "order". + * + * @param Order $order + * @param $result + * @return bool + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function afterCanInvoice(Order $order, $result): bool + { + if ($this->express->isOrderAuthorizationAllowed($order->getPayment())) { + return false; + } + + return $result; + } +} diff --git a/app/code/Magento/Paypal/Plugin/ValidatorCanInvoice.php b/app/code/Magento/Paypal/Plugin/ValidatorCanInvoice.php new file mode 100644 index 0000000000000..520c3d92beb3b --- /dev/null +++ b/app/code/Magento/Paypal/Plugin/ValidatorCanInvoice.php @@ -0,0 +1,52 @@ +express = $express; + } + + /** + * Checks a possibility to invoice of PayPal Express payments when payment action is "order". + * + * @param CanInvoice $subject + * @param $result + * @param OrderInterface $order + * @return array + * @throws LocalizedException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterValidate(CanInvoice $subject, $result, OrderInterface $order): array + { + if ($this->express->isOrderAuthorizationAllowed($order->getPayment())) { + $result[] = __('An invoice cannot be created when none of authorization transactions available.'); + } + + return $result; + } +} diff --git a/app/code/Magento/Paypal/Test/Unit/Block/Adminhtml/Order/ViewTest.php b/app/code/Magento/Paypal/Test/Unit/Block/Adminhtml/Order/ViewTest.php new file mode 100644 index 0000000000000..1341fa62a6d3d --- /dev/null +++ b/app/code/Magento/Paypal/Test/Unit/Block/Adminhtml/Order/ViewTest.php @@ -0,0 +1,123 @@ +order = $this->createPartialMock( + Order::class, + ['canUnhold', 'isPaymentReview', 'getState', 'isCanceled', 'getPayment'] + ); + + $this->express = $this->createPartialMock( + Express::class, + ['isOrderAuthorizationAllowed'] + ); + + $this->payment = $this->createMock(Payment::class); + + $this->view = $objectManager->getObject( + View::class, + [ + 'express' => $this->express, + 'data' => [] + ] + ); + } + + /** + * Tests if authorization action is allowed for order. + * + * @param bool $canUnhold + * @param bool $isPaymentReview + * @param bool $isCanceled + * @param bool $authAllowed + * @param string $orderState + * @param bool $canAuthorize + * @throws LocalizedException + * @dataProvider orderDataProvider + */ + public function testIsOrderAuthorizationAllowed( + $canUnhold, + $isPaymentReview, + $isCanceled, + $authAllowed, + $orderState, + $canAuthorize + ) { + $this->order->method('canUnhold') + ->willReturn($canUnhold); + + $this->order->method('isPaymentReview') + ->willReturn($isPaymentReview); + + $this->order->method('isCanceled') + ->willReturn($isCanceled); + + $this->order->method('getState') + ->willReturn($orderState); + + $this->order->method('getPayment') + ->willReturn($this->payment); + + $this->express->method('isOrderAuthorizationAllowed') + ->with($this->payment) + ->willReturn($authAllowed); + + $this->assertEquals($canAuthorize, $this->view->canAuthorize($this->order)); + } + + /** + * Data provider for order methods call. + * + * @return array + */ + public function orderDataProvider(): array + { + return [ + [true, false, false, true, Order::STATE_PROCESSING, false], + [false, true, false, true, Order::STATE_PROCESSING, false], + [false, false, true, true, Order::STATE_PROCESSING, false], + [false, false, false, false, Order::STATE_PROCESSING, false], + [false, false, false, true, Order::STATE_COMPLETE, false], + [false, false, false, true, Order::STATE_CLOSED, false], + [false, false, false, true, Order::STATE_PROCESSING, true], + ]; + } +} diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Adminhtml/ExpressTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Adminhtml/ExpressTest.php new file mode 100644 index 0000000000000..27eb4ffeca699 --- /dev/null +++ b/app/code/Magento/Paypal/Test/Unit/Model/Adminhtml/ExpressTest.php @@ -0,0 +1,209 @@ +nvp = $this->createPartialMock( + Nvp::class, + ['getData','setProcessableErrors', 'callDoAuthorization'] + ); + $this->nvp->method('getData')->willReturn([]); + $this->nvp->method('setProcessableErrors')->willReturnSelf(); + + $this->pro = $this->createPartialMock( + Pro::class, + ['setMethod', 'getApi', 'importPaymentInfo'] + ); + $this->pro->method('getApi')->willReturn($this->nvp); + + $this->transaction = $this->getMockForAbstractClass(TransactionInterface::class); + $this->transactionRepository = $this->createPartialMock( + TransactionRepository::class, + ['getByTransactionType'] + ); + $this->transactionRepository->method('getByTransactionType')->willReturn($this->transaction); + + $this->express = $objectManager->getObject( + Express::class, + [ + 'data' => [$this->pro], + 'transactionRepository' => $this->transactionRepository + ] + ); + + $this->paymentInstance = $this->getMockForAbstractClass(MethodInterface::class); + $this->payment = $this->createPartialMock( + Payment::class, + [ + 'getAmountAuthorized', + 'getMethod', + 'getMethodInstance', + 'getId', + 'getOrder', + 'addTransaction', + 'addTransactionCommentsToOrder', + 'setAmountAuthorized' + ] + ); + $this->payment->method('getMethodInstance') + ->willReturn($this->paymentInstance); + + $this->payment->method('addTransaction') + ->willReturn($this->transaction); + } + + /** + * Tests payment authorization flow for order. + * + * @throws LocalizedException + */ + public function testAuthorizeOrder() + { + $this->order = $this->createPartialMock( + Order::class, + ['getId', 'getPayment', 'getTotalDue', 'getBaseTotalDue'] + ); + $this->order->method('getPayment') + ->willReturn($this->payment); + $this->order->method('getId') + ->willReturn(1); + + $totalDue = 15; + $baseTotalDue = 10; + + $this->order->method('getTotalDue') + ->willReturn($totalDue); + $this->order->method('getBaseTotalDue') + ->willReturn($baseTotalDue); + + $this->payment->method('getMethod') + ->willReturn('paypal_express'); + $this->payment->method('getId') + ->willReturn(1); + $this->payment->method('getOrder') + ->willReturn($this->order); + $this->payment->method('getAmountAuthorized') + ->willReturn(0); + + $this->paymentInstance->method('getConfigPaymentAction') + ->willReturn('order'); + + $this->nvp->expects(static::once()) + ->method('callDoAuthorization') + ->willReturnSelf(); + + $this->payment->expects(static::once()) + ->method('addTransaction') + ->with(Transaction::TYPE_AUTH) + ->willReturn($this->transaction); + + $this->payment->method('addTransactionCommentsToOrder') + ->with($this->transaction); + + $this->payment->method('setAmountAuthorized') + ->with($totalDue); + + $this->express->authorizeOrder($this->order); + } + + /** + * Checks if payment authorization is allowed. + * + * @param string $method + * @param string $action + * @param float $authorizedAmount + * @param bool $isAuthAllowed + * @throws LocalizedException + * @dataProvider paymentDataProvider + */ + public function testIsOrderAuthorizationAllowed($method, $action, $authorizedAmount, $isAuthAllowed) + { + $this->payment->method('getMethod') + ->willReturn($method); + + $this->paymentInstance->method('getConfigPaymentAction') + ->willReturn($action); + + $this->payment->method('getAmountAuthorized') + ->willReturn($authorizedAmount); + + static::assertEquals($isAuthAllowed, $this->express->isOrderAuthorizationAllowed($this->payment)); + } + + /** + * Data provider for payment methods call. + * + * @return array + */ + public function paymentDataProvider(): array + { + return [ + ['paypal_express', 'sale', 10, false], + ['paypal_express', 'order', 50, false], + ['paypal_express', 'capture', 0, false], + ['paypal_express', 'order', 0, true], + ['braintree', 'authorize', 10, false], + ['braintree', 'authorize', 0, false] + ]; + } +} diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php index 8b270fe24ab15..c0b2bb4fc1dca 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php @@ -126,7 +126,8 @@ protected function _invokeNvpProperty(\Magento\Paypal\Model\Api\Nvp $nvpObject, public function testCall($response, $processableErrors, $exception, $exceptionMessage = '', $exceptionCode = null) { if (isset($exception)) { - $this->expectException($exception, $exceptionMessage, $exceptionCode); + $this->expectException($exception); + $this->expectExceptionMessage($exceptionMessage, $exceptionCode); } $this->curl->expects($this->once()) ->method('read') diff --git a/app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php b/app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php index 6a2d33d010190..2575408078926 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php @@ -5,13 +5,21 @@ */ namespace Magento\Paypal\Test\Unit\Model; +use Magento\Checkout\Model\Session; use Magento\Framework\DataObject; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Payment\Model\InfoInterface; use Magento\Payment\Observer\AbstractDataAssignObserver; +use Magento\Paypal\Model\Api\Nvp; use Magento\Paypal\Model\Api\ProcessableException as ApiProcessableException; use Magento\Paypal\Model\Express; +use Magento\Paypal\Model\Pro; use Magento\Quote\Api\Data\PaymentInterface; +use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Payment; +use Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface; +use \PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Class ExpressTest @@ -38,151 +46,157 @@ class ExpressTest extends \PHPUnit\Framework\TestCase /** * @var Express */ - protected $_model; + private $model; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var Session|MockObject */ - protected $_checkoutSession; + private $checkoutSession; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var Pro|MockObject */ - protected $_pro; + private $pro; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var Nvp|MockObject */ - protected $_nvp; + private $nvp; /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @var ObjectManager */ - protected $_helper; + private $helper; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var BuilderInterface|MockObject */ - protected $transactionBuilder; + private $transactionBuilder; /** - * @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ManagerInterface|MockObject */ - private $eventManagerMock; + private $eventManager; protected function setUp() { - $this->_checkoutSession = $this->createPartialMock( - \Magento\Checkout\Model\Session::class, + $this->checkoutSession = $this->createPartialMock( + Session::class, ['getPaypalTransactionData', 'setPaypalTransactionData'] ); $this->transactionBuilder = $this->getMockForAbstractClass( - \Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface::class, + BuilderInterface::class, [], '', false, false ); - $this->_nvp = $this->createPartialMock( - \Magento\Paypal\Model\Api\Nvp::class, - ['setProcessableErrors', 'setAmount', 'setCurrencyCode', 'setTransactionId', 'callDoAuthorization'] + $this->nvp = $this->createPartialMock( + Nvp::class, + [ + 'setProcessableErrors', + 'setAmount', + 'setCurrencyCode', + 'setTransactionId', + 'callDoAuthorization', + 'setData' + ] ); - $this->_pro = $this->createPartialMock( - \Magento\Paypal\Model\Pro::class, + $this->pro = $this->createPartialMock( + Pro::class, ['setMethod', 'getApi', 'importPaymentInfo', 'resetApi'] ); - $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class) + $this->eventManager = $this->getMockBuilder(ManagerInterface::class) ->setMethods(['dispatch']) ->getMockForAbstractClass(); - $this->_pro->expects($this->any())->method('getApi')->will($this->returnValue($this->_nvp)); - $this->_helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->pro->expects($this->any())->method('getApi')->will($this->returnValue($this->nvp)); + $this->helper = new ObjectManager($this); } public function testSetApiProcessableErrors() { - $this->_nvp->expects($this->once())->method('setProcessableErrors')->with($this->errorCodes); + $this->nvp->expects($this->once())->method('setProcessableErrors')->with($this->errorCodes); - $this->_model = $this->_helper->getObject( + $this->model = $this->helper->getObject( \Magento\Paypal\Model\Express::class, [ - 'data' => [$this->_pro], - 'checkoutSession' => $this->_checkoutSession, + 'data' => [$this->pro], + 'checkoutSession' => $this->checkoutSession, 'transactionBuilder' => $this->transactionBuilder ] ); } + /** + * Tests order payment action. + */ public function testOrder() { - $this->_nvp->expects($this->any())->method('setProcessableErrors')->will($this->returnSelf()); - $this->_nvp->expects($this->any())->method('setAmount')->will($this->returnSelf()); - $this->_nvp->expects($this->any())->method('setCurrencyCode')->will($this->returnSelf()); - $this->_nvp->expects($this->any())->method('setTransactionId')->will($this->returnSelf()); - $this->_nvp->expects($this->any())->method('callDoAuthorization')->will($this->returnSelf()); - - $this->_checkoutSession->expects($this->once())->method('getPaypalTransactionData')->will( - $this->returnValue([]) - ); - $this->_checkoutSession->expects($this->once())->method('setPaypalTransactionData')->with([]); - - $currency = $this->createPartialMock(\Magento\Directory\Model\Currency::class, ['__wakeup', 'formatTxt']); - $paymentModel = $this->createPartialMock(\Magento\Sales\Model\Order\Payment::class, [ - '__wakeup', - 'getBaseCurrency', - 'getOrder', - 'getIsTransactionPending', - 'addStatusHistoryComment', - 'addTransactionCommentsToOrder' - ]); - $order = $this->createPartialMock( - \Magento\Sales\Model\Order::class, - ['setState', 'getBaseCurrency', 'getBaseCurrencyCode', 'setStatus'] - ); - $paymentModel->expects($this->any())->method('getOrder')->willReturn($order); - $order->expects($this->any())->method('getBaseCurrency')->willReturn($currency); - $order->expects($this->any())->method('setState')->with('payment_review')->willReturnSelf(); - $paymentModel->expects($this->any())->method('getIsTransactionPending')->will($this->returnSelf()); - $this->transactionBuilder->expects($this->any())->method('setOrder')->with($order)->will($this->returnSelf()); - $this->transactionBuilder->expects($this->any())->method('setPayment')->will($this->returnSelf()); - $this->transactionBuilder->expects($this->any())->method('setTransactionId')->will($this->returnSelf()); - $this->_model = $this->_helper->getObject( + $transactionData = ['TOKEN' => 'EC-7NJ4634216284232D']; + $this->checkoutSession + ->method('getPaypalTransactionData') + ->willReturn($transactionData); + + $order = $this->createPartialMock(Order::class, ['setActionFlag']); + $order->method('setActionFlag') + ->with(Order::ACTION_FLAG_INVOICE, false) + ->willReturnSelf(); + + $paymentModel = $this->createPartialMock(Payment::class, ['getOrder']); + $paymentModel->method('getOrder') + ->willReturn($order); + + $this->model = $this->helper->getObject( \Magento\Paypal\Model\Express::class, [ - 'data' => [$this->_pro], - 'checkoutSession' => $this->_checkoutSession, - 'transactionBuilder' => $this->transactionBuilder + 'data' => [$this->pro], + 'checkoutSession' => $this->checkoutSession ] ); - $this->assertEquals($this->_model, $this->_model->order($paymentModel, 12.3)); + + $this->nvp->method('setData') + ->with($transactionData) + ->willReturnSelf(); + + static::assertEquals($this->model, $this->model->order($paymentModel, 12.3)); } public function testAssignData() { $transportValue = 'something'; + $extensionAttribute = $this->getMockForAbstractClass( + \Magento\Quote\Api\Data\PaymentExtensionInterface::class, + [], + '', + false, + false + ); + $data = new DataObject( [ PaymentInterface::KEY_ADDITIONAL_DATA => [ Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => $transportValue, Express\Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID => $transportValue, - Express\Checkout::PAYMENT_INFO_TRANSPORT_TOKEN => $transportValue + Express\Checkout::PAYMENT_INFO_TRANSPORT_TOKEN => $transportValue, + \Magento\Framework\Api\ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttribute ] ] ); - $this->_model = $this->_helper->getObject( + $this->model = $this->helper->getObject( \Magento\Paypal\Model\Express::class, [ - 'data' => [$this->_pro], - 'checkoutSession' => $this->_checkoutSession, + 'data' => [$this->pro], + 'checkoutSession' => $this->checkoutSession, 'transactionBuilder' => $this->transactionBuilder, - 'eventDispatcher' => $this->eventManagerMock, + 'eventDispatcher' => $this->eventManager, ] ); $paymentInfo = $this->createMock(InfoInterface::class); - $this->_model->setInfoInstance($paymentInfo); + $this->model->setInfoInstance($paymentInfo); $this->parentAssignDataExpectation($data); @@ -194,7 +208,7 @@ public function testAssignData() [Express\Checkout::PAYMENT_INFO_TRANSPORT_TOKEN, $transportValue] ); - $this->_model->assignData($data); + $this->model->assignData($data); } /** @@ -204,16 +218,16 @@ private function parentAssignDataExpectation(DataObject $data) { $eventData = [ AbstractDataAssignObserver::METHOD_CODE => $this, - AbstractDataAssignObserver::MODEL_CODE => $this->_model->getInfoInstance(), + AbstractDataAssignObserver::MODEL_CODE => $this->model->getInfoInstance(), AbstractDataAssignObserver::DATA_CODE => $data ]; - $this->eventManagerMock->expects(static::exactly(2)) + $this->eventManager->expects(static::exactly(2)) ->method('dispatch') ->willReturnMap( [ [ - 'payment_method_assign_data_' . $this->_model->getCode(), + 'payment_method_assign_data_' . $this->model->getCode(), $eventData ], [ diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/TransactionTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/TransactionTest.php index f5c9ab9a3d9f1..93a1072782448 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/TransactionTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/TransactionTest.php @@ -67,7 +67,7 @@ public function gatewayResponseInvariants() { return [ "Input data is a string" => ['testInput'], - "Input data is an object" => [new \StdClass], + "Input data is an object" => [new \stdClass], "Input data is an array" => [['test' => 'input']] ]; } diff --git a/app/code/Magento/Paypal/Test/Unit/Model/ProTest.php b/app/code/Magento/Paypal/Test/Unit/Model/ProTest.php index 9cf32b99ff510..e1bf204973a8e 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/ProTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/ProTest.php @@ -120,6 +120,9 @@ public function testCapture() ->method('getOrder') ->willReturn($orderMock); + $paymentMock->method('isCaptureFinal') + ->willReturn(true); + $this->apiMock->expects(static::once()) ->method('getTransactionId') ->willReturn(45); @@ -228,16 +231,14 @@ protected function getPaymentMock() $paymentMock = $this->getMockBuilder(\Magento\Payment\Model\Info::class) ->disableOriginalConstructor() ->setMethods([ - 'getParentTransactionId', 'getOrder', 'getShouldCloseParentTransaction' + 'getParentTransactionId', 'getOrder', 'getShouldCloseParentTransaction', 'isCaptureFinal' ]) ->getMock(); $parentTransactionId = 43; $paymentMock->expects(static::once()) ->method('getParentTransactionId') ->willReturn($parentTransactionId); - $paymentMock->expects(static::once()) - ->method('getShouldCloseParentTransaction') - ->willReturn(true); + return $paymentMock; } diff --git a/app/code/Magento/Paypal/composer.json b/app/code/Magento/Paypal/composer.json index c525fb9293898..8aec470cb65ac 100644 --- a/app/code/Magento/Paypal/composer.json +++ b/app/code/Magento/Paypal/composer.json @@ -3,29 +3,30 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-config": "100.2.*", + "magento/module-config": "101.0.*", "magento/module-store": "100.2.*", "magento/module-checkout": "100.2.*", - "magento/module-sales": "100.2.*", - "magento/module-quote": "100.2.*", - "magento/module-customer": "100.2.*", + "magento/module-sales": "101.0.*", + "magento/module-quote": "101.0.*", + "magento/module-customer": "101.0.*", "magento/module-payment": "100.2.*", "magento/module-backend": "100.2.*", "magento/module-tax": "100.2.*", "magento/module-directory": "100.2.*", "magento/module-theme": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-eav": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-ui": "100.2.*", - "magento/module-vault": "100.2.*", + "magento/module-catalog": "102.0.*", + "magento/module-eav": "101.0.*", + "magento/framework": "101.0.*", + "magento/module-ui": "101.0.*", + "magento/module-vault": "101.0.*", + "magento/module-instant-purchase": "100.2.*", "lib-libxml": "*" }, "suggest": { "magento/module-checkout-agreements": "100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "proprietary" ], diff --git a/app/code/Magento/Paypal/etc/acl.xml b/app/code/Magento/Paypal/etc/acl.xml index 0344af13519e5..4373ebc4c12bf 100644 --- a/app/code/Magento/Paypal/etc/acl.xml +++ b/app/code/Magento/Paypal/etc/acl.xml @@ -33,6 +33,11 @@ + + + + + diff --git a/app/code/Magento/Paypal/etc/config.xml b/app/code/Magento/Paypal/etc/config.xml index c70a8840eb578..f0df648af9072 100644 --- a/app/code/Magento/Paypal/etc/config.xml +++ b/app/code/Magento/Paypal/etc/config.xml @@ -95,8 +95,11 @@ Magento\Paypal\Model\Payflow\CvvEmsCodeMapper - PayflowProCreditCardVaultFacade - Stored Cards (Payflow Pro) + PayflowProCreditCardVaultFacade + Stored Cards (Payflow Pro) + + \Magento\Paypal\Model\InstantPurchase\Payflow\Pro\TokenFormatter + 1 diff --git a/app/code/Magento/Paypal/etc/di.xml b/app/code/Magento/Paypal/etc/di.xml index 3071907af4717..c0141bbb3215e 100644 --- a/app/code/Magento/Paypal/etc/di.xml +++ b/app/code/Magento/Paypal/etc/di.xml @@ -67,6 +67,12 @@ + + + + + + Magento\Paypal\Model\Config::METHOD_WPP_PE_EXPRESS diff --git a/app/code/Magento/Paypal/i18n/en_US.csv b/app/code/Magento/Paypal/i18n/en_US.csv index 164feea71511f..797edbf8bfa1e 100644 --- a/app/code/Magento/Paypal/i18n/en_US.csv +++ b/app/code/Magento/Paypal/i18n/en_US.csv @@ -367,7 +367,7 @@ expires,expires here,here " to learn more."," to learn more." "Important: ","Important: " -"To use PayPal Payments Advanced, you must configure your PayPal Payments Advanced account on the PayPal website.","To use PayPal Payments Advanced, you must configure your PayPal Payments Advanced account on the PayPal website." +"To use PayPal Payments Advanced, you must configure your PayPal Payments Advanced account on the PayPal website.","To use PayPal Payments Advanced, you must configure your PayPal Payments Advanced account on the PayPal website." "Once you log into your PayPal Advanced account, navigate to the Service Settings - Hosted Checkout Pages - Set Up menu and set the options described below","Once you log into your PayPal Advanced account, navigate to the Service Settings - Hosted Checkout Pages - Set Up menu and set the options described below" "To use PayPal Payflow Link, you must configure your PayPal Payflow Link account on the PayPal website.","To use PayPal Payflow Link, you must configure your PayPal Payflow Link account on the PayPal website." "Once you log into your PayPal Payflow Link account, navigate to the Service Settings - Hosted Checkout Pages - Set Up menu and set the options described below","Once you log into your PayPal Payflow Link account, navigate to the Service Settings - Hosted Checkout Pages - Set Up menu and set the options described below" diff --git a/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_paypal_reports_block.xml b/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_paypal_reports_block.xml index 49bc4c48ed416..12dcc46e3ecee 100644 --- a/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_paypal_reports_block.xml +++ b/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_paypal_reports_block.xml @@ -27,7 +27,7 @@ - + Report Date report_date @@ -36,7 +36,7 @@ col-date - + Merchant Account account_id @@ -44,7 +44,7 @@ col-merchant - + Transaction ID transaction_id @@ -52,7 +52,7 @@ col-transaction - + Invoice ID invoice_id @@ -60,7 +60,7 @@ col-invoice - + PayPal Reference ID paypal_reference_id @@ -68,7 +68,7 @@ col-reference - + Event transaction_event_code @@ -78,7 +78,7 @@ ol-event - + Start Date transaction_initiation_date @@ -87,7 +87,7 @@ col-initiation - + Finish Date transaction_completion_date @@ -96,7 +96,7 @@ col-completion - + Gross Amount gross_transaction_amount @@ -106,7 +106,7 @@ col-amount - + Fee Amount fee_amount diff --git a/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_system_config_edit.xml b/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_system_config_edit.xml index c84c9290dd1d5..3f1abb95b8fa7 100644 --- a/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_system_config_edit.xml +++ b/app/code/Magento/Paypal/view/adminhtml/layout/adminhtml_system_config_edit.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_view.xml b/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_view.xml new file mode 100644 index 0000000000000..3c11109b7fd63 --- /dev/null +++ b/app/code/Magento/Paypal/view/adminhtml/layout/sales_order_view.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/Paypal/view/adminhtml/templates/system/config/payflowlink/advanced.phtml b/app/code/Magento/Paypal/view/adminhtml/templates/system/config/payflowlink/advanced.phtml index 2339b9ca38534..127d5bd14db42 100644 --- a/app/code/Magento/Paypal/view/adminhtml/templates/system/config/payflowlink/advanced.phtml +++ b/app/code/Magento/Paypal/view/adminhtml/templates/system/config/payflowlink/advanced.phtml @@ -12,7 +12,7 @@

      escapeHtml(__('Important: ')) ?> - escapeHtml(__('To use PayPal Payments Advanced, you must configure your PayPal Payments Advanced account on the PayPal website.')) ?> + escapeHtml(__('To use PayPal Payments Advanced, you must configure your PayPal Payments Advanced account on the PayPal website.')) ?> escapeHtml(__('Once you log into your PayPal Advanced account, navigate to the Service Settings - Hosted Checkout Pages - Set Up menu and set the options described below')) ?>

        diff --git a/app/code/Magento/Paypal/view/frontend/layout/checkout_index_index.xml b/app/code/Magento/Paypal/view/frontend/layout/checkout_index_index.xml index 4f514806eeb89..73c44faff5a57 100644 --- a/app/code/Magento/Paypal/view/frontend/layout/checkout_index_index.xml +++ b/app/code/Magento/Paypal/view/frontend/layout/checkout_index_index.xml @@ -44,6 +44,15 @@ true + + false + + + false + + + false + diff --git a/app/code/Magento/Paypal/view/frontend/web/js/action/set-payment-method.js b/app/code/Magento/Paypal/view/frontend/web/js/action/set-payment-method.js index a994f9defd583..63e34437c6f90 100644 --- a/app/code/Magento/Paypal/view/frontend/web/js/action/set-payment-method.js +++ b/app/code/Magento/Paypal/view/frontend/web/js/action/set-payment-method.js @@ -4,48 +4,12 @@ */ define([ - 'jquery', 'Magento_Checkout/js/model/quote', - 'Magento_Checkout/js/model/url-builder', - 'mage/storage', - 'Magento_Checkout/js/model/error-processor', - 'Magento_Customer/js/model/customer', - 'Magento_Checkout/js/model/full-screen-loader' -], function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) { + 'Magento_Checkout/js/action/set-payment-information' +], function (quote, setPaymentInformation) { 'use strict'; return function (messageContainer) { - var serviceUrl, - payload, - paymentData = quote.paymentMethod(); - - /** - * Checkout for guest and registered customer. - */ - if (!customer.isLoggedIn()) { - serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/set-payment-information', { - cartId: quote.getQuoteId() - }); - payload = { - cartId: quote.getQuoteId(), - email: quote.guestEmail, - paymentMethod: paymentData - }; - } else { - serviceUrl = urlBuilder.createUrl('/carts/mine/set-payment-information', {}); - payload = { - cartId: quote.getQuoteId(), - paymentMethod: paymentData - }; - } - fullScreenLoader.startLoader(); - - return storage.post( - serviceUrl, JSON.stringify(payload) - ).fail(function (response) { - errorProcessor.process(response, messageContainer); - }).always(function () { - fullScreenLoader.stopLoader(); - }); + return setPaymentInformation(messageContainer, quote.paymentMethod()); }; }); diff --git a/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js b/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js index 4d68ad8ef9f4b..c56f21bc718fb 100644 --- a/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js +++ b/app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js @@ -78,7 +78,9 @@ define( $('body').trigger('processStop'); customerData.invalidate(['cart']); }); - }.bind(this)); + }.bind(this)).fail(function () { + paypalExpressCheckout.checkout.closeFlow(); + }); } } } diff --git a/app/code/Magento/Persistent/composer.json b/app/code/Magento/Persistent/composer.json index 516a1c2b4b8ac..ac065ba413cdb 100644 --- a/app/code/Magento/Persistent/composer.json +++ b/app/code/Magento/Persistent/composer.json @@ -5,14 +5,14 @@ "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", "magento/module-checkout": "100.2.*", - "magento/module-customer": "100.2.*", + "magento/module-customer": "101.0.*", "magento/module-cron": "100.2.*", "magento/module-page-cache": "100.2.*", - "magento/module-quote": "100.2.*", - "magento/framework": "100.2.*" + "magento/module-quote": "101.0.*", + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/ProductAlert/Controller/Add/TestObserver.php b/app/code/Magento/ProductAlert/Controller/Add/TestObserver.php deleted file mode 100644 index 74f03220e59d3..0000000000000 --- a/app/code/Magento/ProductAlert/Controller/Add/TestObserver.php +++ /dev/null @@ -1,23 +0,0 @@ -_objectManager->get(\Magento\ProductAlert\Model\Observer::class); - $observer->process($object); - } -} diff --git a/app/code/Magento/ProductAlert/composer.json b/app/code/Magento/ProductAlert/composer.json index 694fb2dda9560..86e67e6bdc8ae 100644 --- a/app/code/Magento/ProductAlert/composer.json +++ b/app/code/Magento/ProductAlert/composer.json @@ -5,15 +5,15 @@ "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-backend": "100.2.*", "magento/module-store": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-customer": "100.2.*", - "magento/framework": "100.2.*" + "magento/module-catalog": "102.0.*", + "magento/module-customer": "101.0.*", + "magento/framework": "101.0.*" }, "suggest": { - "magento/module-config": "100.2.*" + "magento/module-config": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php b/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php index 3658e36a82ec3..9950526182e3e 100644 --- a/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php +++ b/app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php @@ -110,7 +110,7 @@ public function execute() $remoteFileUrl = $this->getRequest()->getParam('remote_image'); $this->validateRemoteFile($remoteFileUrl); $localFileName = Uploader::getCorrectFileName(basename($remoteFileUrl)); - $localTmpFileName = Uploader::getDispretionPath($localFileName) . DIRECTORY_SEPARATOR . $localFileName; + $localTmpFileName = Uploader::getDispersionPath($localFileName) . DIRECTORY_SEPARATOR . $localFileName; $localFilePath = $baseTmpMediaPath . ($localTmpFileName); $localUniqFilePath = $this->appendNewFileName($localFilePath); $this->validateRemoteFileExtensions($localUniqFilePath); @@ -174,7 +174,7 @@ private function validateRemoteFileExtensions($filePath) protected function appendResultSaveRemoteImage($fileName) { $fileInfo = pathinfo($fileName); - $tmpFileName = Uploader::getDispretionPath($fileInfo['basename']) . DIRECTORY_SEPARATOR . $fileInfo['basename']; + $tmpFileName = Uploader::getDispersionPath($fileInfo['basename']) . DIRECTORY_SEPARATOR . $fileInfo['basename']; $result['name'] = $fileInfo['basename']; $result['type'] = $this->imageAdapter->getMimeType(); $result['error'] = 0; diff --git a/app/code/Magento/ProductVideo/composer.json b/app/code/Magento/ProductVideo/composer.json index 9a39534fe3a6c..d40707a06de8a 100644 --- a/app/code/Magento/ProductVideo/composer.json +++ b/app/code/Magento/ProductVideo/composer.json @@ -3,20 +3,20 @@ "description": "Add Video to Products", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-catalog": "101.1.*", + "magento/module-catalog": "102.0.*", "magento/module-backend": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-media-storage": "100.2.*", "magento/module-store": "100.2.*", - "magento/framework": "100.2.*", + "magento/framework": "101.0.*", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-customer": "100.2.*", - "magento/module-config": "100.2.*" + "magento/module-customer": "101.0.*", + "magento/module-config": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "proprietary" ], diff --git a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js index ca920e8740978..13b0e43a84d81 100644 --- a/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js +++ b/app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js @@ -302,7 +302,7 @@ define([ additionalParams += '&autoplay=1'; } - src = window.location.protocol + '//player.vimeo.com/video/' + + src = 'https://player.vimeo.com/video/' + this._code + '?api=1&player_id=vimeo' + this._code + timestamp + @@ -525,7 +525,7 @@ define([ ); } else if (type === 'vimeo') { $.ajax({ - url: window.location.protocol + '//www.vimeo.com/api/v2/video/' + id + '.json', + url: 'https://www.vimeo.com/api/v2/video/' + id + '.json', dataType: 'jsonp', data: { format: 'json' diff --git a/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js b/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js index 03ce42bf25c4a..3104fdc6190dc 100644 --- a/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js +++ b/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js @@ -134,7 +134,6 @@ define([ */ _create: function () { $(this.element).on('gallery:loaded', $.proxy(function () { - this.fotoramaItem = $(this.element).find('.fotorama-item'); this._initialize(); }, this)); }, @@ -154,6 +153,7 @@ define([ this.defaultVideoData = this.options.videoData = this.videoDataPlaceholder; } + this.fotoramaItem = $(this.element).find('.fotorama-item'); this.clearEvents(); if (this._checkForVideoExist()) { @@ -164,6 +164,8 @@ define([ this._initFotoramaVideo(); this._attachFotoramaEvents(); } + + this.element.trigger('AddFotoramaVideoEvents:loaded'); }, /** @@ -173,10 +175,10 @@ define([ */ clearEvents: function () { this.fotoramaItem.off( - 'fotorama:show ' + - 'fotorama:showend ' + - 'fotorama:fullscreenenter ' + - 'fotorama:fullscreenexit' + 'fotorama:show.' + this.PV + + ' fotorama:showend.' + this.PV + + ' fotorama:fullscreenenter.' + this.PV + + ' fotorama:fullscreenexit.' + this.PV ); }, @@ -205,7 +207,7 @@ define([ if (options.dataMergeStrategy === 'prepend') { this.options.videoData = [].concat( this.options.optionsVideoData[options.selectedOption], - this.options.videoData + this.defaultVideoData ); } else { this.options.videoData = this.options.optionsVideoData[options.selectedOption]; @@ -230,11 +232,11 @@ define([ * @private */ _listenForFullscreen: function () { - this.fotoramaItem.on('fotorama:fullscreenenter', $.proxy(function () { + this.fotoramaItem.on('fotorama:fullscreenenter.' + this.PV, $.proxy(function () { this.isFullscreen = true; }, this)); - this.fotoramaItem.on('fotorama:fullscreenexit', $.proxy(function () { + this.fotoramaItem.on('fotorama:fullscreenexit.' + this.PV, $.proxy(function () { this.isFullscreen = false; this._hideVideoArrows(); }, this)); @@ -466,7 +468,7 @@ define([ t; if (!fotorama.activeFrame.$navThumbFrame) { - this.fotoramaItem.on('fotorama:showend', $.proxy(function (evt, fotoramaData) { + this.fotoramaItem.on('fotorama:showend.' + this.PV, $.proxy(function (evt, fotoramaData) { $(fotoramaData.activeFrame.$stageFrame).removeAttr('href'); }, this)); @@ -484,7 +486,7 @@ define([ this._checkForVideo(e, fotorama, t + 1); } - this.fotoramaItem.on('fotorama:showend', $.proxy(function (evt, fotoramaData) { + this.fotoramaItem.on('fotorama:showend.' + this.PV, $.proxy(function (evt, fotoramaData) { $(fotoramaData.activeFrame.$stageFrame).removeAttr('href'); }, this)); }, @@ -526,15 +528,15 @@ define([ * @private */ _attachFotoramaEvents: function () { - this.fotoramaItem.on('fotorama:showend', $.proxy(function (e, fotorama) { + this.fotoramaItem.on('fotorama:showend.' + this.PV, $.proxy(function (e, fotorama) { this._startPrepareForPlayer(e, fotorama); }, this)); - this.fotoramaItem.on('fotorama:show', $.proxy(function (e, fotorama) { + this.fotoramaItem.on('fotorama:show.' + this.PV, $.proxy(function (e, fotorama) { this._unloadVideoPlayer(fotorama.activeFrame.$stageFrame.parent(), fotorama, true); }, this)); - this.fotoramaItem.on('fotorama:fullscreenexit', $.proxy(function (e, fotorama) { + this.fotoramaItem.on('fotorama:fullscreenexit.' + this.PV, $.proxy(function (e, fotorama) { fotorama.activeFrame.$stageFrame.find('.' + this.PV).remove(); this._startPrepareForPlayer(e, fotorama); }, this)); diff --git a/app/code/Magento/ProductVideo/view/frontend/web/js/load-player.js b/app/code/Magento/ProductVideo/view/frontend/web/js/load-player.js index 5a9f6a3eca941..3519d538e523a 100644 --- a/app/code/Magento/ProductVideo/view/frontend/web/js/load-player.js +++ b/app/code/Magento/ProductVideo/view/frontend/web/js/load-player.js @@ -317,7 +317,7 @@ define(['jquery', 'jquery/ui'], function ($) { if (this._loop) { additionalParams += '&loop=1'; } - src = window.location.protocol + '//player.vimeo.com/video/' + + src = 'https://player.vimeo.com/video/' + this._code + '?api=1&player_id=vimeo' + this._code + timestamp + diff --git a/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php b/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php index 9fe69b691424d..e18ab8587fc71 100644 --- a/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php +++ b/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php @@ -10,6 +10,7 @@ use Magento\Quote\Api\CartTotalRepositoryInterface; use Magento\Catalog\Helper\Product\ConfigurationPool; use Magento\Framework\Api\DataObjectHelper; +use Magento\Framework\Api\ExtensibleDataInterface; use Magento\Quote\Model\Cart\Totals\ItemConverter; use Magento\Quote\Api\CouponManagementInterface; @@ -94,6 +95,7 @@ public function get($cartId) $addressTotalsData = $quote->getShippingAddress()->getData(); $addressTotals = $quote->getShippingAddress()->getTotals(); } + unset($addressTotalsData[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]); /** @var \Magento\Quote\Api\Data\TotalsInterface $quoteTotals */ $quoteTotals = $this->totalsFactory->create(); diff --git a/app/code/Magento/Quote/Model/CouponManagement.php b/app/code/Magento/Quote/Model/CouponManagement.php index 7701e41e0b55a..87398ad36cfab 100644 --- a/app/code/Magento/Quote/Model/CouponManagement.php +++ b/app/code/Magento/Quote/Model/CouponManagement.php @@ -50,6 +50,7 @@ public function get($cartId) */ public function set($cartId, $couponCode) { + $couponCode = trim($couponCode); /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); if (!$quote->getItemsCount()) { diff --git a/app/code/Magento/Quote/Model/Quote.php b/app/code/Magento/Quote/Model/Quote.php index 18fa41e2beb58..7741d3b0f7657 100644 --- a/app/code/Magento/Quote/Model/Quote.php +++ b/app/code/Magento/Quote/Model/Quote.php @@ -14,6 +14,8 @@ use Magento\Quote\Model\Quote\Address; use Magento\Quote\Model\Quote\Address\Total as AddressTotal; use Magento\Sales\Model\Status; +use Magento\Framework\App\ObjectManager; +use Magento\Sales\Model\OrderIncrementIdChecker; /** * Quote model @@ -353,6 +355,11 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C */ protected $shippingAddressesItems; + /** + * @var \Magento\Sales\Model\OrderIncrementIdChecker + */ + private $orderIncrementIdChecker; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -394,6 +401,7 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data + * @param OrderIncrementIdChecker|null $orderIncrementIdChecker * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -436,7 +444,8 @@ public function __construct( \Magento\Quote\Model\ShippingAssignmentFactory $shippingAssignmentFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + OrderIncrementIdChecker $orderIncrementIdChecker = null ) { $this->quoteValidator = $quoteValidator; $this->_catalogProduct = $catalogProduct; @@ -471,6 +480,8 @@ public function __construct( $this->totalsReader = $totalsReader; $this->shippingFactory = $shippingFactory; $this->shippingAssignmentFactory = $shippingAssignmentFactory; + $this->orderIncrementIdChecker = $orderIncrementIdChecker ?: ObjectManager::getInstance() + ->get(OrderIncrementIdChecker::class); parent::__construct( $context, $registry, @@ -1046,7 +1057,7 @@ public function addCustomerAddress(\Magento\Customer\Api\Data\AddressInterface $ public function updateCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer) { $quoteCustomer = $this->getCustomer(); - $this->dataObjectHelper->mergeDataObjects(get_class($quoteCustomer), $quoteCustomer, $customer); + $this->dataObjectHelper->mergeDataObjects(CustomerInterface::class, $quoteCustomer, $customer); $this->setCustomer($quoteCustomer); return $this; } @@ -2184,7 +2195,7 @@ public function reserveOrderId() } else { //checking if reserved order id was already used for some order //if yes reserving new one if not using old one - if ($this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId())) { + if ($this->orderIncrementIdChecker->isIncrementIdUsed($this->getReservedOrderId())) { $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this)); } } diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php index 109ca91cb2ae8..67393e3598568 100644 --- a/app/code/Magento/Quote/Model/Quote/Address.php +++ b/app/code/Magento/Quote/Model/Quote/Address.php @@ -1008,6 +1008,7 @@ public function requestShippingRates(\Magento\Quote\Model\Quote\Item\AbstractIte /** * Store and website identifiers specified from StoreManager */ + $request->setQuoteStoreId($this->getQuote()->getStoreId()); $request->setStoreId($this->storeManager->getStore()->getId()); $request->setWebsiteId($this->storeManager->getWebsite()->getId()); $request->setFreeShipping($this->getFreeShipping()); @@ -1170,7 +1171,8 @@ public function validateMinimumAmount() */ public function getAppliedTaxes() { - return $this->serializer->unserialize($this->getData('applied_taxes')); + $taxes = $this->getData('applied_taxes'); + return $taxes ? $this->serializer->unserialize($taxes) : []; } /** diff --git a/app/code/Magento/Quote/Model/Quote/Item.php b/app/code/Magento/Quote/Model/Quote/Item.php index d8177ddfe5236..fe6d712500bcd 100644 --- a/app/code/Magento/Quote/Model/Quote/Item.php +++ b/app/code/Magento/Quote/Model/Quote/Item.php @@ -745,6 +745,9 @@ public function saveItemOptions() unset($this->_options[$index]); unset($this->_optionsByCode[$option->getCode()]); } else { + if (!$option->getItem() || !$option->getItem()->getId()) { + $option->setItem($this); + } $option->save(); } } diff --git a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php index 3113721f8a597..38bfcbf1d30ca 100644 --- a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php +++ b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php @@ -19,22 +19,32 @@ class ValidationMessage /** * @var \Magento\Framework\Locale\CurrencyInterface + * @deprecated since 101.0.0 */ private $currency; + /** + * @var \Magento\Framework\Pricing\Helper\Data + */ + private $priceHelper; + /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Locale\CurrencyInterface $currency + * @param \Magento\Framework\Pricing\Helper\Data $priceHelper */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Locale\CurrencyInterface $currency + \Magento\Framework\Locale\CurrencyInterface $currency, + \Magento\Framework\Pricing\Helper\Data $priceHelper = null ) { $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; $this->currency = $currency; + $this->priceHelper = $priceHelper ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Pricing\Helper\Data::class); } /** @@ -50,13 +60,11 @@ public function getMessage() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); if (!$message) { - $currencyCode = $this->storeManager->getStore()->getCurrentCurrencyCode(); - $minimumAmount = $this->currency->getCurrency($currencyCode)->toCurrency( - $this->scopeConfig->getValue( - 'sales/minimum_order/amount', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) - ); + $minimumAmount = $this->priceHelper->currency($this->scopeConfig->getValue( + 'sales/minimum_order/amount', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ), true, false); + $message = __('Minimum order amount is %1', $minimumAmount); } else { //Added in order to address the issue: https://github.com/magento/magento2/issues/8287 diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 49206ff924f13..9bdcb083808ad 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -232,6 +232,8 @@ public function createEmptyCart() $quote->setShippingAddress($this->quoteAddressFactory->create()); try { + $quote->getShippingAddress()->setCollectShippingRates(true); + $this->quoteRepository->save($quote); } catch (\Exception $e) { throw new CouldNotSaveException(__('Cannot create quote')); @@ -410,17 +412,24 @@ public function submit(QuoteEntity $quote, $orderData = []) */ protected function resolveItems(QuoteEntity $quote) { - $quoteItems = []; - foreach ($quote->getAllItems() as $quoteItem) { - /** @var \Magento\Quote\Model\ResourceModel\Quote\Item $quoteItem */ - $quoteItems[$quoteItem->getId()] = $quoteItem; - } $orderItems = []; - foreach ($quoteItems as $quoteItem) { - $parentItem = (isset($orderItems[$quoteItem->getParentItemId()])) ? - $orderItems[$quoteItem->getParentItemId()] : null; - $orderItems[$quoteItem->getId()] = - $this->quoteItemToOrderItem->convert($quoteItem, ['parent_item' => $parentItem]); + foreach ($quote->getAllItems() as $quoteItem) { + $itemId = $quoteItem->getId(); + + if (!empty($orderItems[$itemId])) { + continue; + } + + $parentItemId = $quoteItem->getParentItemId(); + /** @var \Magento\Quote\Model\ResourceModel\Quote\Item $parentItem */ + if ($parentItemId && !isset($orderItems[$parentItemId])) { + $orderItems[$parentItemId] = $this->quoteItemToOrderItem->convert( + $quoteItem->getParentItem(), + ['parent_item' => null] + ); + } + $parentItem = isset($orderItems[$parentItemId]) ? $orderItems[$parentItemId] : null; + $orderItems[$itemId] = $this->quoteItemToOrderItem->convert($quoteItem, ['parent_item' => $parentItem]); } return array_values($orderItems); } @@ -466,6 +475,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) 'email' => $quote->getCustomerEmail() ] ); + $shippingAddress->setData('quote_address_id', $quote->getShippingAddress()->getId()); $addresses[] = $shippingAddress; $order->setShippingAddress($shippingAddress); $order->setShippingMethod($quote->getShippingAddress()->getShippingMethod()); @@ -477,6 +487,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) 'email' => $quote->getCustomerEmail() ] ); + $billingAddress->setData('quote_address_id', $quote->getBillingAddress()->getId()); $addresses[] = $billingAddress; $order->setBillingAddress($billingAddress); $order->setAddresses($addresses); diff --git a/app/code/Magento/Quote/Model/QuoteRepository.php b/app/code/Magento/Quote/Model/QuoteRepository.php index 01c21bbbe50a7..d3967794b300a 100644 --- a/app/code/Magento/Quote/Model/QuoteRepository.php +++ b/app/code/Magento/Quote/Model/QuoteRepository.php @@ -212,7 +212,7 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared if ($sharedStoreIds) { $quote->setSharedStoreIds($sharedStoreIds); } - $quote->setStoreId($this->storeManager->getStore()->getId())->$loadMethod($identifier); + $quote->$loadMethod($identifier)->setStoreId($this->storeManager->getStore()->getId()); if (!$quote->getId()) { throw NoSuchEntityException::singleField($loadField, $identifier); } diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote.php b/app/code/Magento/Quote/Model/ResourceModel/Quote.php index 054d036075aba..2645d52c87da5 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote.php @@ -167,34 +167,11 @@ public function getReservedOrderId($quote) { return $this->sequenceManager->getSequence( \Magento\Sales\Model\Order::ENTITY, - $quote->getStore()->getGroup()->getDefaultStoreId() + $quote->getStoreId() ) ->getNextValue(); } - /** - * Check if order increment ID is already used. - * Method can be used to avoid collisions of order IDs. - * - * @param int $orderIncrementId - * @return bool - */ - public function isOrderIncrementIdUsed($orderIncrementId) - { - /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */ - $adapter = $this->getConnection(); - $bind = [':increment_id' => $orderIncrementId]; - /** @var \Magento\Framework\DB\Select $select */ - $select = $adapter->select(); - $select->from($this->getTable('sales_order'), 'entity_id')->where('increment_id = :increment_id'); - $entity_id = $adapter->fetchOne($select, $bind); - if ($entity_id > 0) { - return true; - } - - return false; - } - /** * Mark quotes - that depend on catalog price rules - to be recollected on demand * @@ -234,7 +211,7 @@ public function markQuotesRecollectOnCatalogRules() * @param \Magento\Catalog\Model\Product $product * @return $this */ - public function substractProductFromQuotes($product) + public function subtractProductFromQuotes($product) { $productId = (int)$product->getId(); if (!$productId) { @@ -274,6 +251,21 @@ public function substractProductFromQuotes($product) return $this; } + /** + * Subtract product from all quotes quantities + * + * @param \Magento\Catalog\Model\Product $product + * + * @deprecated 101.0.1 + * @see \Magento\Quote\Model\ResourceModel\Quote::subtractProductFromQuotes + * + * @return $this + */ + public function substractProductFromQuotes($product) + { + return $this->subtractProductFromQuotes($product); + } + /** * Mark recollect contain product(s) quotes * diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index 52c33e98bbc73..0487d7e46eb26 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -101,7 +101,7 @@ protected function _construct() */ public function getStoreId() { - return (int)$this->_quote->getStoreId(); + return (int)$this->_productCollectionFactory->create()->getStoreId(); } /** @@ -156,18 +156,20 @@ protected function _afterLoad() { parent::_afterLoad(); - /** - * Assign parent items - */ + $productIds = []; foreach ($this as $item) { + // Assign parent items if ($item->getParentItemId()) { $item->setParentItem($this->getItemById($item->getParentItemId())); } if ($this->_quote) { $item->setQuote($this->_quote); } + // Collect quote products ids + $productIds[] = (int)$item->getProductId(); } - + $this->_productIds = array_merge($this->_productIds, $productIds); + $this->removeItemsWithAbsentProducts(); /** * Assign options and products */ @@ -205,12 +207,6 @@ protected function _assignOptions() protected function _assignProducts() { \Magento\Framework\Profiler::start('QUOTE:' . __METHOD__, ['group' => 'QUOTE', 'method' => __METHOD__]); - $productIds = []; - foreach ($this as $item) { - $productIds[] = (int)$item->getProductId(); - } - $this->_productIds = array_merge($this->_productIds, $productIds); - $productCollection = $this->_productCollectionFactory->create()->setStoreId( $this->getStoreId() )->addIdFilter( @@ -305,4 +301,24 @@ private function addTierPriceData(ProductCollection $productCollection) $productCollection->addTierPriceDataByGroupId($this->_quote->getCustomerGroupId()); } } + + /** + * Find and remove quote items with non existing products + * + * @return void + */ + private function removeItemsWithAbsentProducts() + { + $productCollection = $this->_productCollectionFactory->create()->addIdFilter($this->_productIds); + $existingProductsIds = $productCollection->getAllIds(); + $absentProductsIds = array_diff($this->_productIds, $existingProductsIds); + // Remove not existing products from items collection + if (!empty($absentProductsIds)) { + foreach ($absentProductsIds as $productIdToExclude) { + /** @var \Magento\Quote\Model\Quote\Item $quoteItem */ + $quoteItem = $this->getItemByColumnValue('product_id', $productIdToExclude); + $this->removeItemByKey($quoteItem->getId()); + } + } + } } diff --git a/app/code/Magento/Quote/Observer/Webapi/SubmitObserver.php b/app/code/Magento/Quote/Observer/SubmitObserver.php similarity index 94% rename from app/code/Magento/Quote/Observer/Webapi/SubmitObserver.php rename to app/code/Magento/Quote/Observer/SubmitObserver.php index 4f1e66dcc724b..1213636e5966b 100644 --- a/app/code/Magento/Quote/Observer/Webapi/SubmitObserver.php +++ b/app/code/Magento/Quote/Observer/SubmitObserver.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Quote\Observer\Webapi; +namespace Magento\Quote\Observer; use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Magento\Framework\Event\ObserverInterface; @@ -13,12 +13,12 @@ class SubmitObserver implements ObserverInterface /** * @var \Psr\Log\LoggerInterface */ - protected $logger; + private $logger; /** * @var OrderSender */ - protected $orderSender; + private $orderSender; /** * @param \Psr\Log\LoggerInterface $logger diff --git a/app/code/Magento/Quote/Setup/UpgradeSchema.php b/app/code/Magento/Quote/Setup/UpgradeSchema.php index e4912892dbe17..e9221895e18dc 100644 --- a/app/code/Magento/Quote/Setup/UpgradeSchema.php +++ b/app/code/Magento/Quote/Setup/UpgradeSchema.php @@ -5,6 +5,7 @@ */ namespace Magento\Quote\Setup; +use Magento\Framework\DB\Ddl\Table; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; @@ -40,7 +41,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con 'street', 'street', [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'type' => Table::TYPE_TEXT, 'length' => 255, 'comment' => 'Street' ] @@ -48,20 +49,20 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con } //drop foreign key for single DB case if (version_compare($context->getVersion(), '2.0.3', '<') - && $setup->tableExists($setup->getTable('quote_item')) + && $setup->tableExists($setup->getTable('quote_item', self::$connectionName)) ) { - $setup->getConnection()->dropForeignKey( - $setup->getTable('quote_item'), + $setup->getConnection(self::$connectionName)->dropForeignKey( + $setup->getTable('quote_item', self::$connectionName), $setup->getFkName('quote_item', 'product_id', 'catalog_product_entity', 'entity_id') ); } if (version_compare($context->getVersion(), '2.0.5', '<')) { - $connection = $setup->getConnection(); + $connection = $setup->getConnection(self::$connectionName); $connection->modifyColumn( - $setup->getTable('quote_address'), + $setup->getTable('quote_address', self::$connectionName), 'shipping_method', [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'type' => Table::TYPE_TEXT, 'length' => 120 ] ); @@ -72,33 +73,53 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con $setup->getTable('quote_address', self::$connectionName), 'firstname', [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'type' => Table::TYPE_TEXT, 'length' => 255, ] )->modifyColumn( $setup->getTable('quote_address', self::$connectionName), 'middlename', [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'type' => Table::TYPE_TEXT, 'length' => 40, ] )->modifyColumn( $setup->getTable('quote_address', self::$connectionName), 'lastname', [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'type' => Table::TYPE_TEXT, 'length' => 255, ] )->modifyColumn( $setup->getTable('quote', self::$connectionName), 'updated_at', [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + 'type' => Table::TYPE_TIMESTAMP, 'nullable' => false, - 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE, + 'default' => Table::TIMESTAMP_INIT_UPDATE, ] ); } + if (version_compare($context->getVersion(), '2.0.7', '<')) { + $connection = $setup->getConnection(self::$connectionName); + $connection->modifyColumn( + $setup->getTable('quote_address', self::$connectionName), + 'telephone', + ['type' => Table::TYPE_TEXT, 'length' => 255] + )->modifyColumn( + $setup->getTable('quote_address', self::$connectionName), + 'fax', + ['type' => Table::TYPE_TEXT, 'length' => 255] + )->modifyColumn( + $setup->getTable('quote_address', self::$connectionName), + 'region', + ['type' => Table::TYPE_TEXT, 'length' => 255] + )->modifyColumn( + $setup->getTable('quote_address', self::$connectionName), + 'city', + ['type' => Table::TYPE_TEXT, 'length' => 255] + ); + } $setup->endSetup(); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php index 1557fe420be02..e25b770b7a81e 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php @@ -9,7 +9,7 @@ namespace Magento\Quote\Test\Unit\Model\Quote; use Magento\Directory\Model\Currency; -use \Magento\Quote\Model\Quote\Address; +use Magento\Quote\Model\Quote\Address; use Magento\Quote\Model\Quote\Address\Rate; use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory as RateCollectionFactory; use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\Collection as RatesCollection; @@ -28,11 +28,13 @@ use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Api\Data\WebsiteInterface; use Magento\Quote\Model\Quote\Address\RateResult\AbstractResult; +use Magento\Framework\Serialize\Serializer\Json; /** * Test class for sales quote address model * * @see \Magento\Quote\Model\Quote\Address + * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class AddressTest extends \PHPUnit\Framework\TestCase @@ -47,6 +49,11 @@ class AddressTest extends \PHPUnit\Framework\TestCase */ private $quote; + /** + * @var \Magento\Quote\Model\Quote\Address\CustomAttributeListInterface | \PHPUnit_Framework_MockObject_MockObject + */ + private $attributeList; + /** * @var \Magento\Framework\App\Config | \PHPUnit_Framework_MockObject_MockObject */ @@ -117,7 +124,7 @@ protected function setUp() $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->scopeConfig = $this->createMock(\Magento\Framework\App\Config::class); - $this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class); + $this->serializer = new Json(); $this->requestFactory = $this->getMockBuilder(RateRequestFactory::class) ->disableOriginalConstructor() @@ -165,9 +172,13 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->attributeList = $this->createMock(\Magento\Quote\Model\Quote\Address\CustomAttributeListInterface::class); + $this->attributeList->method('getAttributes')->willReturn([]); + $this->address = $objectManager->getObject( \Magento\Quote\Model\Quote\Address::class, [ + 'attributeList' => $this->attributeList, 'scopeConfig' => $this->scopeConfig, 'serializer' => $this->serializer, 'storeManager' => $this->storeManager, @@ -273,20 +284,17 @@ public function testValidateMiniumumAmountNegative() public function testSetAndGetAppliedTaxes() { $data = ['data']; - $result = json_encode($data); - - $this->serializer->expects($this->once()) - ->method('serialize') - ->with($data) - ->willReturn($result); - - $this->serializer->expects($this->once()) - ->method('unserialize') - ->with($result) - ->willReturn($data); + self::assertInstanceOf(Address::class, $this->address->setAppliedTaxes($data)); + self::assertEquals($data, $this->address->getAppliedTaxes()); + } - $this->assertInstanceOf(\Magento\Quote\Model\Quote\Address::class, $this->address->setAppliedTaxes($data)); - $this->assertEquals($data, $this->address->getAppliedTaxes()); + /** + * Checks a case, when applied taxes are not provided. + */ + public function testGetAppliedTaxesWithEmptyValue() + { + $this->address->setData('applied_taxes', null); + self::assertEquals([], $this->address->getAppliedTaxes()); } /** diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php index 64204ea1fb93d..272a4e3a4ba49 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php @@ -26,19 +26,27 @@ class ValidationMessageTest extends \PHPUnit\Framework\TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject + * @deprecated since 101.0.0 */ private $currencyMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $priceHelperMock; + protected function setUp() { $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); $this->currencyMock = $this->createMock(\Magento\Framework\Locale\CurrencyInterface::class); + $this->priceHelperMock = $this->createMock(\Magento\Framework\Pricing\Helper\Data::class); $this->model = new \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage( $this->scopeConfigMock, $this->storeManagerMock, - $this->currencyMock + $this->currencyMock, + $this->priceHelperMock ); } @@ -46,8 +54,6 @@ public function testGetMessage() { $minimumAmount = 20; $minimumAmountCurrency = '$20'; - $currencyCode = 'currency_code'; - $this->scopeConfigMock->expects($this->at(0)) ->method('getValue') ->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) @@ -58,27 +64,13 @@ public function testGetMessage() ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) ->willReturn($minimumAmount); - $storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getCurrentCurrencyCode']); - $storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn($currencyCode); - $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + $this->priceHelperMock->expects($this->once()) + ->method('currency') + ->with($minimumAmount, true, false) + ->will($this->returnValue($minimumAmountCurrency)); - $currencyMock = $this->createMock(\Magento\Framework\Currency::class); - $this->currencyMock->expects($this->once()) - ->method('getCurrency') - ->with($currencyCode) - ->willReturn($currencyMock); - - $currencyMock->expects($this->once()) - ->method('toCurrency') - ->with($minimumAmount) - ->willReturn($minimumAmountCurrency); - - $this->assertEquals( - __('Minimum order amount is %1', $minimumAmountCurrency), - $this->model->getMessage() - ); + $this->assertEquals(__('Minimum order amount is %1', $minimumAmountCurrency), $this->model->getMessage()); } - public function testGetConfigMessage() { $configMessage = 'config_message'; diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php index 71dd3a2e7ea8a..145a18fb34ca3 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php @@ -7,8 +7,8 @@ namespace Magento\Quote\Test\Unit\Model; use Magento\Framework\Exception\NoSuchEntityException; - use Magento\Quote\Model\CustomerManagement; +use Magento\Sales\Api\Data\OrderAddressInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -131,6 +131,11 @@ class QuoteManagementTest extends \PHPUnit\Framework\TestCase */ private $addressRepositoryMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $quoteFactoryMock; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -241,10 +246,15 @@ public function testCreateEmptyCartAnonymous() $quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class); - $quoteAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class); + $quoteAddress = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address::class) + ->disableOriginalConstructor() + ->setMethods(['setCollectShippingRates']) + ->getMock(); $quoteMock->expects($this->any())->method('setBillingAddress')->with($quoteAddress)->willReturnSelf(); $quoteMock->expects($this->any())->method('setShippingAddress')->with($quoteAddress)->willReturnSelf(); + $quoteMock->expects($this->any())->method('getShippingAddress')->willReturn($quoteAddress); + $quoteAddress->expects($this->once())->method('setCollectShippingRates')->with(true); $this->quoteAddressFactory->expects($this->any())->method('create')->willReturn($quoteAddress); @@ -530,12 +540,12 @@ public function testSubmit() $shippingAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class); $payment = $this->createMock(\Magento\Quote\Model\Quote\Payment::class); $baseOrder = $this->createMock(\Magento\Sales\Api\Data\OrderInterface::class); - $convertedBillingAddress = $this->createMock(\Magento\Sales\Api\Data\OrderAddressInterface::class); - $convertedShippingAddress = $this->createMock(\Magento\Sales\Api\Data\OrderAddressInterface::class); + $convertedBilling = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']); + $convertedShipping = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']); $convertedPayment = $this->createMock(\Magento\Sales\Api\Data\OrderPaymentInterface::class); $convertedQuoteItem = $this->createMock(\Magento\Sales\Api\Data\OrderItemInterface::class); - $addresses = [$convertedShippingAddress, $convertedBillingAddress]; + $addresses = [$convertedShipping, $convertedBilling]; $quoteItems = [$quoteItem]; $convertedItems = [$convertedQuoteItem]; @@ -564,7 +574,7 @@ public function testSubmit() 'email' => 'customer@example.com' ] ) - ->willReturn($convertedShippingAddress); + ->willReturn($convertedShipping); $this->quoteAddressToOrderAddress->expects($this->at(1)) ->method('convert') ->with( @@ -574,22 +584,27 @@ public function testSubmit() 'email' => 'customer@example.com' ] ) - ->willReturn($convertedBillingAddress); + ->willReturn($convertedBilling); + + $billingAddress->expects($this->once())->method('getId')->willReturn(4); + $convertedBilling->expects($this->once())->method('setData')->with('quote_address_id', 4); $this->quoteItemToOrderItem->expects($this->once())->method('convert') ->with($quoteItem, ['parent_item' => null]) ->willReturn($convertedQuoteItem); $this->quotePaymentToOrderPayment->expects($this->once())->method('convert')->with($payment) ->willReturn($convertedPayment); $shippingAddress->expects($this->once())->method('getShippingMethod')->willReturn('free'); + $shippingAddress->expects($this->once())->method('getId')->willReturn(5); + $convertedShipping->expects($this->once())->method('setData')->with('quote_address_id', 5); $order = $this->prepareOrderFactory( $baseOrder, - $convertedBillingAddress, + $convertedBilling, $addresses, $convertedPayment, $convertedItems, $quoteId, - $convertedShippingAddress + $convertedShipping ); $this->orderManagement->expects($this->once()) @@ -963,9 +978,6 @@ protected function setPropertyValue(&$object, $property, $value) return $object; } - /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ public function testSubmitForCustomer() { $orderData = []; @@ -978,16 +990,12 @@ public function testSubmitForCustomer() $shippingAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class); $payment = $this->createMock(\Magento\Quote\Model\Quote\Payment::class); $baseOrder = $this->createMock(\Magento\Sales\Api\Data\OrderInterface::class); - $convertedBillingAddress = $this->createMock( - \Magento\Sales\Api\Data\OrderAddressInterface::class - ); - $convertedShippingAddress = $this->createMock( - \Magento\Sales\Api\Data\OrderAddressInterface::class - ); + $convertedBilling = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']); + $convertedShipping = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']); $convertedPayment = $this->createMock(\Magento\Sales\Api\Data\OrderPaymentInterface::class); $convertedQuoteItem = $this->createMock(\Magento\Sales\Api\Data\OrderItemInterface::class); - $addresses = [$convertedShippingAddress, $convertedBillingAddress]; + $addresses = [$convertedShipping, $convertedBilling]; $quoteItems = [$quoteItem]; $convertedItems = [$convertedQuoteItem]; @@ -1016,7 +1024,7 @@ public function testSubmitForCustomer() 'email' => 'customer@example.com' ] ) - ->willReturn($convertedShippingAddress); + ->willReturn($convertedShipping); $this->quoteAddressToOrderAddress->expects($this->at(1)) ->method('convert') ->with( @@ -1026,22 +1034,24 @@ public function testSubmitForCustomer() 'email' => 'customer@example.com' ] ) - ->willReturn($convertedBillingAddress); + ->willReturn($convertedBilling); $this->quoteItemToOrderItem->expects($this->once())->method('convert') ->with($quoteItem, ['parent_item' => null]) ->willReturn($convertedQuoteItem); $this->quotePaymentToOrderPayment->expects($this->once())->method('convert')->with($payment) ->willReturn($convertedPayment); $shippingAddress->expects($this->once())->method('getShippingMethod')->willReturn('free'); + $shippingAddress->expects($this->once())->method('getId')->willReturn(5); + $convertedShipping->expects($this->once())->method('setData')->with('quote_address_id', 5); $order = $this->prepareOrderFactory( $baseOrder, - $convertedBillingAddress, + $convertedBilling, $addresses, $convertedPayment, $convertedItems, $quoteId, - $convertedShippingAddress + $convertedShipping ); $customerAddressMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AddressInterface::class) ->getMockForAbstractClass(); @@ -1050,6 +1060,8 @@ public function testSubmitForCustomer() $quote->expects($this->any())->method('addCustomerAddress')->with($customerAddressMock); $billingAddress->expects($this->once())->method('getCustomerId')->willReturn(2); $billingAddress->expects($this->once())->method('getSaveInAddressBook')->willReturn(false); + $billingAddress->expects($this->once())->method('getId')->willReturn(4); + $convertedBilling->expects($this->once())->method('setData')->with('quote_address_id', 4); $this->orderManagement->expects($this->once()) ->method('place') ->with($order) @@ -1063,4 +1075,25 @@ public function testSubmitForCustomer() $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote); $this->assertEquals($order, $this->model->submit($quote, $orderData)); } + + /** + * Get mock for abstract class with methods. + * + * @param string $className + * @param array $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function createPartialMockForAbstractClass($className, $methods = []) + { + return $this->getMockForAbstractClass( + $className, + [], + '', + true, + true, + true, + $methods + ); + } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php index 359d5f95d7356..c0056e2c8338f 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php @@ -147,6 +147,11 @@ class QuoteTest extends \PHPUnit\Framework\TestCase */ private $itemProcessor; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $orderIncrementIdChecker; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -233,6 +238,9 @@ protected function setUp() ->getMock(); $this->extensionAttributesJoinProcessorMock = $this->createMock(\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface::class); $this->customerDataFactoryMock = $this->createPartialMock(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class, ['create']); + $this->orderIncrementIdChecker = $this->getMockBuilder(\Magento\Sales\Model\OrderIncrementIdChecker::class) + ->disableOriginalConstructor() + ->getMock(); $this->quote = (new ObjectManager($this)) ->getObject( \Magento\Quote\Model\Quote::class, @@ -257,6 +265,7 @@ protected function setUp() 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock, 'customerDataFactory' => $this->customerDataFactoryMock, 'itemProcessor' => $this->itemProcessor, + 'orderIncrementIdChecker' => $this->orderIncrementIdChecker, 'data' => [ 'reserved_order_id' => 1000001 ] @@ -1186,9 +1195,9 @@ public function testGetAllItems() */ public function testReserveOrderId($isReservedOrderIdExist, $reservedOrderId) { - $this->resourceMock + $this->orderIncrementIdChecker ->expects($this->once()) - ->method('isOrderIncrementIdUsed') + ->method('isIncrementIdUsed') ->with(1000001)->willReturn($isReservedOrderIdExist); $this->resourceMock->expects($this->any())->method('getReservedOrderId')->willReturn($reservedOrderId); $this->quote->reserveOrderId(); diff --git a/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php index a6f34fb10bccd..ab36746da5e73 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php @@ -6,79 +6,98 @@ namespace Magento\Quote\Test\Unit\Model\ResourceModel; +use Magento\Framework\DB\Sequence\SequenceInterface; +use Magento\Framework\Model\ResourceModel\Db\Context; +use Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite; +use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot; +use Magento\Quote\Model\Quote; +use Magento\SalesSequence\Model\Manager; + class QuoteTest extends \PHPUnit\Framework\TestCase { /** - * @var \Magento\Quote\Model\ResourceModel\Quote + * @var Quote|\PHPUnit_Framework_MockObject_MockObject */ - private $model; + private $quoteMock; /** - * @var \Magento\Framework\App\ResourceConnection + * @var Manager|\PHPUnit_Framework_MockObject_MockObject */ - private $resourceMock; + private $sequenceManagerMock; /** - * @var \Magento\Framework\DB\Adapter\Pdo\Mysql + * @var SequenceInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $adapterMock; + private $sequenceMock; /** - * @var \Magento\Framework\DB\Select + * @var \Magento\Quote\Model\ResourceModel\Quote */ - private $selectMock; + private $quote; + /** + * {@inheritdoc} + */ protected function setUp() { - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) + $context = $this->getMockBuilder(Context::class) ->disableOriginalConstructor() ->getMock(); - $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf()); - $this->selectMock->expects($this->any())->method('where'); - - $this->adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class) + $snapshot = $this->getMockBuilder(Snapshot::class) ->disableOriginalConstructor() ->getMock(); - $this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock)); - - $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) + $relationComposite = $this->getMockBuilder(RelationComposite::class) ->disableOriginalConstructor() ->getMock(); - $this->resourceMock->expects( - $this->any() - )->method( - 'getConnection' - )->will( - $this->returnValue($this->adapterMock) - ); - - $this->model = $objectManagerHelper->getObject( - \Magento\Quote\Model\ResourceModel\Quote::class, - [ - 'resource' => $this->resourceMock - ] + $this->quoteMock = $this->getMockBuilder(Quote::class) + ->disableOriginalConstructor() + ->getMock(); + $this->sequenceManagerMock = $this->getMockBuilder(Manager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->sequenceMock = $this->getMockBuilder(SequenceInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->quote = new \Magento\Quote\Model\ResourceModel\Quote( + $context, + $snapshot, + $relationComposite, + $this->sequenceManagerMock, + null ); } /** - * Unit test to verify if isOrderIncrementIdUsed method works with different types increment ids - * - * @param array $value - * @dataProvider isOrderIncrementIdUsedDataProvider + * @param $entityType + * @param $storeId + * @param $reservedOrderId + * @dataProvider getReservedOrderIdDataProvider */ - public function testIsOrderIncrementIdUsed($value) + public function testGetReservedOrderId($entityType, $storeId, $reservedOrderId) { - $expectedBind = [':increment_id' => $value]; - $this->adapterMock->expects($this->once())->method('fetchOne')->with($this->selectMock, $expectedBind); - $this->model->isOrderIncrementIdUsed($value); + $this->sequenceManagerMock->expects($this->once()) + ->method('getSequence') + ->with($entityType, $storeId) + ->willReturn($this->sequenceMock); + $this->quoteMock->expects($this->once()) + ->method('getStoreId') + ->willReturn($storeId); + $this->sequenceMock->expects($this->once()) + ->method('getNextValue') + ->willReturn($reservedOrderId); + + $this->assertEquals($reservedOrderId, $this->quote->getReservedOrderId($this->quoteMock)); } /** * @return array */ - public function isOrderIncrementIdUsedDataProvider() + public function getReservedOrderIdDataProvider(): array { - return [[100000001], ['10000000001'], ['M10000000001']]; + return [ + [\Magento\Sales\Model\Order::ENTITY, 1, '1000000001'], + [\Magento\Sales\Model\Order::ENTITY, 2, '2000000001'], + [\Magento\Sales\Model\Order::ENTITY, 3, '3000000001'] + ]; } } diff --git a/app/code/Magento/Quote/Test/Unit/Observer/Webapi/SubmitObserverTest.php b/app/code/Magento/Quote/Test/Unit/Observer/SubmitObserverTest.php similarity index 95% rename from app/code/Magento/Quote/Test/Unit/Observer/Webapi/SubmitObserverTest.php rename to app/code/Magento/Quote/Test/Unit/Observer/SubmitObserverTest.php index 618a633fd62e0..c19606a7b8f5d 100644 --- a/app/code/Magento/Quote/Test/Unit/Observer/Webapi/SubmitObserverTest.php +++ b/app/code/Magento/Quote/Test/Unit/Observer/SubmitObserverTest.php @@ -3,12 +3,12 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Quote\Test\Unit\Observer\Webapi; +namespace Magento\Quote\Test\Unit\Observer; class SubmitObserverTest extends \PHPUnit\Framework\TestCase { /** - * @var \Magento\Quote\Observer\Webapi\SubmitObserver + * @var \Magento\Quote\Observer\SubmitObserver */ protected $model; @@ -59,7 +59,7 @@ protected function setUp() $eventMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock); $eventMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock); $this->quoteMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock); - $this->model = new \Magento\Quote\Observer\Webapi\SubmitObserver( + $this->model = new \Magento\Quote\Observer\SubmitObserver( $this->loggerMock, $this->orderSenderMock ); diff --git a/app/code/Magento/Quote/composer.json b/app/code/Magento/Quote/composer.json index f15cb8c72e3bd..31f875a0f9a35 100644 --- a/app/code/Magento/Quote/composer.json +++ b/app/code/Magento/Quote/composer.json @@ -4,26 +4,26 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-customer": "100.2.*", + "magento/module-catalog": "102.0.*", + "magento/module-customer": "101.0.*", "magento/module-checkout": "100.2.*", "magento/module-authorization": "100.2.*", "magento/module-payment": "100.2.*", - "magento/module-sales": "100.2.*", + "magento/module-sales": "101.0.*", "magento/module-shipping": "100.2.*", "magento/module-sales-sequence": "100.2.*", "magento/module-backend": "100.2.*", "magento/module-directory": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-tax": "100.2.*", "magento/module-catalog-inventory": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "suggest": { "magento/module-webapi": "100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "101.0.2", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Quote/etc/frontend/events.xml b/app/code/Magento/Quote/etc/frontend/events.xml new file mode 100644 index 0000000000000..1e9822bbf3ef8 --- /dev/null +++ b/app/code/Magento/Quote/etc/frontend/events.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/code/Magento/Quote/etc/module.xml b/app/code/Magento/Quote/etc/module.xml index f682568e63d02..6607dea5809b1 100644 --- a/app/code/Magento/Quote/etc/module.xml +++ b/app/code/Magento/Quote/etc/module.xml @@ -6,6 +6,6 @@ */ --> - + diff --git a/app/code/Magento/Quote/etc/webapi_rest/events.xml b/app/code/Magento/Quote/etc/webapi_rest/events.xml index 7b94434f3f20a..1e9822bbf3ef8 100644 --- a/app/code/Magento/Quote/etc/webapi_rest/events.xml +++ b/app/code/Magento/Quote/etc/webapi_rest/events.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/Quote/etc/webapi_soap/events.xml b/app/code/Magento/Quote/etc/webapi_soap/events.xml index 7b94434f3f20a..1e9822bbf3ef8 100644 --- a/app/code/Magento/Quote/etc/webapi_soap/events.xml +++ b/app/code/Magento/Quote/etc/webapi_soap/events.xml @@ -7,6 +7,6 @@ --> - + diff --git a/app/code/Magento/QuoteAnalytics/LICENSE.txt b/app/code/Magento/QuoteAnalytics/LICENSE.txt new file mode 100644 index 0000000000000..49525fd99da9c --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/QuoteAnalytics/LICENSE_AFL.txt b/app/code/Magento/QuoteAnalytics/LICENSE_AFL.txt new file mode 100644 index 0000000000000..f39d641b18a19 --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/QuoteAnalytics/README.md b/app/code/Magento/QuoteAnalytics/README.md new file mode 100644 index 0000000000000..d4adcc9313229 --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/README.md @@ -0,0 +1,3 @@ +# Magento_QuoteAnalytics + +The Magento_QuoteAnalytics module configures data definitions for a data collection related to the Quote module entities to be used in [Advanced Reporting](http://devdocs.magento.com/guides/v2.2/advanced-reporting/modules.html). diff --git a/app/code/Magento/QuoteAnalytics/composer.json b/app/code/Magento/QuoteAnalytics/composer.json new file mode 100644 index 0000000000000..c75abc5bb5da2 --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/composer.json @@ -0,0 +1,23 @@ +{ + "name": "magento/module-quote-analytics", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/framework": "101.0.*", + "magento/module-quote": "101.0.*" + }, + "type": "magento2-module", + "version": "100.2.0", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\QuoteAnalytics\\": "" + } + } +} diff --git a/app/code/Magento/QuoteAnalytics/etc/analytics.xml b/app/code/Magento/QuoteAnalytics/etc/analytics.xml new file mode 100644 index 0000000000000..cc4dfb6364904 --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/etc/analytics.xml @@ -0,0 +1,18 @@ + + + + + + + + quotes + + + + + diff --git a/app/code/Magento/QuoteAnalytics/etc/module.xml b/app/code/Magento/QuoteAnalytics/etc/module.xml new file mode 100644 index 0000000000000..d72e36b748748 --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/etc/module.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/app/code/Magento/QuoteAnalytics/etc/reports.xml b/app/code/Magento/QuoteAnalytics/etc/reports.xml new file mode 100644 index 0000000000000..f57012df23389 --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/etc/reports.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/QuoteAnalytics/registration.php b/app/code/Magento/QuoteAnalytics/registration.php new file mode 100644 index 0000000000000..19718c3cf2adf --- /dev/null +++ b/app/code/Magento/QuoteAnalytics/registration.php @@ -0,0 +1,11 @@ +productMetadata = $productMetadata; + $this->notificationLogger = $notificationLogger; + $this->logger = $logger; + } + + /** + * Log information about the last shown advertisement + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + try { + $responseContent = [ + 'success' => $this->notificationLogger->log( + $this->_auth->getUser()->getId(), + $this->productMetadata->getVersion() + ), + 'error_message' => '' + ]; + } catch (LocalizedException $e) { + $this->logger->error($e->getMessage()); + $responseContent = [ + 'success' => false, + 'error_message' => $e->getMessage() + ]; + } catch (\Exception $e) { + $this->logger->error($e->getMessage()); + $responseContent = [ + 'success' => false, + 'error_message' => __('It is impossible to log user action') + ]; + } + $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); + return $resultJson->setData($responseContent); + } + + protected function _isAllowed() + { + return parent::_isAllowed(); + } +} diff --git a/app/code/Magento/ReleaseNotification/LICENSE.txt b/app/code/Magento/ReleaseNotification/LICENSE.txt new file mode 100644 index 0000000000000..49525fd99da9c --- /dev/null +++ b/app/code/Magento/ReleaseNotification/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/ReleaseNotification/LICENSE_AFL.txt b/app/code/Magento/ReleaseNotification/LICENSE_AFL.txt new file mode 100644 index 0000000000000..f39d641b18a19 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/ReleaseNotification/Model/Condition/CanViewNotification.php b/app/code/Magento/ReleaseNotification/Model/Condition/CanViewNotification.php new file mode 100644 index 0000000000000..07e26bb1a4d8d --- /dev/null +++ b/app/code/Magento/ReleaseNotification/Model/Condition/CanViewNotification.php @@ -0,0 +1,106 @@ +viewerLogger = $viewerLogger; + $this->session = $session; + $this->productMetadata = $productMetadata; + $this->cacheStorage = $cacheStorage; + } + + /** + * Validate if notification popup can be shown and set the notification flag + * + * @inheritdoc + */ + public function isVisible(array $arguments) + { + $userId = $this->session->getUser()->getId(); + $cacheKey = self::$cachePrefix . $userId; + $value = $this->cacheStorage->load($cacheKey); + if ($value === false) { + $value = version_compare( + $this->viewerLogger->get($userId)->getLastViewVersion(), + $this->productMetadata->getVersion(), + '<' + ); + $this->cacheStorage->save(false, $cacheKey); + } + return (bool)$value; + } + + /** + * Get condition name + * + * @return string + */ + public function getName() + { + return self::$conditionName; + } +} diff --git a/app/code/Magento/ReleaseNotification/Model/ResourceModel/Viewer/Logger.php b/app/code/Magento/ReleaseNotification/Model/ResourceModel/Viewer/Logger.php new file mode 100644 index 0000000000000..967ccabcdb49c --- /dev/null +++ b/app/code/Magento/ReleaseNotification/Model/ResourceModel/Viewer/Logger.php @@ -0,0 +1,103 @@ +resource = $resource; + $this->logFactory = $logFactory; + } + + /** + * Save (insert new or update existing) log. + * + * @param int $viewerId + * @param string $lastViewVersion + * @return bool + */ + public function log(int $viewerId, string $lastViewVersion) : bool + { + /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */ + $connection = $this->resource->getConnection(ResourceConnection::DEFAULT_CONNECTION); + $connection->insertOnDuplicate( + $this->resource->getTableName(self::LOG_TABLE_NAME), + [ + 'viewer_id' => $viewerId, + 'last_view_version' => $lastViewVersion + ], + [ + 'last_view_version' + ] + ); + return true; + } + + /** + * Get log by viewer Id. + * + * @param int $viewerId + * @return Log + */ + public function get(int $viewerId) : Log + { + return $this->logFactory->create(['data' => $this->loadLogData($viewerId)]); + } + + /** + * Load release notification viewer log data by viewer id + * + * @param int $viewerId + * @return array + */ + private function loadLogData(int $viewerId) : array + { + $connection = $this->resource->getConnection(); + $select = $connection->select() + ->from($this->resource->getTableName(self::LOG_TABLE_NAME)) + ->where('viewer_id = ?', $viewerId); + + $data = $connection->fetchRow($select); + if (!$data) { + $data = []; + } + return $data; + } +} diff --git a/app/code/Magento/ReleaseNotification/Model/Viewer/Log.php b/app/code/Magento/ReleaseNotification/Model/Viewer/Log.php new file mode 100644 index 0000000000000..27100b62fa798 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/Model/Viewer/Log.php @@ -0,0 +1,46 @@ +getData('id'); + } + + /** + * Get viewer id + * + * @return int + */ + public function getViewerId() + { + return $this->getData('viewer_id'); + } + + /** + * Get last viewed product version + * + * @return string + */ + public function getLastViewVersion() + { + return $this->getData('last_view_version'); + } +} diff --git a/app/code/Magento/ReleaseNotification/README.md b/app/code/Magento/ReleaseNotification/README.md new file mode 100644 index 0000000000000..bb0a6e7f4cf80 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/README.md @@ -0,0 +1,11 @@ + # Magento_ReleaseNotification Module + +The **Release Notification Module** serves to provide a notification delivery platform for displaying new features of a Magento installation or upgrade as well as any other required release notifications. + +## Purpose and Content + +* Provides a method of notifying administrators of changes, features, and functionality being introduced in a Magento release +* Displays a modal containing a high level overview of the features included in the installed or upgraded release of Magento upon the initial login of each administrator into the Admin Panel for a given Magento version +* The modal is enabled with pagination functionality to allow for easy navigation between each modal page +* Each modal page includes detailed information about a highlighted feature of the Magento release or other notification +* Release Notification modal content is determined and provided by Magento Marketing diff --git a/app/code/Magento/ReleaseNotification/Setup/InstallSchema.php b/app/code/Magento/ReleaseNotification/Setup/InstallSchema.php new file mode 100644 index 0000000000000..a6a0f51befa3f --- /dev/null +++ b/app/code/Magento/ReleaseNotification/Setup/InstallSchema.php @@ -0,0 +1,69 @@ +startSetup(); + + /** + * Create table 'release_notification_viewer_log' + */ + $table = $setup->getConnection()->newTable( + $setup->getTable('release_notification_viewer_log') + )->addColumn( + 'id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], + 'Log ID' + )->addColumn( + 'viewer_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['unsigned' => true, 'nullable' => false], + 'Viewer admin user ID' + )->addColumn( + 'last_view_version', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 16, + ['nullable' => false], + 'Viewer last view on product version' + )->addIndex( + $setup->getIdxName( + 'release_notification_viewer_log', + ['viewer_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE + ), + ['viewer_id'], + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] + )->addForeignKey( + $setup->getFkName('release_notification_viewer_log', 'viewer_id', 'admin_user', 'user_id'), + 'viewer_id', + $setup->getTable('admin_user'), + 'user_id', + Table::ACTION_CASCADE + )->setComment( + 'Release Notification Viewer Log Table' + ); + $setup->getConnection()->createTable($table); + + $setup->endSetup(); + } +} diff --git a/app/code/Magento/ReleaseNotification/Test/Unit/Controller/Notification/MarkUserNotifiedTest.php b/app/code/Magento/ReleaseNotification/Test/Unit/Controller/Notification/MarkUserNotifiedTest.php new file mode 100644 index 0000000000000..894368cbcba01 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/Test/Unit/Controller/Notification/MarkUserNotifiedTest.php @@ -0,0 +1,189 @@ +storageMock = $this->getMockBuilder(StorageInterface::class) + ->setMethods(['getId']) + ->getMockForAbstractClass(); + $this->authMock = $this->getMockBuilder(Auth::class) + ->disableOriginalConstructor() + ->getMock(); + $contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->getMock(); + $contextMock->expects($this->once()) + ->method('getAuth') + ->willReturn($this->authMock); + $this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class) + ->getMockForAbstractClass(); + $this->notificationLoggerMock = $this->getMockBuilder(NotificationLogger::class) + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) + ->getMock(); + $resultFactoryMock = $this->getMockBuilder(ResultFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resultMock = $this->getMockBuilder(Json::class) + ->disableOriginalConstructor() + ->getMock(); + $resultFactoryMock->expects($this->once()) + ->method('create') + ->with(ResultFactory::TYPE_JSON) + ->willReturn($this->resultMock); + $objectManagerHelper = new ObjectManagerHelper($this); + $this->action = $objectManagerHelper->getObject( + MarkUserNotified::class, + [ + 'resultFactory' => $resultFactoryMock, + 'productMetadata' => $this->productMetadataMock, + 'notificationLogger' => $this->notificationLoggerMock, + 'context' => $contextMock, + 'logger' => $this->loggerMock + ] + ); + } + + public function testExecuteSuccess() + { + $this->authMock->expects($this->once()) + ->method('getUser') + ->willReturn($this->storageMock); + $this->storageMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->productMetadataMock->expects($this->once()) + ->method('getVersion') + ->willReturn('999.999.999-alpha'); + $this->notificationLoggerMock->expects($this->once()) + ->method('log') + ->with(1, '999.999.999-alpha') + ->willReturn(true); + $this->resultMock->expects($this->once()) + ->method('setData') + ->with( + [ + 'success' => true, + 'error_message' => '' + ], + false, + [] + )->willReturnSelf(); + $this->assertEquals($this->resultMock, $this->action->execute()); + } + + public function testExecuteFailedWithLocalizedException() + { + $this->authMock->expects($this->once()) + ->method('getUser') + ->willReturn($this->storageMock); + $this->storageMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->productMetadataMock->expects($this->once()) + ->method('getVersion') + ->willReturn('999.999.999-alpha'); + $this->notificationLoggerMock->expects($this->once()) + ->method('log') + ->willThrowException(new LocalizedException(__('Error message'))); + $this->resultMock->expects($this->once()) + ->method('setData') + ->with( + [ + 'success' => false, + 'error_message' => 'Error message' + ], + false, + [] + )->willReturnSelf(); + $this->assertEquals($this->resultMock, $this->action->execute()); + } + + public function testExecuteFailedWithException() + { + $this->authMock->expects($this->once()) + ->method('getUser') + ->willReturn($this->storageMock); + $this->storageMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->productMetadataMock->expects($this->once()) + ->method('getVersion') + ->willReturn('999.999.999-alpha'); + $this->notificationLoggerMock->expects($this->once()) + ->method('log') + ->willThrowException(new \Exception('Any message')); + $this->resultMock->expects($this->once()) + ->method('setData') + ->with( + [ + 'success' => false, + 'error_message' => __('It is impossible to log user action') + ], + false, + [] + )->willReturnSelf(); + $this->assertEquals($this->resultMock, $this->action->execute()); + } +} diff --git a/app/code/Magento/ReleaseNotification/Test/Unit/Model/Condition/CanViewNotificationTest.php b/app/code/Magento/ReleaseNotification/Test/Unit/Model/Condition/CanViewNotificationTest.php new file mode 100644 index 0000000000000..3ec00697507c1 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/Test/Unit/Model/Condition/CanViewNotificationTest.php @@ -0,0 +1,128 @@ +cacheStorageMock = $this->getMockBuilder(CacheInterface::class) + ->getMockForAbstractClass(); + $this->logMock = $this->getMockBuilder(Log::class) + ->getMock(); + $this->sessionMock = $this->getMockBuilder(Session::class) + ->disableOriginalConstructor() + ->setMethods(['getUser', 'getId']) + ->getMock(); + $this->viewerLoggerMock = $this->getMockBuilder(Logger::class) + ->disableOriginalConstructor() + ->getMock(); + $this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $objectManager = new ObjectManager($this); + $this->canViewNotification = $objectManager->getObject( + CanViewNotification::class, + [ + 'viewerLogger' => $this->viewerLoggerMock, + 'session' => $this->sessionMock, + 'productMetadata' => $this->productMetadataMock, + 'cacheStorage' => $this->cacheStorageMock, + ] + ); + } + + public function testIsVisibleLoadDataFromCache() + { + $this->sessionMock->expects($this->once()) + ->method('getUser') + ->willReturn($this->sessionMock); + $this->sessionMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->cacheStorageMock->expects($this->once()) + ->method('load') + ->with('release-notification-popup-1') + ->willReturn("0"); + $this->assertEquals(false, $this->canViewNotification->isVisible([])); + } + + /** + * @param bool $expected + * @param string $version + * @param string|null $lastViewVersion + * @dataProvider isVisibleProvider + */ + public function testIsVisible($expected, $version, $lastViewVersion) + { + $this->cacheStorageMock->expects($this->once()) + ->method('load') + ->with('release-notification-popup-1') + ->willReturn(false); + $this->sessionMock->expects($this->once()) + ->method('getUser') + ->willReturn($this->sessionMock); + $this->sessionMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->productMetadataMock->expects($this->once()) + ->method('getVersion') + ->willReturn($version); + $this->logMock->expects($this->once()) + ->method('getLastViewVersion') + ->willReturn($lastViewVersion); + $this->viewerLoggerMock->expects($this->once()) + ->method('get') + ->with(1) + ->willReturn($this->logMock); + $this->cacheStorageMock->expects($this->once()) + ->method('save') + ->with(false, 'release-notification-popup-1'); + $this->assertEquals($expected, $this->canViewNotification->isVisible([])); + } + + public function isVisibleProvider() + { + return [ + [false, '2.2.1-dev', '999.999.999-alpha'], + [true, '2.2.1-dev', '2.0.0'], + [true, '2.2.1-dev', null], + [false, '2.2.1-dev', '2.2.1'], + [true, '2.2.1-dev', '2.2.0'], + [true, '2.3.0', '2.2.0'], + [false, '2.2.2', '2.2.2'], + ]; + } +} diff --git a/app/code/Magento/ReleaseNotification/Ui/DataProvider/DataProvider.php b/app/code/Magento/ReleaseNotification/Ui/DataProvider/DataProvider.php new file mode 100644 index 0000000000000..48f01b3b058e2 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/Ui/DataProvider/DataProvider.php @@ -0,0 +1,198 @@ +name = $name; + $this->searchResult = $searchResult; + $this->searchCriteria = $searchCriteria; + $this->collection = $collection; + $this->data = $data; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function getConfigData() + { + return isset($this->data['config']) ? $this->data['config'] : []; + } + + /** + * {@inheritdoc} + */ + public function setConfigData($config) + { + $this->data['config'] = $config; + + return true; + } + + /** + * {@inheritdoc} + */ + public function getMeta() + { + return []; + } + + /** + * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getFieldMetaInfo($fieldSetName, $fieldName) + { + return []; + } + + /** + * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getFieldSetMetaInfo($fieldSetName) + { + return []; + } + + /** + * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getFieldsMetaInfo($fieldSetName) + { + return []; + } + + /** + * {@inheritdoc} + */ + public function getPrimaryFieldName() + { + return 'release_notification'; + } + + /** + * {@inheritdoc} + */ + public function getRequestFieldName() + { + return 'release_notification'; + } + + /** + * {@inheritdoc} + */ + public function getData() + { + return $this->collection->toArray(); + } + + /** + * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function addFilter(\Magento\Framework\Api\Filter $filter) + { + } + + /** + * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function addOrder($field, $direction) + { + } + + /** + * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setLimit($offset, $size) + { + } + + /** + * {@inheritdoc} + */ + public function getSearchCriteria() + { + return $this->searchCriteria; + } + + /** + * {@inheritdoc} + */ + public function getSearchResult() + { + return $this->searchResult; + } +} diff --git a/app/code/Magento/ReleaseNotification/composer.json b/app/code/Magento/ReleaseNotification/composer.json new file mode 100644 index 0000000000000..40e9e02db9217 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/composer.json @@ -0,0 +1,24 @@ +{ + "name": "magento/module-release-notification", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/module-user": "101.0.*", + "magento/module-backend": "100.2.*", + "magento/framework": "101.0.*" + }, + "type": "magento2-module", + "version": "100.2.0", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\ReleaseNotification\\": "" + } + } +} diff --git a/app/code/Magento/ReleaseNotification/etc/adminhtml/routes.xml b/app/code/Magento/ReleaseNotification/etc/adminhtml/routes.xml new file mode 100644 index 0000000000000..4b1ddc69ce3bd --- /dev/null +++ b/app/code/Magento/ReleaseNotification/etc/adminhtml/routes.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/ReleaseNotification/etc/module.xml b/app/code/Magento/ReleaseNotification/etc/module.xml new file mode 100644 index 0000000000000..134d82e4f5776 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/etc/module.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/app/code/Magento/ReleaseNotification/i18n/en_US.csv b/app/code/Magento/ReleaseNotification/i18n/en_US.csv new file mode 100644 index 0000000000000..4a3cd02782b9c --- /dev/null +++ b/app/code/Magento/ReleaseNotification/i18n/en_US.csv @@ -0,0 +1,112 @@ +"Next >","Next >" +"< Back","< Back" +"Done","Done" +"What's new with Magento 2.2.2","What's new with Magento 2.2.2" +"

        Magento 2.2.2 offers advanced new features, including:

        +
        +
        +

        Advanced Reporting

        +

        Gain valuable insights through a dynamic suite of product, order, and customer reports, + powered by Magento Business Intelligence.

        +
        +
        +

        Instant Purchase

        +

        Simplify ordering and boost conversion rates by allowing your customers to use stored + payment and shipping information to skip tedious checkout steps.

        +
        +
        +

        Email Marketing Automation

        +

        Send smarter, faster email campaigns with marketing automation from dotmailer, powered by + your Magento store's live data.

        +
        +

        Release notes and additional details can be found at + Magento DevDocs. +

        ","

        Magento 2.2.2 offers advanced new features, including:

        +
        +
        +

        Advanced Reporting

        +

        Gain valuable insights through a dynamic suite of product, order, and customer reports, + powered by Magento Business Intelligence.

        +
        +
        +

        Instant Purchase

        +

        Simplify ordering and boost conversion rates by allowing your customers to use stored + payment and shipping information to skip tedious checkout steps.

        +
        +
        +

        Email Marketing Automation

        +

        Send smarter, faster email campaigns with marketing automation from dotmailer, powered by + your Magento store's live data.

        +
        +

        Release notes and additional details can be found at + Magento DevDocs. +

        " +"Advanced Reporting","Advanced Reporting" +"

        Advanced Reporting + provides you with a dynamic suite of reports with rich insights about the health of your + business.


        As part of the Advanced Reporting service, we may also use your customer + data for such purposes as benchmarking, improving our products and services, and providing you + with new and improved analytics.


        By using Magento 2.2.2, you agree to the Advanced + Reporting Privacy Policy and + Terms + of Service. You may opt out at any time from the Stores Configuration page.

        + ","

        Advanced Reporting + provides you with a dynamic suite of reports with rich insights about the health of your + business.


        As part of the Advanced Reporting service, we may also use your customer + data for such purposes as benchmarking, improving our products and services, and providing you + with new and improved analytics.


        By using Magento 2.2.2, you agree to the Advanced + Reporting Privacy Policy and + Terms + of Service. You may opt out at any time from the Stores Configuration page.

        " +"Instant Purchase","Instant Purchase" +"

        Now you can deliver an Amazon-like experience with a new, streamlined checkout option. + Logged-in customers can use previously-stored payment credentials and shipping information + to skip steps, making the process faster and easier, especially for mobile shoppers. Key + features include: +

        +
          +
        • Configurable “Instant Purchase” button to place orders.
        • +
        • Support for all payment solutions using Braintree Vault, including Braintree Credit + Card, Braintree PayPal, and PayPal Payflow Pro.
        • +
        • Shipping to the customer’s default address using the lowest cost, available shipping + method.
        • +
        • Ability for developers to customize the Instant Purchase business logic to meet + merchant needs.
        • +
        ","

        Now you can deliver an Amazon-like experience with a new, streamlined checkout option. + Logged-in customers can use previously-stored payment credentials and shipping information + to skip steps, making the process faster and easier, especially for mobile shoppers. Key + features include: +

        +
          +
        • Configurable “Instant Purchase” button to place orders.
        • +
        • Support for all payment solutions using Braintree Vault, including Braintree Credit + Card, Braintree PayPal, and PayPal Payflow Pro.
        • +
        • Shipping to the customer’s default address using the lowest cost, available shipping + method.
        • +
        • Ability for developers to customize the Instant Purchase business logic to meet + merchant needs.
        • +
        " +"Email Marketing Automation","Email Marketing Automation" +"

        Unlock an unparalleled level of insight and control of your eCommerce marketing with + dotmailer Email Marketing Automation. Included with Magento 2.2.2 for easy set-up, dotmailer + ensures every customer’s journey is captured, segmented, and personalized, enabling you to + deliver customer-centric campaigns that beat your results over and over again. Benefits include: +

        +
          +
        • No obligation 14-day trial.
        • +
        • Automation campaigns using your live Magento store data that drive revenue, + including abandoned cart, abandoned browse, product replenishment, and many more
        • +
        • Built-in solution for transactional emails.
        • +
        • Telephone support and advice from marketing experts included.
        • +
        ","

        Unlock an unparalleled level of insight and control of your eCommerce marketing with + dotmailer Email Marketing Automation. Included with Magento 2.2.2 for easy set-up, dotmailer + ensures every customer’s journey is captured, segmented, and personalized, enabling you to + deliver customer-centric campaigns that beat your results over and over again. Benefits include: +

        +
          +
        • No obligation 14-day trial.
        • +
        • Automation campaigns using your live Magento store data that drive revenue, + including abandoned cart, abandoned browse, product replenishment, and many more
        • +
        • Built-in solution for transactional emails.
        • +
        • Telephone support and advice from marketing experts included.
        • +
        " diff --git a/app/code/Magento/ReleaseNotification/registration.php b/app/code/Magento/ReleaseNotification/registration.php new file mode 100644 index 0000000000000..c5bce27f20387 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/registration.php @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/app/code/Magento/ReleaseNotification/view/adminhtml/ui_component/release_notification.xml b/app/code/Magento/ReleaseNotification/view/adminhtml/ui_component/release_notification.xml new file mode 100644 index 0000000000000..0364750d56a38 --- /dev/null +++ b/app/code/Magento/ReleaseNotification/view/adminhtml/ui_component/release_notification.xml @@ -0,0 +1,377 @@ + + +
        + + + release_notification.release_notification_data_source + + Release Notification + templates/form/collapsible + + + release_notification + data + + release_notification.release_notification_data_source + + + + + + + + + + + + + + + Magento_Ui/js/form/provider + + + + + + + actionCancel + true + + + + + + + + + +
        + + + + + + + release-notification-text + Magento 2.2.2 offers advanced new features, including:

        +
        +
        +

        Advanced Reporting

        +

        Gain valuable insights through a dynamic suite of product, order, and customer reports, + powered by Magento Business Intelligence.

        +
        +
        +

        Instant Purchase

        +

        Simplify ordering and boost conversion rates by allowing your customers to use stored + payment and shipping information to skip tedious checkout steps.

        +
        + +

        Release notes and additional details can be found at + Magento DevDocs. +

        ]]> +
        +
        +
        +
        + + + + + + + + +
        +
        + + + actionCancel + + + + + + + + + +
        + + + + + + + release-notification-text + Advanced Reporting + provides you with a dynamic suite of reports with rich insights about the health of your + business.


        As part of the Advanced Reporting service, we may also use your customer + data for such purposes as benchmarking, improving our products and services, and providing you + with new and improved analytics.


        By using Magento 2.2.2, you agree to the Advanced + Reporting Privacy Policy + and Terms + of Service. You may opt out at any time from the Stores Configuration page.

        ]]> +
        +
        +
        +
        + + + + + + + + + +
        +
        + + + actionCancel + + + + + + + + + +
        + + + + + + + release-notification-text + Now you can deliver an Amazon-like experience with a new, streamlined checkout option. + Logged-in customers can use previously-stored payment credentials and shipping information + to skip steps, making the process faster and easier, especially for mobile shoppers. Key + features include: +

        +
          +
        • Configurable “Instant Purchase” button to place orders.
        • +
        • Support for all payment solutions using Braintree Vault, including Braintree Credit + Card, Braintree PayPal, and PayPal Payflow Pro.
        • +
        • Shipping to the customer’s default address using the lowest cost, available shipping + method.
        • +
        • Ability for developers to customize the Instant Purchase business logic to meet + merchant needs.
        • +
        ]]> +
        +
        +
        +
        + + + + + + + + + +
        +
        + + + actionCancel + + + + + + + + + +
        + + + + + + + release-notification-text + Unlock an unparalleled level of insight and control of your eCommerce marketing with + dotmailer Email Marketing Automation. Included with Magento 2.2.2 for easy set-up, dotmailer + ensures every customer’s journey is captured, segmented, and personalized, enabling you to + deliver customer-centric campaigns that beat your results over and over again. Benefits include: +

        +
          +
        • No obligation 14-day trial.
        • +
        • Automation campaigns using your live Magento store data that drive revenue, + including abandoned cart, abandoned browse, product replenishment, and many more.
        • +
        • Built-in solution for transactional emails.
        • +
        • Telephone support and advice from marketing experts included.
        • +
        ]]> +
        +
        +
        +
        + + + + + + + + + +
        +
        +
        diff --git a/app/code/Magento/ReleaseNotification/view/adminhtml/web/js/modal/component.js b/app/code/Magento/ReleaseNotification/view/adminhtml/web/js/modal/component.js new file mode 100644 index 0000000000000..b74ef2af1a04d --- /dev/null +++ b/app/code/Magento/ReleaseNotification/view/adminhtml/web/js/modal/component.js @@ -0,0 +1,65 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', + 'Magento_Ui/js/modal/modal-component', + 'Magento_Ui/js/modal/alert', + 'mage/translate' +], function ($, Modal, alert, $t) { + 'use strict'; + + return Modal.extend({ + defaults: { + imports: { + logAction: '${ $.provider }:data.logAction' + } + }, + + /** + * Error handler. + * + * @param {Object} xhr - request result. + */ + onError: function (xhr) { + if (xhr.statusText === 'abort') { + return; + } + + alert({ + content: xhr.message || $t('An error occurred while logging process.') + }); + }, + + /** + * Log release notes show + */ + logReleaseNotesShow: function () { + var self = this, + data = { + 'form_key': window.FORM_KEY + }; + + $.ajax({ + type: 'POST', + url: this.logAction, + data: data, + showLoader: true + }).done(function (xhr) { + if (xhr.error) { + self.onError(xhr); + } + }).fail(this.onError); + }, + + /** + * Close release notes + */ + closeReleaseNotes: function () { + this.logReleaseNotesShow(); + this.closeModal(); + } + }); +}); diff --git a/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php b/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php index 48a87bf77cf94..158455db26455 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php @@ -363,12 +363,11 @@ public function setStoreIds($storeIds) public function getCurrentCurrencyCode() { if ($this->_currentCurrencyCode === null) { - $this->_currentCurrencyCode = count( - $this->_storeIds - ) > 0 ? $this->_storeManager->getStore( - array_shift($this->_storeIds) - )->getBaseCurrencyCode() : $this->_storeManager->getStore()->getBaseCurrencyCode(); + $this->_currentCurrencyCode = count($this->_storeIds) > 0 + ? $this->_storeManager->getStore(array_shift($this->_storeIds))->getCurrentCurrencyCode() + : $this->_storeManager->getStore()->getBaseCurrencyCode(); } + return $this->_currentCurrencyCode; } diff --git a/app/code/Magento/Reports/Block/Adminhtml/Product/Lowstock/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Product/Lowstock/Grid.php index 653dabb71e21d..5460dab3a7ff8 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Product/Lowstock/Grid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Product/Lowstock/Grid.php @@ -53,14 +53,12 @@ protected function _prepareCollection() } elseif ($store) { $storeId = (int)$store; } else { - $storeId = ''; + $storeId = null; } /** @var $collection \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection */ $collection = $this->_lowstocksFactory->create()->addAttributeToSelect( '*' - )->setStoreId( - $storeId )->filterByIsQtyProductTypes()->joinInventoryItem( 'qty' )->useManageStockFilter( diff --git a/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php index cc21b8dc98395..337c87f6da03d 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php @@ -298,7 +298,7 @@ public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) } /** - * Add views count + * Add views count. * * @param string $from * @param string $to @@ -322,10 +322,7 @@ public function addViewsCount($from = '', $to = '') ['views' => 'COUNT(report_table_views.event_id)'] )->join( ['e' => $this->getProductEntityTableName()], - $this->getConnection()->quoteInto( - 'e.entity_id = report_table_views.object_id AND e.attribute_set_id = ?', - $this->getProductAttributeSetId() - ) + 'e.entity_id = report_table_views.object_id' )->where( 'report_table_views.event_type_id = ?', $productViewEvent @@ -341,6 +338,7 @@ public function addViewsCount($from = '', $to = '') if ($from != '' && $to != '') { $this->getSelect()->where('logged_at >= ?', $from)->where('logged_at <= ?', $to); } + return $this; } diff --git a/app/code/Magento/Reports/Model/ResourceModel/Product/Sold/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Product/Sold/Collection.php index cf6455f3cab64..61dc77d188438 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Product/Sold/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Product/Sold/Collection.php @@ -65,17 +65,19 @@ public function addOrderedQty($from = '', $to = '') $this->getSelect()->reset()->from( ['order_items' => $this->getTable('sales_order_item')], - ['ordered_qty' => 'SUM(order_items.qty_ordered)', 'order_items_name' => 'order_items.name'] + [ + 'ordered_qty' => 'order_items.qty_ordered', + 'order_items_name' => 'order_items.name', + 'order_items_sku' => 'order_items.sku' + ] )->joinInner( ['order' => $this->getTable('sales_order')], implode(' AND ', $orderJoinCondition), [] )->where( - 'parent_item_id IS NULL' - )->group( - 'order_items.product_id' + 'order_items.parent_item_id IS NULL' )->having( - 'SUM(order_items.qty_ordered) > ?', + 'order_items.qty_ordered > ?', 0 ); return $this; diff --git a/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php index 6e891c481aebe..d219aefe81d45 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php @@ -192,7 +192,7 @@ protected function getProductData(array $productIds) . ' AND product_name.attribute_id = ' . $productAttrNameId . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, ['name' => 'product_name.value'] - )->joinInner( + )->joinLeft( ['product_price' => $productAttrPrice->getBackend()->getTable()], "product_price.{$linkField} = main_table.{$linkField}" ." AND product_price.attribute_id = {$productAttrPriceId}", @@ -220,8 +220,10 @@ protected function _afterLoad() $orderData = $this->getOrdersData($productIds); foreach ($items as $item) { $item->setId($item->getProductId()); - $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate()); - $item->setName($productData[$item->getProductId()]['name']); + if (isset($productData[$item->getProductId()])) { + $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate()); + $item->setName($productData[$item->getProductId()]['name']); + } $item->setOrders(0); if (isset($orderData[$item->getProductId()])) { $item->setOrders($orderData[$item->getProductId()]['orders']); diff --git a/app/code/Magento/Reports/Model/ResourceModel/Review/Customer/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Review/Customer/Collection.php index a832823967647..02eae4d75d2a7 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Review/Customer/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Review/Customer/Collection.php @@ -103,6 +103,21 @@ protected function _joinCustomers() return $this; } + /** + * {@inheritdoc} + * + * Additional processing of 'customer_name' field is required, as it is a concat field, which can not be aliased. + * @see _joinCustomers + */ + public function addFieldToFilter($field, $condition = null) + { + if ($field === 'customer_name') { + $field = $this->getConnection()->getConcatSql(['customer.firstname', 'customer.lastname'], ' '); + } + + return parent::addFieldToFilter($field, $condition); + } + /** * Get select count sql * @@ -110,13 +125,14 @@ protected function _joinCustomers() */ public function getSelectCountSql() { - $countSelect = clone $this->_select; + $countSelect = clone $this->getSelect(); $countSelect->reset(\Magento\Framework\DB\Select::ORDER); $countSelect->reset(\Magento\Framework\DB\Select::GROUP); $countSelect->reset(\Magento\Framework\DB\Select::HAVING); $countSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT); $countSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET); $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS); + $countSelect->reset(\Magento\Framework\DB\Select::WHERE); $countSelect->columns(new \Zend_Db_Expr('COUNT(DISTINCT detail.customer_id)')); diff --git a/app/code/Magento/Reports/Setup/InstallData.php b/app/code/Magento/Reports/Setup/InstallData.php index 66ee0d9f288bc..2ef7f9507380d 100644 --- a/app/code/Magento/Reports/Setup/InstallData.php +++ b/app/code/Magento/Reports/Setup/InstallData.php @@ -83,8 +83,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface // @codingStandardsIgnoreStart $reportLayoutUpdate = ''; // @codingStandardsIgnoreEnd diff --git a/app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Grid/AbstractGridTest.php b/app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Grid/AbstractGridTest.php new file mode 100644 index 0000000000000..dc16928861b1c --- /dev/null +++ b/app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Grid/AbstractGridTest.php @@ -0,0 +1,91 @@ +storeManagerMock = $this->getMockForAbstractClass( + \Magento\Store\Model\StoreManagerInterface::class, + [], + '', + true, + true, + true, + ['getStore'] + ); + + $this->model = $objectManager->getObject( + \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid::class, + ['_storeManager' => $this->storeManagerMock] + ); + } + + /** + * @param $storeIds + * + * @dataProvider getCurrentCurrencyCodeDataProvider + */ + public function testGetCurrentCurrencyCode($storeIds) + { + $storeMock = $this->getMockForAbstractClass( + \Magento\Store\Api\Data\StoreInterface::class, + [], + '', + true, + true, + true, + ['getBaseCurrencyCode', 'getCurrentCurrencyCode'] + ); + + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + + $this->model->setStoreIds($storeIds); + + if ($storeIds) { + $storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn('EUR'); + $expectedCurrencyCode = 'EUR'; + } else { + $storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD'); + $expectedCurrencyCode = 'USD'; + } + + $currencyCode = $this->model->getCurrentCurrencyCode(); + $this->assertEquals($expectedCurrencyCode, $currencyCode); + } + + /** + * DataProvider for testGetCurrentCurrencyCode. + * + * @return array + */ + public function getCurrentCurrencyCodeDataProvider() + { + return [ + [[]], + [[2]], + ]; + } +} diff --git a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php new file mode 100644 index 0000000000000..038d37a990442 --- /dev/null +++ b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php @@ -0,0 +1,286 @@ +objectManager = new ObjectManager($this); + $context = $this->createPartialMock(Context::class, ['getResource', 'getEavConfig']); + $entityFactoryMock = $this->createMock(EntityFactory::class); + $loggerMock = $this->createMock(LoggerInterface::class); + $fetchStrategyMock = $this->createMock(FetchStrategyInterface::class); + $eventManagerMock = $this->createMock(ManagerInterface::class); + $eavConfigMock = $this->createMock(Config::class); + $this->resourceMock = $this->createPartialMock(ResourceConnection::class, ['getTableName', 'getConnection']); + $eavEntityFactoryMock = $this->createMock(EavEntityFactory::class); + $resourceHelperMock = $this->createMock(Helper::class); + $universalFactoryMock = $this->createMock(UniversalFactory::class); + $storeManagerMock = $this->createPartialMockForAbstractClass( + StoreManagerInterface::class, + ['getStore', 'getId'] + ); + $moduleManagerMock = $this->createMock(Manager::class); + $productFlatStateMock = $this->createMock(State::class); + $scopeConfigMock = $this->createMock(ScopeConfigInterface::class); + $optionFactoryMock = $this->createMock(OptionFactory::class); + $catalogUrlMock = $this->createMock(Url::class); + $localeDateMock = $this->createMock(TimezoneInterface::class); + $customerSessionMock = $this->createMock(Session::class); + $dateTimeMock = $this->createMock(DateTime::class); + $groupManagementMock = $this->createMock(GroupManagementInterface::class); + $eavConfig = $this->createPartialMock(Config::class, ['getEntityType']); + $entityType = $this->createMock(Type::class); + + $eavConfig->expects($this->atLeastOnce())->method('getEntityType')->willReturn($entityType); + $context->expects($this->atLeastOnce())->method('getResource')->willReturn($this->resourceMock); + $context->expects($this->atLeastOnce())->method('getEavConfig')->willReturn($eavConfig); + + $defaultAttributes = $this->createPartialMock(DefaultAttributes::class, ['_getDefaultAttributes']); + $productMock = $this->objectManager->getObject( + ResourceProduct::class, + ['context' => $context, 'defaultAttributes' => $defaultAttributes] + ); + + $this->eventTypeFactoryMock = $this->createMock(TypeFactory::class); + $productTypeMock = $this->createMock(ProductType::class); + $quoteResourceMock = $this->createMock(Collection::class); + $this->connectionMock = $this->createPartialMockForAbstractClass(AdapterInterface::class, ['select']); + $this->selectMock = $this->createPartialMock( + Select::class, + [ + 'reset', + 'from', + 'join', + 'where', + 'group', + 'order', + 'having', + ] + ); + + $storeManagerMock->expects($this->atLeastOnce())->method('getStore')->willReturn($storeManagerMock); + $storeManagerMock->expects($this->atLeastOnce())->method('getId')->willReturn(1); + $universalFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($productMock); + $this->resourceMock->expects($this->atLeastOnce())->method('getTableName')->willReturn('test_table'); + $this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->connectionMock); + $this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock); + + $this->collection = new ProductCollection( + $entityFactoryMock, + $loggerMock, + $fetchStrategyMock, + $eventManagerMock, + $eavConfigMock, + $this->resourceMock, + $eavEntityFactoryMock, + $resourceHelperMock, + $universalFactoryMock, + $storeManagerMock, + $moduleManagerMock, + $productFlatStateMock, + $scopeConfigMock, + $optionFactoryMock, + $catalogUrlMock, + $localeDateMock, + $customerSessionMock, + $dateTimeMock, + $groupManagementMock, + $productMock, + $this->eventTypeFactoryMock, + $productTypeMock, + $quoteResourceMock, + $this->connectionMock + ); + } + + /** + * Test addViewsCount behavior. + */ + public function testAddViewsCount() + { + $context = $this->createPartialMock( + \Magento\Framework\Model\ResourceModel\Db\Context::class, + ['getResources'] + ); + $context->expects($this->atLeastOnce()) + ->method('getResources') + ->willReturn($this->resourceMock); + $abstractResourceMock = $this->getMockForAbstractClass( + \Magento\Framework\Model\ResourceModel\Db\AbstractDb::class, + ['context' => $context], + '', + true, + true, + true, + [ + 'getTableName', + 'getConnection', + 'getMainTable', + ] + ); + + $abstractResourceMock->expects($this->atLeastOnce()) + ->method('getConnection') + ->willReturn($this->connectionMock); + $abstractResourceMock->expects($this->atLeastOnce()) + ->method('getMainTable') + ->willReturn('catalog_product'); + + /** @var \Magento\Reports\Model\ResourceModel\Event\Type\Collection $eventTypesCollection */ + $eventTypesCollection = $this->objectManager->getObject( + \Magento\Reports\Model\ResourceModel\Event\Type\Collection::class, + ['resource' => $abstractResourceMock] + ); + $eventTypeMock = $this->createPartialMock( + \Magento\Reports\Model\Event\Type::class, + [ + 'getEventName', + 'getId', + 'getCollection', + ] + ); + + $eventTypesCollection->addItem($eventTypeMock); + + $this->eventTypeFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($eventTypeMock); + $eventTypeMock->expects($this->atLeastOnce()) + ->method('getCollection') + ->willReturn($eventTypesCollection); + $eventTypeMock->expects($this->atLeastOnce()) + ->method('getEventName') + ->willReturn('catalog_product_view'); + $eventTypeMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn(1); + + $this->selectMock->expects($this->atLeastOnce()) + ->method('reset') + ->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce()) + ->method('from') + ->with( + ['report_table_views' => 'test_table'], + ['views' => 'COUNT(report_table_views.event_id)'] + )->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce()) + ->method('join') + ->with( + ['e' => 'test_table'], + 'e.entity_id = report_table_views.object_id' + )->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce()) + ->method('where') + ->with('report_table_views.event_type_id = ?', 1) + ->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce()) + ->method('group') + ->with('e.entity_id') + ->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce()) + ->method('order') + ->with('views DESC') + ->willReturn($this->selectMock); + $this->selectMock->expects($this->atLeastOnce()) + ->method('having') + ->with('COUNT(report_table_views.event_id) > ?', 0) + ->willReturn($this->selectMock); + + $this->collection->addViewsCount(); + } + + /** + * Get mock for abstract class with methods. + * + * @param string $className + * @param array $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function createPartialMockForAbstractClass($className, $methods) + { + return $this->getMockForAbstractClass( + $className, + [], + '', + true, + true, + true, + $methods + ); + } +} diff --git a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php index 051dc3f5f5593..7bb866287d37a 100644 --- a/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php +++ b/app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php @@ -124,7 +124,8 @@ public function testLoadWithFilter() $this->selectMock->expects($this->once())->method('reset')->willReturnSelf(); $this->selectMock->expects($this->once())->method('from')->willReturnSelf(); $this->selectMock->expects($this->once())->method('useStraightJoin')->willReturnSelf(); - $this->selectMock->expects($this->exactly(2))->method('joinInner')->willReturnSelf(); + $this->selectMock->expects($this->once())->method('joinInner')->willReturnSelf(); + $this->selectMock->expects($this->once())->method('joinLeft')->willReturnSelf(); $collection->expects($this->once())->method('getOrdersData')->willReturn([]); $productAttributeMock->expects($this->once())->method('getBackend')->willReturnSelf(); $priceAttributeMock->expects($this->once())->method('getBackend')->willReturnSelf(); diff --git a/app/code/Magento/Reports/composer.json b/app/code/Magento/Reports/composer.json index 55da507c5e04d..78cfa41c5d610 100644 --- a/app/code/Magento/Reports/composer.json +++ b/app/code/Magento/Reports/composer.json @@ -3,26 +3,26 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-config": "100.2.*", + "magento/module-config": "101.0.*", "magento/module-store": "100.2.*", - "magento/module-eav": "100.2.*", - "magento/module-customer": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-sales": "100.2.*", - "magento/module-cms": "101.1.*", + "magento/module-eav": "101.0.*", + "magento/module-customer": "101.0.*", + "magento/module-catalog": "102.0.*", + "magento/module-sales": "101.0.*", + "magento/module-cms": "102.0.*", "magento/module-backend": "100.2.*", - "magento/module-widget": "100.2.*", - "magento/module-wishlist": "100.2.*", + "magento/module-widget": "101.0.*", + "magento/module-wishlist": "101.0.*", "magento/module-review": "100.2.*", "magento/module-catalog-inventory": "100.2.*", "magento/module-tax": "100.2.*", "magento/module-downloadable": "100.2.*", - "magento/module-sales-rule": "100.2.*", - "magento/module-quote": "100.2.*", - "magento/framework": "100.2.*" + "magento/module-sales-rule": "101.0.*", + "magento/module-quote": "101.0.*", + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.3", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_accounts_grid.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_accounts_grid.xml index fa2e8b3d0a986..900dc08d571da 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_accounts_grid.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_accounts_grid.xml @@ -31,7 +31,7 @@ gridAccounts 1 - + New Accounts accounts diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_orders_grid.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_orders_grid.xml index 47af0edcf2c50..d886e5724cb0b 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_orders_grid.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_customer_orders_grid.xml @@ -30,7 +30,7 @@ 1 - + Customer 0 @@ -41,7 +41,7 @@ col-name - + Orders 0 @@ -53,7 +53,7 @@ col-qty - + Average 0 @@ -65,7 +65,7 @@ col-average - + Total 0 diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_grid.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_grid.xml index aa8dbf74085e7..82aa475807a25 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_grid.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_grid.xml @@ -46,7 +46,7 @@ We can't find records for this period. We can't find records for this period. - + Interval 0 diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_lowstock_grid.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_lowstock_grid.xml index c0826bd6716c7..070c39259aabd 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_lowstock_grid.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_lowstock_grid.xml @@ -29,7 +29,7 @@ - + Product 0 @@ -38,7 +38,7 @@ col-product - + SKU 0 @@ -47,7 +47,7 @@ col-sku - + Stock Quantity Magento\Backend\Block\Widget\Grid\Column\Filter\Range diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_sold_grid.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_sold_grid.xml index 1748a1a378c6f..a1b01aeeb526f 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_sold_grid.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_product_sold_grid.xml @@ -31,7 +31,7 @@ report_product_sold 1 - + Product text @@ -41,7 +41,17 @@ col-product - + + + SKU + text + order_items_sku + sku + col-sku + col-sku + + + Ordered Quantity sum diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_customer_grid.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_customer_grid.xml index c3f1c0f242b7b..f941ca52eef59 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_customer_grid.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_customer_grid.xml @@ -40,7 +40,7 @@ - + Customer customer_name @@ -51,7 +51,7 @@ col-name - + Reviews text @@ -60,7 +60,7 @@ col-qty - + Action 0 diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_product_grid.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_product_grid.xml index f4d2deac0a3da..1275e761ade3c 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_product_grid.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_review_product_grid.xml @@ -40,7 +40,7 @@ - + ID entity_id @@ -50,7 +50,7 @@ col-id - + Product text @@ -59,7 +59,7 @@ col-product - + Reviews review_cnt @@ -68,7 +68,7 @@ col-qty - + Average avg_rating @@ -77,7 +77,7 @@ col-rating - + Average (Approved) avg_rating_approved @@ -86,7 +86,7 @@ col-avg-rating - + Last Review datetime @@ -96,7 +96,7 @@ col-date - + Action center diff --git a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_statistics_index.xml b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_statistics_index.xml index e02c3c2bea744..4ec984ef9fc11 100644 --- a/app/code/Magento/Reports/view/adminhtml/layout/reports_report_statistics_index.xml +++ b/app/code/Magento/Reports/view/adminhtml/layout/reports_report_statistics_index.xml @@ -42,7 +42,7 @@ 0 gridRefreshStatistics - + Report string @@ -53,7 +53,7 @@ col-report - + Description string @@ -64,7 +64,7 @@ col-description - + Updated datetime diff --git a/app/code/Magento/Reports/view/adminhtml/templates/grid.phtml b/app/code/Magento/Reports/view/adminhtml/templates/grid.phtml index cb267ce29dd34..00766acac16fd 100644 --- a/app/code/Magento/Reports/view/adminhtml/templates/grid.phtml +++ b/app/code/Magento/Reports/view/adminhtml/templates/grid.phtml @@ -31,7 +31,7 @@ $numColumns = sizeof($block->getColumns()); type="text" id="getSuffixId('period_date_from') ?>" name="report_from" - value="getFilter('report_from') ?>"> + value="escapeHtml($block->getFilter('report_from')) ?>"> @@ -44,7 +44,7 @@ $numColumns = sizeof($block->getColumns()); type="text" id="getSuffixId('period_date_to') ?>" name="report_to" - value="getFilter('report_to') ?>"/> + value="escapeHtml($block->getFilter('report_to')) ?>"/> diff --git a/app/code/Magento/RequireJs/Model/FileManager.php b/app/code/Magento/RequireJs/Model/FileManager.php index 019c2cbedb75c..ec41c4238967f 100644 --- a/app/code/Magento/RequireJs/Model/FileManager.php +++ b/app/code/Magento/RequireJs/Model/FileManager.php @@ -183,6 +183,9 @@ public function createBundleJsPool() } foreach ($libDir->read($bundleDir) as $bundleFile) { + if (pathinfo($bundleFile, PATHINFO_EXTENSION) !== 'js') { + continue; + } $relPath = $libDir->getRelativePath($bundleFile); $bundles[] = $this->assetRepo->createArbitrary($relPath, ''); } diff --git a/app/code/Magento/RequireJs/Test/Unit/Model/FileManagerTest.php b/app/code/Magento/RequireJs/Test/Unit/Model/FileManagerTest.php index 6b6d709cbb608..834ee5b68485e 100644 --- a/app/code/Magento/RequireJs/Test/Unit/Model/FileManagerTest.php +++ b/app/code/Magento/RequireJs/Test/Unit/Model/FileManagerTest.php @@ -153,7 +153,7 @@ public function testCreateBundleJsPool() ->expects($this->once()) ->method('read') ->with('path/to/bundle/dir/js/bundle') - ->willReturn(['bundle1.js', 'bundle2.js']); + ->willReturn(['bundle1.js', 'bundle2.js', 'some_file.not_js']); $dirRead ->expects($this->exactly(2)) ->method('getRelativePath') diff --git a/app/code/Magento/RequireJs/composer.json b/app/code/Magento/RequireJs/composer.json index 093002b35c8a7..04757e61586c2 100644 --- a/app/code/Magento/RequireJs/composer.json +++ b/app/code/Magento/RequireJs/composer.json @@ -3,10 +3,10 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Review/Block/Form.php b/app/code/Magento/Review/Block/Form.php index 440e13deb5839..f6a579e844386 100644 --- a/app/code/Magento/Review/Block/Form.php +++ b/app/code/Magento/Review/Block/Form.php @@ -5,7 +5,6 @@ */ namespace Magento\Review\Block; -use Magento\Catalog\Model\Product; use Magento\Customer\Model\Context; use Magento\Customer\Model\Url; use Magento\Review\Model\ResourceModel\Rating\Collection as RatingCollection; diff --git a/app/code/Magento/Review/Block/Product/ReviewRenderer.php b/app/code/Magento/Review/Block/Product/ReviewRenderer.php index f60b33bffb8cb..8aa10d2437cbb 100644 --- a/app/code/Magento/Review/Block/Product/ReviewRenderer.php +++ b/app/code/Magento/Review/Block/Product/ReviewRenderer.php @@ -57,6 +57,10 @@ public function getReviewsSummaryHtml( $templateType = self::DEFAULT_VIEW, $displayIfNoReviews = false ) { + if (!$product->getRatingSummary()) { + $this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId()); + } + if (!$product->getRatingSummary() && !$displayIfNoReviews) { return ''; } @@ -68,9 +72,6 @@ public function getReviewsSummaryHtml( $this->setDisplayIfEmpty($displayIfNoReviews); - if (!$product->getRatingSummary()) { - $this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId()); - } $this->setProduct($product); return $this->toHtml(); diff --git a/app/code/Magento/Review/Controller/Product/ListAction.php b/app/code/Magento/Review/Controller/Product/ListAction.php index dd8b272867c55..26344d125172a 100644 --- a/app/code/Magento/Review/Controller/Product/ListAction.php +++ b/app/code/Magento/Review/Controller/Product/ListAction.php @@ -26,8 +26,8 @@ protected function getProductPage($product) $resultPage->getConfig()->setPageLayout($product->getPageLayout()); } $urlSafeSku = rawurlencode($product->getSku()); - $resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku]); $resultPage->addPageLayoutHandles(['type' => $product->getTypeId()], null, false); + $resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku]); $resultPage->addUpdate($product->getCustomLayoutUpdate()); return $resultPage; } diff --git a/app/code/Magento/Review/Model/ResourceModel/Rating/Option.php b/app/code/Magento/Review/Model/ResourceModel/Rating/Option.php index 6f68000a1efff..ef4acb6c90cb8 100644 --- a/app/code/Magento/Review/Model/ResourceModel/Rating/Option.php +++ b/app/code/Magento/Review/Model/ResourceModel/Rating/Option.php @@ -154,7 +154,7 @@ public function addVote($option) } $connection->commit(); } catch (\Exception $e) { - $connection->rollback(); + $connection->rollBack(); throw new \Exception($e->getMessage()); } return $this; diff --git a/app/code/Magento/Review/composer.json b/app/code/Magento/Review/composer.json index 48fe25430f504..c108f743f6e25 100644 --- a/app/code/Magento/Review/composer.json +++ b/app/code/Magento/Review/composer.json @@ -4,21 +4,21 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-customer": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-catalog": "102.0.*", + "magento/module-customer": "101.0.*", + "magento/module-eav": "101.0.*", "magento/module-theme": "100.2.*", "magento/module-backend": "100.2.*", "magento/module-newsletter": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-ui": "100.2.*" + "magento/framework": "101.0.*", + "magento/module-ui": "101.0.*" }, "suggest": { "magento/module-cookie": "100.2.*", "magento/module-review-sample-data": "Sample Data version:100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.3", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Review/i18n/en_US.csv b/app/code/Magento/Review/i18n/en_US.csv index 36407ae341148..cb5452f2f0c39 100644 --- a/app/code/Magento/Review/i18n/en_US.csv +++ b/app/code/Magento/Review/i18n/en_US.csv @@ -132,3 +132,4 @@ Summary,Summary "Allow Guests to Write Reviews","Allow Guests to Write Reviews" Active,Active Inactive,Inactive +"Please select one of each of the ratings above.","Please select one of each of the ratings above." diff --git a/app/code/Magento/Review/view/adminhtml/layout/rating_block.xml b/app/code/Magento/Review/view/adminhtml/layout/rating_block.xml index 0b78bb34b31d3..b439bcb1c2710 100644 --- a/app/code/Magento/Review/view/adminhtml/layout/rating_block.xml +++ b/app/code/Magento/Review/view/adminhtml/layout/rating_block.xml @@ -25,7 +25,7 @@ - + ID rating_id @@ -33,19 +33,19 @@ col-id - + Rating rating_code - + Sort Order position - + Is Active is_active diff --git a/app/code/Magento/Review/view/adminhtml/web/js/rating.js b/app/code/Magento/Review/view/adminhtml/web/js/rating.js index cc72d386dc053..b8d1b1b241b8f 100644 --- a/app/code/Magento/Review/view/adminhtml/web/js/rating.js +++ b/app/code/Magento/Review/view/adminhtml/web/js/rating.js @@ -27,7 +27,7 @@ define([ _bind: function () { this._labels.on({ click: $.proxy(function (e) { - $('[id="' + $(e.currentTarget).attr('for') + '"]').prop('checked', true); + $(e.currentTarget).prev().prop('checked', true); this._updateRating(); }, this), diff --git a/app/code/Magento/Review/view/frontend/templates/form.phtml b/app/code/Magento/Review/view/frontend/templates/form.phtml index 22031b3f3a20b..707e201cd3add 100644 --- a/app/code/Magento/Review/view/frontend/templates/form.phtml +++ b/app/code/Magento/Review/view/frontend/templates/form.phtml @@ -25,23 +25,23 @@
        getRatings() as $_rating): ?>
        - +
        getOptions();?> + data-validate="{ 'rating-required':true}" + aria-labelledby="escapeHtmlAttr(str_replace(' ', '_', $_rating->getRatingCode())) ?>_rating_label escapeHtmlAttr(str_replace(' ', '_', $_rating->getRatingCode())) ?>_escapeHtmlAttr($_option->getValue()) ?>_label" /> @@ -85,7 +85,8 @@ "Magento_Ui/js/core/app": getJsLayout() ?> }, "#review-form": { - "Magento_Review/js/error-placement": {} + "Magento_Review/js/error-placement": {}, + "Magento_Review/js/validate-review": {} } } diff --git a/app/code/Magento/Review/view/frontend/web/js/validate-review.js b/app/code/Magento/Review/view/frontend/web/js/validate-review.js new file mode 100644 index 0000000000000..e3f57eaf8cd33 --- /dev/null +++ b/app/code/Magento/Review/view/frontend/web/js/validate-review.js @@ -0,0 +1,18 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', + 'jquery/ui', + 'jquery/validate', + 'mage/translate' +], function ($) { + 'use strict'; + + $.validator.addMethod( + 'rating-required', function (value) { + return value !== undefined; + }, $.mage.__('Please select one of each of the ratings above.')); +}); diff --git a/app/code/Magento/ReviewAnalytics/LICENSE.txt b/app/code/Magento/ReviewAnalytics/LICENSE.txt new file mode 100644 index 0000000000000..49525fd99da9c --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/ReviewAnalytics/LICENSE_AFL.txt b/app/code/Magento/ReviewAnalytics/LICENSE_AFL.txt new file mode 100644 index 0000000000000..f39d641b18a19 --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/ReviewAnalytics/README.md b/app/code/Magento/ReviewAnalytics/README.md new file mode 100644 index 0000000000000..b078083dfb7dc --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/README.md @@ -0,0 +1,3 @@ +# Magento_ReviewAnalytics module + +The Magento_ReviewAnalytics module configures data definitions for a data collection related to the Review module entities to be used in [Advanced Reporting](http://devdocs.magento.com/guides/v2.2/advanced-reporting/modules.html). diff --git a/app/code/Magento/ReviewAnalytics/composer.json b/app/code/Magento/ReviewAnalytics/composer.json new file mode 100644 index 0000000000000..2c982969a391f --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/composer.json @@ -0,0 +1,23 @@ +{ + "name": "magento/module-review-analytics", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/framework": "101.0.*", + "magento/module-review": "100.2.*" + }, + "type": "magento2-module", + "version": "100.2.0", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\ReviewAnalytics\\": "" + } + } +} diff --git a/app/code/Magento/ReviewAnalytics/etc/analytics.xml b/app/code/Magento/ReviewAnalytics/etc/analytics.xml new file mode 100644 index 0000000000000..cd5d1b2c1af4c --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/etc/analytics.xml @@ -0,0 +1,27 @@ + + + + + + + + reviews + + + + + + + + + rating_option_votes + + + + + diff --git a/app/code/Magento/ReviewAnalytics/etc/module.xml b/app/code/Magento/ReviewAnalytics/etc/module.xml new file mode 100644 index 0000000000000..65df87bac4af1 --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/etc/module.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/app/code/Magento/ReviewAnalytics/etc/reports.xml b/app/code/Magento/ReviewAnalytics/etc/reports.xml new file mode 100644 index 0000000000000..8dd508983aced --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/etc/reports.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/ReviewAnalytics/registration.php b/app/code/Magento/ReviewAnalytics/registration.php new file mode 100644 index 0000000000000..6b795ca04c61b --- /dev/null +++ b/app/code/Magento/ReviewAnalytics/registration.php @@ -0,0 +1,11 @@ +resultPageFactory->create(true); $resultPage->addHandle('robots_index_index'); + $resultPage->setHeader('Content-Type', 'text/plain'); return $resultPage; } } diff --git a/app/code/Magento/Robots/Test/Unit/Controller/Index/IndexTest.php b/app/code/Magento/Robots/Test/Unit/Controller/Index/IndexTest.php index 22a69cc13bd52..d3a7a97c7ea80 100644 --- a/app/code/Magento/Robots/Test/Unit/Controller/Index/IndexTest.php +++ b/app/code/Magento/Robots/Test/Unit/Controller/Index/IndexTest.php @@ -51,6 +51,9 @@ public function testExecute() $resultPageMock->expects($this->once()) ->method('addHandle') ->with('robots_index_index'); + $resultPageMock->expects($this->once()) + ->method('setHeader') + ->with('Content-Type', 'text/plain'); $this->resultPageFactory->expects($this->any()) ->method('create') diff --git a/app/code/Magento/Robots/composer.json b/app/code/Magento/Robots/composer.json index a359918fad7d1..38c143e2547d7 100644 --- a/app/code/Magento/Robots/composer.json +++ b/app/code/Magento/Robots/composer.json @@ -1,26 +1,26 @@ { - "name": "magento/module-robots", - "description": "N/A", - "require": { - "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/framework": "100.2.*", - "magento/module-store": "100.2.*" - }, - "suggest": { - "magento/module-theme": "100.2.*" - }, - "type": "magento2-module", - "version": "100.2.0-dev", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "autoload": { - "files": [ - "registration.php" + "name": "magento/module-robots", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/framework": "101.0.*", + "magento/module-store": "100.2.*" + }, + "suggest": { + "magento/module-theme": "100.2.*" + }, + "type": "magento2-module", + "version": "100.2.0", + "license": [ + "OSL-3.0", + "AFL-3.0" ], - "psr-4": { - "Magento\\Robots\\": "" + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\Robots\\": "" + } } - } } diff --git a/app/code/Magento/Rss/composer.json b/app/code/Magento/Rss/composer.json index 2c6223f192439..e462497581b14 100644 --- a/app/code/Magento/Rss/composer.json +++ b/app/code/Magento/Rss/composer.json @@ -5,11 +5,11 @@ "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", "magento/module-backend": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-customer": "100.2.*" + "magento/framework": "101.0.*", + "magento/module-customer": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php b/app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php index 5ab1379b96cf6..c02bbd64e7ca3 100644 --- a/app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php +++ b/app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php @@ -137,6 +137,7 @@ public function getDefaultOperatorInputByType() */ $this->_defaultOperatorInputByType['category'] = ['==', '!=', '{}', '!{}', '()', '!()']; $this->_arrayInputTypes[] = 'category'; + $this->_defaultOperatorInputByType['sku'] = ['==', '!=', '{}', '!{}', '()', '!()']; } return $this->_defaultOperatorInputByType; } @@ -241,7 +242,9 @@ protected function _prepareValueOptions() } else { $addEmptyOption = true; } - $selectOptions = $attributeObject->getSource()->getAllOptions($addEmptyOption); + $selectOptions = $this->removeTagsFromLabel( + $attributeObject->getSource()->getAllOptions($addEmptyOption) + ); } } @@ -380,6 +383,9 @@ public function getInputType() if ($this->getAttributeObject()->getAttributeCode() == 'category_ids') { return 'category'; } + if ($this->getAttributeObject()->getAttributeCode() == 'sku') { + return 'sku'; + } switch ($this->getAttributeObject()->getFrontendInput()) { case 'select': return 'select'; @@ -604,7 +610,12 @@ public function getBindArgumentValue() $this->getValueParsed() )->__toString() ); + } elseif ($this->getAttribute() === 'sku') { + $value = $this->getData('value'); + $value = preg_split('#\s*[,;]\s*#', $value, null, PREG_SPLIT_NO_EMPTY); + $this->setValueParsed($value); } + return parent::getBindArgumentValue(); } @@ -702,7 +713,7 @@ protected function _getAttributeSetId($productId) public function getOperatorForValidate() { $operator = $this->getOperator(); - if ($this->getInputType() == 'category') { + if (in_array($this->getInputType(), ['category', 'sku'])) { if ($operator == '==') { $operator = '{}'; } elseif ($operator == '!=') { @@ -734,4 +745,21 @@ protected function getEavAttributeTableAlias() return 'at_' . $attribute->getAttributeCode(); } + + /** + * Remove html tags from attribute labels. + * + * @param array $selectOptions + * @return array + */ + private function removeTagsFromLabel(array $selectOptions) + { + foreach ($selectOptions as &$option) { + if (isset($option['label'])) { + $option['label'] = strip_tags($option['label']); + } + } + + return $selectOptions; + } } diff --git a/app/code/Magento/Rule/Model/Condition/Sql/Builder.php b/app/code/Magento/Rule/Model/Condition/Sql/Builder.php index 41a55f4c25166..31592bf121d0f 100644 --- a/app/code/Magento/Rule/Model/Condition/Sql/Builder.php +++ b/app/code/Magento/Rule/Model/Condition/Sql/Builder.php @@ -6,9 +6,14 @@ namespace Magento\Rule\Model\Condition\Sql; +use Magento\Framework\App\ObjectManager; use Magento\Framework\DB\Select; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Rule\Model\Condition\AbstractCondition; use Magento\Rule\Model\Condition\Combine; +use Magento\Eav\Api\AttributeRepositoryInterface; +use Magento\Catalog\Model\Product; +use Magento\Eav\Model\Entity\Collection\AbstractCollection; /** * Class SQL Builder @@ -41,12 +46,22 @@ class Builder */ protected $_expressionFactory; + /** + * @var AttributeRepositoryInterface + */ + private $attributeRepository; + /** * @param ExpressionFactory $expressionFactory + * @param AttributeRepositoryInterface|null $attributeRepository */ - public function __construct(ExpressionFactory $expressionFactory) - { + public function __construct( + ExpressionFactory $expressionFactory, + AttributeRepositoryInterface $attributeRepository = null + ) { $this->_expressionFactory = $expressionFactory; + $this->attributeRepository = $attributeRepository ?: + ObjectManager::getInstance()->get(AttributeRepositoryInterface::class); } /** @@ -88,12 +103,12 @@ protected function _getChildCombineTablesToJoin(Combine $combine, $tables = []) /** * Join tables from conditions combination to collection * - * @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection + * @param AbstractCollection $collection * @param Combine $combine * @return $this */ protected function _joinTablesToCollection( - \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection, + AbstractCollection $collection, Combine $combine ) { foreach ($this->_getCombineTablesToJoin($combine) as $alias => $joinTable) { @@ -112,10 +127,11 @@ protected function _joinTablesToCollection( * * @param AbstractCondition $condition * @param string $value + * @param bool $isDefaultStoreUsed * @return string * @throws \Magento\Framework\Exception\LocalizedException */ - protected function _getMappedSqlCondition(AbstractCondition $condition, $value = '') + protected function _getMappedSqlCondition(AbstractCondition $condition, $value = '', $isDefaultStoreUsed = true) { $argument = $condition->getMappedSqlField(); @@ -130,9 +146,16 @@ protected function _getMappedSqlCondition(AbstractCondition $condition, $value = throw new \Magento\Framework\Exception\LocalizedException(__('Unknown condition operator')); } + $defaultValue = 0; + // Check if attribute has a table with default value and add it to the query + if ($this->canAttributeHaveDefaultValue($condition->getAttribute(), $isDefaultStoreUsed)) { + $defaultField = 'at_' . $condition->getAttribute() . '_default.value'; + $defaultValue = $this->_connection->quoteIdentifier($defaultField); + } + $sql = str_replace( ':field', - $this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), 0), + $this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue), $this->_conditionOperatorMap[$conditionOperator] ); @@ -144,10 +167,11 @@ protected function _getMappedSqlCondition(AbstractCondition $condition, $value = /** * @param Combine $combine * @param string $value + * @param bool $isDefaultStoreUsed * @return string * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function _getMappedSqlCombination(Combine $combine, $value = '') + protected function _getMappedSqlCombination(Combine $combine, $value = '', $isDefaultStoreUsed = true) { $out = (!empty($value) ? $value : ''); $value = ($combine->getValue() ? '' : ' NOT '); @@ -158,9 +182,9 @@ protected function _getMappedSqlCombination(Combine $combine, $value = '') $con = ($getAggregator == 'any' ? Select::SQL_OR : Select::SQL_AND); $con = (isset($conditions[$key+1]) ? $con : ''); if ($condition instanceof Combine) { - $out .= $this->_getMappedSqlCombination($condition, $value); + $out .= $this->_getMappedSqlCombination($condition, $value, $isDefaultStoreUsed); } else { - $out .= $this->_getMappedSqlCondition($condition, $value); + $out .= $this->_getMappedSqlCondition($condition, $value, $isDefaultStoreUsed); } $out .= $out ? (' ' . $con) : ''; } @@ -170,21 +194,55 @@ protected function _getMappedSqlCombination(Combine $combine, $value = '') /** * Attach conditions filter to collection * - * @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection + * @param AbstractCollection $collection * @param Combine $combine - * * @return void */ public function attachConditionToCollection( - \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection, + AbstractCollection $collection, Combine $combine ) { $this->_connection = $collection->getResource()->getConnection(); $this->_joinTablesToCollection($collection, $combine); - $whereExpression = (string)$this->_getMappedSqlCombination($combine); + $isDefaultStoreUsed = $this->checkIsDefaultStoreUsed($collection); + $whereExpression = (string)$this->_getMappedSqlCombination($combine, '', $isDefaultStoreUsed); if (!empty($whereExpression)) { // Select ::where method adds braces even on empty expression $collection->getSelect()->where($whereExpression); } } + + /** + * Check is default store used + * + * @param AbstractCollection $collection + * @return bool + */ + private function checkIsDefaultStoreUsed(AbstractCollection $collection): bool + { + return (int)$collection->getStoreId() === (int)$collection->getDefaultStoreId(); + } + + /** + * Check if attribute can have default value + * + * @param string $attributeCode + * @param bool $isDefaultStoreUsed + * @return bool + */ + private function canAttributeHaveDefaultValue(string $attributeCode, bool $isDefaultStoreUsed): bool + { + if ($isDefaultStoreUsed) { + return false; + } + + try { + $attribute = $this->attributeRepository->get(Product::ENTITY, $attributeCode); + } catch (NoSuchEntityException $e) { + // It's not exceptional case as we want to check if we have such attribute or not + return false; + } + + return !$attribute->isScopeGlobal(); + } } diff --git a/app/code/Magento/Rule/Model/ResourceModel/AbstractResource.php b/app/code/Magento/Rule/Model/ResourceModel/AbstractResource.php index 2fdb960521a97..6e685a9a9b978 100644 --- a/app/code/Magento/Rule/Model/ResourceModel/AbstractResource.php +++ b/app/code/Magento/Rule/Model/ResourceModel/AbstractResource.php @@ -81,7 +81,7 @@ public function bindRuleToEntity($ruleIds, $entityIds, $entityType) try { $this->_multiplyBunchInsert($ruleIds, $entityIds, $entityType); } catch (\Exception $e) { - $this->getConnection()->rollback(); + $this->getConnection()->rollBack(); throw $e; } diff --git a/app/code/Magento/Rule/Test/Unit/Model/Condition/Sql/BuilderTest.php b/app/code/Magento/Rule/Test/Unit/Model/Condition/Sql/BuilderTest.php index f53098c4bb97e..daf7b1462c722 100644 --- a/app/code/Magento/Rule/Test/Unit/Model/Condition/Sql/BuilderTest.php +++ b/app/code/Magento/Rule/Test/Unit/Model/Condition/Sql/BuilderTest.php @@ -35,7 +35,12 @@ public function testAttachConditionToCollection() { $collection = $this->createPartialMock( \Magento\Eav\Model\Entity\Collection\AbstractCollection::class, - ['getResource', 'getSelect'] + [ + 'getResource', + 'getSelect', + 'getStoreId', + 'getDefaultStoreId', + ] ); $combine = $this->createPartialMock(\Magento\Rule\Model\Condition\Combine::class, ['getConditions']); $resource = $this->createPartialMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class, ['getConnection']); @@ -53,10 +58,15 @@ public function testAttachConditionToCollection() $collection->expects($this->once()) ->method('getResource') ->will($this->returnValue($resource)); - $collection->expects($this->any()) ->method('getSelect') ->will($this->returnValue($select)); + $collection->expects($this->once()) + ->method('getStoreId') + ->willReturn(1); + $collection->expects($this->once()) + ->method('getDefaultStoreId') + ->willReturn(1); $resource->expects($this->once()) ->method('getConnection') diff --git a/app/code/Magento/Rule/Test/Unit/Model/ConditionFactoryTest.php b/app/code/Magento/Rule/Test/Unit/Model/ConditionFactoryTest.php index d8c0cc470f55e..f78ee4f345d0d 100644 --- a/app/code/Magento/Rule/Test/Unit/Model/ConditionFactoryTest.php +++ b/app/code/Magento/Rule/Test/Unit/Model/ConditionFactoryTest.php @@ -78,7 +78,8 @@ public function testCreateExceptionClass() ->expects($this->never()) ->method('create'); - $this->expectException(\InvalidArgumentException::class, 'Class does not exist'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Class does not exist'); $this->conditionFactory->create($type); } @@ -92,7 +93,8 @@ public function testCreateExceptionType() ->method('create') ->with($type) ->willReturn(new \stdClass()); - $this->expectException(\InvalidArgumentException::class, 'Class does not implement condition interface'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Class does not implement condition interface'); $this->conditionFactory->create($type); } } diff --git a/app/code/Magento/Rule/composer.json b/app/code/Magento/Rule/composer.json index 661e73a86de1e..d42f9dc60f08d 100644 --- a/app/code/Magento/Rule/composer.json +++ b/app/code/Magento/Rule/composer.json @@ -4,14 +4,14 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-eav": "100.2.*", - "magento/module-catalog": "101.1.*", + "magento/module-eav": "101.0.*", + "magento/module-catalog": "102.0.*", "magento/module-backend": "100.2.*", - "magento/framework": "100.2.*", + "magento/framework": "101.0.*", "lib-libxml": "*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php index f2b454260dc22..2d23bca110ae2 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php @@ -135,4 +135,20 @@ public function getFormValues() { return $this->_getAddress()->getData(); } + + /** + * @inheritdoc + */ + protected function processCountryOptions( + \Magento\Framework\Data\Form\Element\AbstractElement $countryElement, + $storeId = null + ) { + /** @var \Magento\Sales\Model\Order\Address $address */ + $address = $this->_coreRegistry->registry('order_address'); + if ($address !== null) { + $storeId = $address->getOrder()->getStoreId(); + } + + parent::processCountryOptions($countryElement, $storeId); + } } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php index 323c2df975a8a..b684fe8c62df2 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php @@ -160,4 +160,22 @@ public function convertPrice($value, $format = true) ) : $this->priceCurrency->convert($value, $this->getStore()); } + + /** + * If item is quote or wishlist we need to get product from it. + * + * @param $item + * + * @return Product + */ + public function getProduct($item) + { + if ($item instanceof Product) { + $product = $item; + } else { + $product = $item->getProduct(); + } + + return $product; + } } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php index 5738e8ee33399..6625f438f9515 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php @@ -293,11 +293,17 @@ protected function _prepareForm() /** * @param \Magento\Framework\Data\Form\Element\AbstractElement $countryElement + * @param string|int $storeId + * * @return void */ - private function processCountryOptions(\Magento\Framework\Data\Form\Element\AbstractElement $countryElement) - { - $storeId = $this->getBackendQuoteSession()->getStoreId(); + protected function processCountryOptions( + \Magento\Framework\Data\Form\Element\AbstractElement $countryElement, + $storeId = null + ) { + if ($storeId === null) { + $storeId = $this->getBackendQuoteSession()->getStoreId(); + } $options = $this->getCountriesCollection() ->loadByStore($storeId) ->toOptionArray(); diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Adjustments.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Adjustments.php index d73371d46dae1..3f38939296a04 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Adjustments.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Adjustments.php @@ -109,4 +109,20 @@ public function getShippingLabel() } return $label; } + + /** + * Get update totals url + * + * @return string + */ + public function getUpdateTotalsUrl() + { + return $this->getUrl( + 'sales/*/updateQty', + [ + 'order_id' => $this->getSource()->getOrderId(), + 'invoice_id' => $this->getRequest()->getParam('invoice_id', null) + ] + ); + } } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Items.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Items.php index 65163f9ed5d82..da865cf3f541f 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Items.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Items.php @@ -56,9 +56,14 @@ protected function _prepareLayout() $this->addChild( 'update_button', \Magento\Backend\Block\Widget\Button::class, - ['label' => __('Update Qty\'s'), 'class' => 'update-button', 'onclick' => $onclick] + ['label' => __('Update Qty\'s'), 'class' => 'update-button secondary', 'onclick' => $onclick] ); - + $this->addChild( + 'update_totals_button', + \Magento\Backend\Block\Widget\Button::class, + ['label' => __('Update Totals'), 'class' => 'update-totals-button secondary', 'onclick' => $onclick] + ); + if ($this->getCreditmemo()->canRefund()) { if ($this->getCreditmemo()->getInvoice() && $this->getCreditmemo()->getInvoice()->getTransactionId()) { $this->addChild( @@ -176,6 +181,16 @@ public function getUpdateButtonHtml() return $this->getChildHtml('update_button'); } + /** + * Get update totals button html + * + * @return string + */ + public function getUpdateTotalsButtonHtml() + { + return $this->getChildHtml('update_totals_button'); + } + /** * Get update url * diff --git a/app/code/Magento/Sales/Block/Order/Totals.php b/app/code/Magento/Sales/Block/Order/Totals.php index f910b654f4d8c..3720db76b5778 100644 --- a/app/code/Magento/Sales/Block/Order/Totals.php +++ b/app/code/Magento/Sales/Block/Order/Totals.php @@ -293,6 +293,12 @@ public function removeTotal($code) */ public function applySortOrder($order) { + \uksort( + $this->_totals, + function ($code1, $code2) use ($order) { + return ($order[$code1] ?? 0) <=> ($order[$code2] ?? 0); + } + ); return $this; } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php index db0c2b2f5991b..dc994e554b394 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php @@ -6,7 +6,29 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order; -class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order +use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\Redirect; +use Magento\Directory\Model\RegionFactory; +use Magento\Sales\Api\OrderManagementInterface; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Api\Data\OrderAddressInterface; +use Magento\Sales\Controller\Adminhtml\Order; +use Magento\Sales\Model\Order\Address as AddressModel; +use Psr\Log\LoggerInterface; +use Magento\Framework\Registry; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Framework\Translate\InlineInterface; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\Result\JsonFactory; +use Magento\Framework\View\Result\LayoutFactory; +use Magento\Framework\Controller\Result\RawFactory; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\App\ObjectManager; + +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class AddressSave extends Order { /** * Authorization level of a basic admin session @@ -15,19 +37,70 @@ class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order */ const ADMIN_RESOURCE = 'Magento_Sales::actions_edit'; + /** + * @var RegionFactory + */ + private $regionFactory; + /** + * @param Context $context + * @param Registry $coreRegistry + * @param FileFactory $fileFactory + * @param InlineInterface $translateInline + * @param PageFactory $resultPageFactory + * @param JsonFactory $resultJsonFactory + * @param LayoutFactory $resultLayoutFactory + * @param RawFactory $resultRawFactory + * @param OrderManagementInterface $orderManagement + * @param OrderRepositoryInterface $orderRepository + * @param LoggerInterface $logger + * @param RegionFactory|null $regionFactory + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + */ + public function __construct( + Context $context, + Registry $coreRegistry, + FileFactory $fileFactory, + InlineInterface $translateInline, + PageFactory $resultPageFactory, + JsonFactory $resultJsonFactory, + LayoutFactory $resultLayoutFactory, + RawFactory $resultRawFactory, + OrderManagementInterface $orderManagement, + OrderRepositoryInterface $orderRepository, + LoggerInterface $logger, + RegionFactory $regionFactory = null + ) { + $this->regionFactory = $regionFactory ?: ObjectManager::getInstance()->get(RegionFactory::class); + parent::__construct( + $context, + $coreRegistry, + $fileFactory, + $translateInline, + $resultPageFactory, + $resultJsonFactory, + $resultLayoutFactory, + $resultRawFactory, + $orderManagement, + $orderRepository, + $logger + ); + } + /** * Save order address * - * @return \Magento\Backend\Model\View\Result\Redirect + * @return Redirect */ public function execute() { $addressId = $this->getRequest()->getParam('address_id'); - /** @var $address \Magento\Sales\Api\Data\OrderAddressInterface|\Magento\Sales\Model\Order\Address */ + /** @var $address OrderAddressInterface|AddressModel */ $address = $this->_objectManager->create( - \Magento\Sales\Api\Data\OrderAddressInterface::class + OrderAddressInterface::class )->load($addressId); $data = $this->getRequest()->getPostValue(); + $data = $this->updateRegionData($data); $resultRedirect = $this->resultRedirectFactory->create(); if ($data && $address->getId()) { $address->addData($data); @@ -41,7 +114,7 @@ public function execute() ); $this->messageManager->addSuccess(__('You updated the order address.')); return $resultRedirect->setPath('sales/*/view', ['order_id' => $address->getParentId()]); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('We can\'t update the order address right now.')); @@ -51,4 +124,20 @@ public function execute() return $resultRedirect->setPath('sales/*/'); } } + + /** + * Update region data + * + * @param array $attributeValues + * @return array + */ + private function updateRegionData($attributeValues) + { + if (!empty($attributeValues['region_id'])) { + $newRegion = $this->regionFactory->create()->load($attributeValues['region_id']); + $attributeValues['region_code'] = $newRegion->getCode(); + $attributeValues['region'] = $newRegion->getDefaultName(); + } + return $attributeValues; + } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php index 74b7ad2165332..621705c7937cb 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Save.php @@ -63,6 +63,8 @@ public function execute() } $resultRedirect->setPath('sales/*/'); } catch (\Magento\Framework\Exception\LocalizedException $e) { + // customer can be created before place order flow is completed and should be stored in current session + $this->_getSession()->setCustomerId($this->_getSession()->getQuote()->getCustomerId()); $message = $e->getMessage(); if (!empty($message)) { $this->messageManager->addError($message); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php index 63c266150384a..c45a1982784e1 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php @@ -191,14 +191,7 @@ public function execute() } $transactionSave->save(); - if (isset($shippingResponse) && $shippingResponse->hasErrors()) { - $this->messageManager->addError( - __( - 'The invoice and the shipment have been created. ' . - 'The shipping label cannot be created now.' - ) - ); - } elseif (!empty($data['do_shipment'])) { + if (!empty($data['do_shipment'])) { $this->messageManager->addSuccess(__('You created the invoice and shipment.')); } else { $this->messageManager->addSuccess(__('The invoice has been created.')); diff --git a/app/code/Magento/Sales/CustomerData/LastOrderedItems.php b/app/code/Magento/Sales/CustomerData/LastOrderedItems.php index 3cd3afbfa4d22..f98b5f16f3019 100644 --- a/app/code/Magento/Sales/CustomerData/LastOrderedItems.php +++ b/app/code/Magento/Sales/CustomerData/LastOrderedItems.php @@ -6,6 +6,7 @@ namespace Magento\Sales\CustomerData; use Magento\Customer\CustomerData\SectionSourceInterface; +use Magento\Catalog\Api\ProductRepositoryInterface; /** * Returns information for "Recently Ordered" widget. @@ -54,25 +55,33 @@ class LastOrderedItems implements SectionSourceInterface */ private $_storeManager; + /** + * @var \Magento\Catalog\Api\ProductRepositoryInterface + */ + private $productRepository; + /** * @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory * @param \Magento\Sales\Model\Order\Config $orderConfig * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param ProductRepositoryInterface $productRepository */ public function __construct( \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory, \Magento\Sales\Model\Order\Config $orderConfig, \Magento\Customer\Model\Session $customerSession, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, - \Magento\Store\Model\StoreManagerInterface $storeManager + \Magento\Store\Model\StoreManagerInterface $storeManager, + ProductRepositoryInterface $productRepository ) { $this->_orderCollectionFactory = $orderCollectionFactory; $this->_orderConfig = $orderConfig; $this->_customerSession = $customerSession; $this->stockRegistry = $stockRegistry; $this->_storeManager = $storeManager; + $this->productRepository = $productRepository; } /** @@ -108,11 +117,18 @@ protected function getItems() $website = $this->_storeManager->getStore()->getWebsiteId(); /** @var \Magento\Sales\Model\Order\Item $item */ foreach ($order->getParentItemsRandomCollection($limit) as $item) { - if ($item->hasData('product') && in_array($website, $item->getProduct()->getWebsiteIds())) { + /** @var \Magento\Catalog\Model\Product $product */ + $product = $this->productRepository->getById( + $item->getProductId(), + false, + $this->_storeManager->getStore()->getId() + ); + if ($product && in_array($website, $product->getWebsiteIds())) { + $url = $product->isVisibleInSiteVisibility() ? $product->getProductUrl() : null; $items[] = [ 'id' => $item->getId(), 'name' => $item->getName(), - 'url' => $item->getProduct()->getProductUrl(), + 'url' => $url, 'is_saleable' => $this->isItemAvailableForReorder($item), ]; } diff --git a/app/code/Magento/Sales/Helper/Guest.php b/app/code/Magento/Sales/Helper/Guest.php index a80be58bc003e..dd8845008d79e 100644 --- a/app/code/Magento/Sales/Helper/Guest.php +++ b/app/code/Magento/Sales/Helper/Guest.php @@ -178,6 +178,9 @@ public function loadValidOrder(App\RequestInterface $request) public function getBreadcrumbs(\Magento\Framework\View\Result\Page $resultPage) { $breadcrumbs = $resultPage->getLayout()->getBlock('breadcrumbs'); + if (!$breadcrumbs) { + return; + } $breadcrumbs->addCrumb( 'home', [ diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index ccc5c134514f6..22ef39aa30247 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -10,7 +10,12 @@ use Magento\Customer\Api\AddressMetadataInterface; use Magento\Customer\Model\Metadata\Form as CustomerForm; +use Magento\Framework\Api\ExtensibleDataObjectConverter; +use Magento\Framework\App\ObjectManager; +use Magento\Quote\Model\Quote\Address; use Magento\Quote\Model\Quote\Item; +use Magento\Sales\Api\Data\OrderAddressInterface; +use Magento\Sales\Model\Order; /** * Order create model @@ -233,6 +238,11 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ */ private $serializer; + /** + * @var ExtensibleDataObjectConverter + */ + private $dataObjectConverter; + /** * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param \Magento\Framework\Event\ManagerInterface $eventManager @@ -263,6 +273,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ * @param \Magento\Quote\Model\QuoteFactory $quoteFactory * @param array $data * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @param ExtensibleDataObjectConverter|null $dataObjectConverter * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -294,7 +305,8 @@ public function __construct( \Magento\Sales\Api\OrderManagementInterface $orderManagement, \Magento\Quote\Model\QuoteFactory $quoteFactory, array $data = [], - \Magento\Framework\Serialize\Serializer\Json $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null, + ExtensibleDataObjectConverter $dataObjectConverter = null ) { $this->_objectManager = $objectManager; $this->_eventManager = $eventManager; @@ -323,9 +335,11 @@ public function __construct( $this->dataObjectHelper = $dataObjectHelper; $this->orderManagement = $orderManagement; $this->quoteFactory = $quoteFactory; - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + $this->serializer = $serializer ?: ObjectManager::getInstance() ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($data); + $this->dataObjectConverter = $dataObjectConverter ?: ObjectManager::getInstance() + ->get(ExtensibleDataObjectConverter::class); } /** @@ -512,9 +526,7 @@ public function initFromOrder(\Magento\Sales\Model\Order $order) $shippingAddress = $order->getShippingAddress(); if ($shippingAddress) { - $addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData()); - unset($addressDiff['address_type'], $addressDiff['entity_id']); - $shippingAddress->setSameAsBilling(empty($addressDiff)); + $shippingAddress->setSameAsBilling($this->isAddressesAreEqual($order)); } $this->_initBillingAddressFromOrder($order); @@ -669,7 +681,7 @@ public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $q */ public function getCustomerWishlist($cacheReload = false) { - if (!is_null($this->_wishlist) && !$cacheReload) { + if (($this->_wishlist !== null) && !$cacheReload) { return $this->_wishlist; } @@ -696,16 +708,17 @@ public function getCustomerWishlist($cacheReload = false) */ public function getCustomerCart() { - if (!is_null($this->_cart)) { + if ($this->_cart !== null) { return $this->_cart; } $this->_cart = $this->quoteFactory->create(); $customerId = (int)$this->getSession()->getCustomerId(); + $storeId = (int)$this->getSession()->getStoreId(); if ($customerId) { try { - $this->_cart = $this->quoteRepository->getForCustomer($customerId); + $this->_cart = $this->quoteRepository->getForCustomer($customerId, [$storeId]); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { $this->_cart->setStore($this->getSession()->getStore()); $customerData = $this->customerRepository->getById($customerId); @@ -724,7 +737,7 @@ public function getCustomerCart() */ public function getCustomerCompareList() { - if (!is_null($this->_compareList)) { + if ($this->_compareList !== null) { return $this->_compareList; } $customerId = (int)$this->getSession()->getCustomerId(); @@ -795,7 +808,7 @@ public function moveQuoteItem($item, $moveTo, $qty) break; case 'cart': $cart = $this->getCustomerCart(); - if ($cart && is_null($item->getOptionByCode('additional_options'))) { + if ($cart && ($item->getOptionByCode('additional_options') === null)) { //options and info buy request $product = $this->_objectManager->create( \Magento\Catalog\Model\Product::class @@ -1449,33 +1462,37 @@ public function getBillingAddress() */ public function setBillingAddress($address) { - if (is_array($address)) { - $billingAddress = $this->_objectManager->create( - \Magento\Quote\Model\Quote\Address::class - )->setData( - $address - )->setAddressType( - \Magento\Quote\Model\Quote\Address::TYPE_BILLING - ); - $this->_setQuoteAddress($billingAddress, $address); - /** - * save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress, - * that is why it should be added after _setQuoteAddress call - */ - $saveInAddressBook = (int)(!empty($address['save_in_address_book'])); - $billingAddress->setData('save_in_address_book', $saveInAddressBook); - - if (!$this->getQuote()->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) { - $shippingAddress = clone $billingAddress; - $shippingAddress->setSameAsBilling(true); - $shippingAddress->setSaveInAddressBook(false); - $address['save_in_address_book'] = 0; - $this->setShippingAddress($address); - } + if (!is_array($address)) { + return $this; + } + + $billingAddress = $this->_objectManager->create(Address::class) + ->setData($address) + ->setAddressType(Address::TYPE_BILLING); - $this->getQuote()->setBillingAddress($billingAddress); + $this->_setQuoteAddress($billingAddress, $address); + + /** + * save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress, + * that is why it should be added after _setQuoteAddress call + */ + $saveInAddressBook = (int)(!empty($address['save_in_address_book'])); + $billingAddress->setData('save_in_address_book', $saveInAddressBook); + + $quote = $this->getQuote(); + if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) { + $address['save_in_address_book'] = 0; + $this->setShippingAddress($address); } + // not assigned billing address should be saved as new + // but if quote already has the billing address it won't be overridden + if (empty($billingAddress->getCustomerAddressId())) { + $billingAddress->setCustomerAddressId(null); + $quote->getBillingAddress()->setCustomerAddressId(null); + } + $quote->setBillingAddress($billingAddress); + return $this; } @@ -1711,7 +1728,7 @@ protected function _validateCustomerData(\Magento\Customer\Api\Data\CustomerInte } $data = $form->restoreData($data); foreach ($data as $key => $value) { - if (!is_null($value)) { + if ($value !== null) { unset($data[$key]); } } @@ -1775,6 +1792,7 @@ public function _prepareCustomer() $address = $this->getShippingAddress()->setCustomerId($this->getQuote()->getCustomer()->getId()); $this->setShippingAddress($address); } + $this->getBillingAddress()->setCustomerId($customer->getId()); $this->getQuote()->updateCustomerData($this->getQuote()->getCustomer()); $customer = $this->getQuote()->getCustomer(); @@ -1834,12 +1852,12 @@ protected function _prepareCustomerAddress($customer, $quoteCustomerAddress) switch ($addressType) { case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_BILLING: - if (is_null($customer->getDefaultBilling())) { + if ($customer->getDefaultBilling() === null) { $customerAddress->setIsDefaultBilling(true); } break; case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING: - if (is_null($customer->getDefaultShipping())) { + if ($customer->getDefaultShipping() === null) { $customerAddress->setIsDefaultShipping(true); } break; @@ -1907,6 +1925,7 @@ public function createOrder() $oldOrder = $this->getSession()->getOrder(); $oldOrder->setRelationChildId($order->getId()); $oldOrder->setRelationChildRealId($order->getIncrementId()); + $oldOrder->save(); $this->orderManagement->cancel($oldOrder->getEntityId()); $order->save(); } @@ -1930,7 +1949,7 @@ public function createOrder() protected function _validate() { $customerId = $this->getSession()->getCustomerId(); - if (is_null($customerId)) { + if ($customerId === null) { throw new \Magento\Framework\Exception\LocalizedException(__('Please select a customer')); } @@ -2002,4 +2021,26 @@ protected function _getNewCustomerEmail() return $email; } + + /** + * Checks id shipping and billing addresses are equal. + * + * @param Order $order + * @return bool + */ + private function isAddressesAreEqual(Order $order) + { + $shippingAddress = $order->getShippingAddress(); + $billingAddress = $order->getBillingAddress(); + $shippingData = $this->dataObjectConverter->toFlatArray($shippingAddress, [], OrderAddressInterface::class); + $billingData = $this->dataObjectConverter->toFlatArray($billingAddress, [], OrderAddressInterface::class); + unset( + $shippingData['address_type'], + $shippingData['entity_id'], + $billingData['address_type'], + $billingData['entity_id'] + ); + + return $shippingData == $billingData; + } } diff --git a/app/code/Magento/Sales/Model/Order.php b/app/code/Magento/Sales/Model/Order.php index 250aa510eafc6..85443ee7f4f11 100644 --- a/app/code/Magento/Sales/Model/Order.php +++ b/app/code/Magento/Sales/Model/Order.php @@ -7,6 +7,8 @@ use Magento\Directory\Model\Currency; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Locale\ResolverInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\Data\OrderStatusHistoryInterface; @@ -267,6 +269,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface */ protected $timezone; + /** + * @var ResolverInterface + */ + private $localeResolver; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -295,7 +302,9 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param ResolverInterface $localeResolver * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( \Magento\Framework\Model\Context $context, @@ -324,7 +333,8 @@ public function __construct( \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productListFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + ResolverInterface $localeResolver = null ) { $this->_storeManager = $storeManager; $this->_orderConfig = $orderConfig; @@ -335,7 +345,6 @@ public function __construct( $this->_productVisibility = $productVisibility; $this->invoiceManagement = $invoiceManagement; $this->_currencyFactory = $currencyFactory; - $this->_eavConfig = $eavConfig; $this->_orderHistoryFactory = $orderHistoryFactory; $this->_addressCollectionFactory = $addressCollectionFactory; $this->_paymentCollectionFactory = $paymentCollectionFactory; @@ -346,6 +355,8 @@ public function __construct( $this->_trackCollectionFactory = $trackCollectionFactory; $this->salesOrderCollectionFactory = $salesOrderCollectionFactory; $this->priceCurrency = $priceCurrency; + $this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(ResolverInterface::class); + parent::__construct( $context, $registry, @@ -1830,7 +1841,7 @@ public function getCreatedAtFormatted($format) new \DateTime($this->getCreatedAt()), $format, $format, - null, + $this->localeResolver->getDefaultLocale(), $this->timezone->getConfigTimezone('store', $this->getStore()) ); } diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 1c7514142678b..e00eda647dc8d 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -122,8 +122,14 @@ public function getStateDefaultStatus($state) */ public function getStatusLabel($code) { - $code = $this->maskStatusForArea($this->state->getAreaCode(), $code); + $area = $this->state->getAreaCode(); + $code = $this->maskStatusForArea($area, $code); $status = $this->orderStatusFactory->create()->load($code); + + if ($area == 'adminhtml') { + return $status->getLabel(); + } + return $status->getStoreLabel(); } @@ -211,7 +217,7 @@ public function getStateStatuses($state, $addLabels = true) foreach ($collection as $item) { $status = $item->getData('status'); if ($addLabels) { - $statuses[$status] = $item->getStoreLabel(); + $statuses[$status] = $this->getStatusLabel($status); } else { $statuses[] = $status; } diff --git a/app/code/Magento/Sales/Model/Order/Creditmemo.php b/app/code/Magento/Sales/Model/Order/Creditmemo.php index 68339e7db9390..0d0e0d23496b7 100644 --- a/app/code/Magento/Sales/Model/Order/Creditmemo.php +++ b/app/code/Magento/Sales/Model/Order/Creditmemo.php @@ -9,10 +9,12 @@ namespace Magento\Sales\Model\Order; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Sales\Api\Data\CreditmemoInterface; use Magento\Sales\Model\AbstractModel; use Magento\Sales\Model\EntityInterface; +use Magento\Sales\Model\Order\InvoiceFactory; /** * Order creditmemo model @@ -114,6 +116,11 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt */ protected $priceCurrency; + /** + * @var InvoiceFactory + */ + private $invoiceFactory; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -130,6 +137,7 @@ class Creditmemo extends AbstractModel implements EntityInterface, CreditmemoInt * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param InvoiceFactory $invoiceFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -147,7 +155,8 @@ public function __construct( PriceCurrencyInterface $priceCurrency, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + InvoiceFactory $invoiceFactory = null ) { $this->_creditmemoConfig = $creditmemoConfig; $this->_orderFactory = $orderFactory; @@ -157,6 +166,7 @@ public function __construct( $this->_commentFactory = $commentFactory; $this->_commentCollectionFactory = $commentCollectionFactory; $this->priceCurrency = $priceCurrency; + $this->invoiceFactory = $invoiceFactory ?: ObjectManager::getInstance()->get(InvoiceFactory::class); parent::__construct( $context, $registry, @@ -379,6 +389,9 @@ public function canRefund() */ public function getInvoice() { + if (!$this->getData('invoice') instanceof \Magento\Sales\Api\Data\InvoiceInterface && $this->getInvoiceId()) { + $this->setInvoice($this->invoiceFactory->create()->load($this->getInvoiceId())); + } return $this->getData('invoice'); } @@ -418,7 +431,7 @@ public function canVoid() /** * If we not retrieve negative answer from payment yet */ - if (is_null($canVoid)) { + if ($canVoid === null) { $canVoid = $this->getOrder()->getPayment()->canVoid(); if ($canVoid === false) { $this->setCanVoidFlag(false); @@ -438,7 +451,7 @@ public function canVoid() */ public static function getStates() { - if (is_null(static::$_states)) { + if (static::$_states === null) { static::$_states = [ self::STATE_OPEN => __('Pending'), self::STATE_REFUNDED => __('Refunded'), @@ -456,11 +469,11 @@ public static function getStates() */ public function getStateName($stateId = null) { - if (is_null($stateId)) { + if ($stateId === null) { $stateId = $this->getState(); } - if (is_null(static::$_states)) { + if (static::$_states === null) { static::getStates(); } if (isset(static::$_states[$stateId])) { @@ -1524,6 +1537,5 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\CreditmemoExtensi { return $this->_setExtensionAttributes($extensionAttributes); } - //@codeCoverageIgnoreEnd } diff --git a/app/code/Magento/Sales/Model/Order/Creditmemo/CommentRepository.php b/app/code/Magento/Sales/Model/Order/Creditmemo/CommentRepository.php index 14d4ccae22446..a3dde4e5172e7 100644 --- a/app/code/Magento/Sales/Model/Order/Creditmemo/CommentRepository.php +++ b/app/code/Magento/Sales/Model/Order/Creditmemo/CommentRepository.php @@ -7,6 +7,7 @@ use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\CouldNotDeleteException; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Sales\Api\CreditmemoCommentRepositoryInterface; @@ -14,7 +15,15 @@ use Magento\Sales\Api\Data\CreditmemoCommentInterfaceFactory; use Magento\Sales\Api\Data\CreditmemoCommentSearchResultInterfaceFactory; use Magento\Sales\Model\Spi\CreditmemoCommentResourceInterface; +use Magento\Sales\Model\Order\Email\Sender\CreditmemoCommentSender; +use Magento\Sales\Api\CreditmemoRepositoryInterface; +use Psr\Log\LoggerInterface; +/** + * Class CommentRepository + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class CommentRepository implements CreditmemoCommentRepositoryInterface { /** @@ -37,22 +46,48 @@ class CommentRepository implements CreditmemoCommentRepositoryInterface */ private $collectionProcessor; + /** + * @var CreditmemoCommentSender + */ + private $creditmemoCommentSender; + + /** + * @var CreditmemoRepositoryInterface + */ + private $creditmemoRepository; + + /** + * @var LoggerInterface + */ + private $logger; + /** * @param CreditmemoCommentResourceInterface $commentResource * @param CreditmemoCommentInterfaceFactory $commentFactory * @param CreditmemoCommentSearchResultInterfaceFactory $searchResultFactory * @param CollectionProcessorInterface $collectionProcessor + * @param CreditmemoCommentSender|null $creditmemoCommentSender + * @param CreditmemoRepositoryInterface|null $creditmemoRepository + * @param LoggerInterface|null $logger */ public function __construct( CreditmemoCommentResourceInterface $commentResource, CreditmemoCommentInterfaceFactory $commentFactory, CreditmemoCommentSearchResultInterfaceFactory $searchResultFactory, - CollectionProcessorInterface $collectionProcessor + CollectionProcessorInterface $collectionProcessor, + CreditmemoCommentSender $creditmemoCommentSender = null, + CreditmemoRepositoryInterface $creditmemoRepository = null, + LoggerInterface $logger = null ) { $this->commentResource = $commentResource; $this->commentFactory = $commentFactory; $this->searchResultFactory = $searchResultFactory; $this->collectionProcessor = $collectionProcessor; + $this->creditmemoCommentSender = $creditmemoCommentSender + ?: ObjectManager::getInstance()->get(CreditmemoCommentSender::class); + $this->creditmemoRepository = $creditmemoRepository + ?: ObjectManager::getInstance()->get(CreditmemoRepositoryInterface::class); + $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class); } /** @@ -97,7 +132,14 @@ public function save(CreditmemoCommentInterface $entity) try { $this->commentResource->save($entity); } catch (\Exception $e) { - throw new CouldNotSaveException(__('Could not save the comment.'), $e); + throw new CouldNotSaveException(__('Could not save the creditmemo comment.'), $e); + } + + try { + $creditmemo = $this->creditmemoRepository->get($entity->getParentId()); + $this->creditmemoCommentSender->send($creditmemo, $entity->getIsCustomerNotified(), $entity->getComment()); + } catch (\Exception $exception) { + $this->logger->warning('Something went wrong while sending email.'); } return $entity; } diff --git a/app/code/Magento/Sales/Model/Order/Creditmemo/Sender/EmailSender.php b/app/code/Magento/Sales/Model/Order/Creditmemo/Sender/EmailSender.php index 435b3aee4d6d7..ecd5670a319e7 100644 --- a/app/code/Magento/Sales/Model/Order/Creditmemo/Sender/EmailSender.php +++ b/app/code/Magento/Sales/Model/Order/Creditmemo/Sender/EmailSender.php @@ -7,9 +7,12 @@ use Magento\Sales\Model\Order\Email\Sender; use Magento\Sales\Model\Order\Creditmemo\SenderInterface; +use Magento\Framework\DataObject; /** * Email notification sender for Creditmemo. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class EmailSender extends Sender implements SenderInterface { @@ -106,13 +109,17 @@ public function send( 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order), ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_creditmemo_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); if ($this->checkAndSend($order)) { $creditmemo->setEmailSent(true); diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index 5f1bba4c8f2c2..50523015d87eb 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -5,13 +5,16 @@ */ namespace Magento\Sales\Model\Order; +use Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice; +use Magento\Sales\Api\Data\OrderItemInterface; + /** * Factory class for @see \Magento\Sales\Model\Order\Creditmemo */ class CreditmemoFactory { /** - * Quote convert object + * Order convert object * * @var \Magento\Sales\Model\Convert\Order */ @@ -63,31 +66,15 @@ public function createByOrder(\Magento\Sales\Model\Order $order, array $data = [ { $totalQty = 0; $creditmemo = $this->convertor->toCreditmemo($order); - $qtys = isset($data['qtys']) ? $data['qtys'] : []; + $qtyList = isset($data['qtys']) ? $data['qtys'] : []; foreach ($order->getAllItems() as $orderItem) { - if (!$this->canRefundItem($orderItem, $qtys)) { + if (!$this->canRefundItem($orderItem, $qtyList)) { continue; } $item = $this->convertor->itemToCreditmemoItem($orderItem); - if ($orderItem->isDummy()) { - if (isset($data['qtys'][$orderItem->getParentItemId()])) { - $parentQty = $data['qtys'][$orderItem->getParentItemId()]; - } else { - $parentQty = $orderItem->getParentItem() ? $orderItem->getParentItem()->getQtyToRefund() : 1; - } - $qty = $this->calculateProductOptions($orderItem, $parentQty); - $orderItem->setLockedDoShip(true); - } else { - if (isset($qtys[$orderItem->getId()])) { - $qty = (double)$qtys[$orderItem->getId()]; - } elseif (!count($qtys)) { - $qty = $orderItem->getQtyToRefund(); - } else { - continue; - } - } + $qty = $this->getQtyToRefund($orderItem, $qtyList); $totalQty += $qty; $item->setQty($qty); $creditmemo->addItem($item); @@ -106,72 +93,31 @@ public function createByOrder(\Magento\Sales\Model\Order $order, array $data = [ * @param \Magento\Sales\Model\Order\Invoice $invoice * @param array $data * @return Creditmemo - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) */ public function createByInvoice(\Magento\Sales\Model\Order\Invoice $invoice, array $data = []) { $order = $invoice->getOrder(); $totalQty = 0; - $qtys = isset($data['qtys']) ? $data['qtys'] : []; + $qtyList = isset($data['qtys']) ? $data['qtys'] : []; $creditmemo = $this->convertor->toCreditmemo($order); $creditmemo->setInvoice($invoice); - $invoiceQtysRefunded = []; - foreach ($invoice->getOrder()->getCreditmemosCollection() as $createdCreditmemo) { - if ($createdCreditmemo->getState() != Creditmemo::STATE_CANCELED && - $createdCreditmemo->getInvoiceId() == $invoice->getId() - ) { - foreach ($createdCreditmemo->getAllItems() as $createdCreditmemoItem) { - $orderItemId = $createdCreditmemoItem->getOrderItem()->getId(); - if (isset($invoiceQtysRefunded[$orderItemId])) { - $invoiceQtysRefunded[$orderItemId] += $createdCreditmemoItem->getQty(); - } else { - $invoiceQtysRefunded[$orderItemId] = $createdCreditmemoItem->getQty(); - } - } - } - } - - $invoiceQtysRefundLimits = []; - foreach ($invoice->getAllItems() as $invoiceItem) { - $invoiceQtyCanBeRefunded = $invoiceItem->getQty(); - $orderItemId = $invoiceItem->getOrderItem()->getId(); - if (isset($invoiceQtysRefunded[$orderItemId])) { - $invoiceQtyCanBeRefunded = $invoiceQtyCanBeRefunded - $invoiceQtysRefunded[$orderItemId]; - } - $invoiceQtysRefundLimits[$orderItemId] = $invoiceQtyCanBeRefunded; - } - + $invoiceRefundLimitsQtyList = $this->getInvoiceRefundLimitsQtyList($invoice); foreach ($invoice->getAllItems() as $invoiceItem) { + /** @var OrderItemInterface $orderItem */ $orderItem = $invoiceItem->getOrderItem(); - if (!$this->canRefundItem($orderItem, $qtys, $invoiceQtysRefundLimits)) { + if (!$this->canRefundItem($orderItem, $qtyList, $invoiceRefundLimitsQtyList)) { continue; } - $item = $this->convertor->itemToCreditmemoItem($orderItem); - if ($orderItem->isDummy()) { - if (isset($data['qtys'][$orderItem->getParentItemId()])) { - $parentQty = $data['qtys'][$orderItem->getParentItemId()]; - } else { - $parentQty = $orderItem->getParentItem() ? $orderItem->getParentItem()->getQtyToRefund() : 1; - } - $qty = $this->calculateProductOptions($orderItem, $parentQty); - } else { - if (isset($qtys[$orderItem->getId()])) { - $qty = (double)$qtys[$orderItem->getId()]; - } elseif (!count($qtys)) { - $qty = $orderItem->getQtyToRefund(); - } else { - continue; - } - if (isset($invoiceQtysRefundLimits[$orderItem->getId()])) { - $qty = min($qty, $invoiceQtysRefundLimits[$orderItem->getId()]); - } - } - $qty = min($qty, $invoiceItem->getQty()); + $qty = min( + $this->getQtyToRefund($orderItem, $qtyList, $invoiceRefundLimitsQtyList), + $invoiceItem->getQty() + ); $totalQty += $qty; + + $item = $this->convertor->itemToCreditmemoItem($orderItem); $item->setQty($qty); $creditmemo->addItem($item); } @@ -179,15 +125,7 @@ public function createByInvoice(\Magento\Sales\Model\Order\Invoice $invoice, arr $this->initData($creditmemo, $data); if (!isset($data['shipping_amount'])) { - $isShippingInclTax = $this->taxConfig->displaySalesShippingInclTax($order->getStoreId()); - if ($isShippingInclTax) { - $baseAllowedAmount = $order->getBaseShippingInclTax() - - $order->getBaseShippingRefunded() - - $order->getBaseShippingTaxRefunded(); - } else { - $baseAllowedAmount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded(); - $baseAllowedAmount = min($baseAllowedAmount, $invoice->getBaseShippingAmount()); - } + $baseAllowedAmount = $this->getShippingAmount($invoice); $creditmemo->setBaseShippingAmount($baseAllowedAmount); } @@ -272,11 +210,11 @@ protected function initData($creditmemo, $data) } /** - * @param \Magento\Sales\Api\Data\OrderItemInterface $orderItem + * @param Item $orderItem * @param int $parentQty * @return int */ - private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterface $orderItem, $parentQty) + private function calculateProductOptions(Item $orderItem, $parentQty) { $qty = $parentQty; $productOptions = $orderItem->getProductOptions(); @@ -290,4 +228,113 @@ private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterf } return $qty; } + + /** + * Gets list of quantities based on invoice refunded items. + * + * @param Invoice $invoice + * @return array + */ + private function getInvoiceRefundedQtyList(Invoice $invoice): array + { + $invoiceRefundedQtyList = []; + foreach ($invoice->getOrder()->getCreditmemosCollection() as $creditmemo) { + if ($creditmemo->getState() !== Creditmemo::STATE_CANCELED && + $creditmemo->getInvoiceId() === $invoice->getId() + ) { + foreach ($creditmemo->getAllItems() as $creditmemoItem) { + $orderItemId = $creditmemoItem->getOrderItem()->getId(); + if (isset($invoiceRefundedQtyList[$orderItemId])) { + $invoiceRefundedQtyList[$orderItemId] += $creditmemoItem->getQty(); + } else { + $invoiceRefundedQtyList[$orderItemId] = $creditmemoItem->getQty(); + } + } + } + } + + return $invoiceRefundedQtyList; + } + + /** + * Gets limits of refund based on invoice items. + * + * @param Invoice $invoice + * @return array + */ + private function getInvoiceRefundLimitsQtyList(Invoice $invoice): array + { + $invoiceRefundLimitsQtyList = []; + $invoiceRefundedQtyList = $this->getInvoiceRefundedQtyList($invoice); + + foreach ($invoice->getAllItems() as $invoiceItem) { + $qtyCanBeRefunded = $invoiceItem->getQty(); + $orderItemId = $invoiceItem->getOrderItem()->getId(); + if (isset($invoiceRefundedQtyList[$orderItemId])) { + $qtyCanBeRefunded = $qtyCanBeRefunded - $invoiceRefundedQtyList[$orderItemId]; + } + $invoiceRefundLimitsQtyList[$orderItemId] = $qtyCanBeRefunded; + } + + return $invoiceRefundLimitsQtyList; + } + + /** + * Gets quantity of items to refund based on order item. + * + * @param Item $orderItem + * @param array $qtyList + * @param array $refundLimits + * @return float + */ + private function getQtyToRefund(Item $orderItem, array $qtyList, array $refundLimits = []): float + { + $qty = 0; + if ($orderItem->isDummy()) { + if (isset($qtyList[$orderItem->getParentItemId()])) { + $parentQty = $qtyList[$orderItem->getParentItemId()]; + } elseif ($orderItem->getProductType() === BundlePrice::PRODUCT_TYPE) { + $parentQty = $orderItem->getQtyInvoiced(); + } else { + $parentQty = $orderItem->getParentItem() ? $orderItem->getParentItem()->getQtyToRefund() : 1; + } + $qty = $this->calculateProductOptions($orderItem, $parentQty); + } else { + if (isset($qtyList[$orderItem->getId()])) { + $qty = $qtyList[$orderItem->getId()]; + } elseif (!count($qtyList)) { + $qty = $orderItem->getQtyToRefund(); + } else { + return (float)$qty; + } + + if (isset($refundLimits[$orderItem->getId()])) { + $qty = min($qty, $refundLimits[$orderItem->getId()]); + } + } + + return (float)$qty; + } + + /** + * Gets shipping amount based on invoice. + * + * @param Invoice $invoice + * @return float + */ + private function getShippingAmount(Invoice $invoice): float + { + $order = $invoice->getOrder(); + $isShippingInclTax = $this->taxConfig->displaySalesShippingInclTax($order->getStoreId()); + if ($isShippingInclTax) { + $amount = $order->getBaseShippingInclTax() - + $order->getBaseShippingRefunded() - + $order->getBaseShippingTaxRefunded(); + } else { + $amount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded(); + $amount = min($amount, $invoice->getBaseShippingAmount()); + } + + return (float)$amount; + } } diff --git a/app/code/Magento/Sales/Model/Order/CustomerManagement.php b/app/code/Magento/Sales/Model/Order/CustomerManagement.php index a84d90693e087..466f3ff8adddb 100644 --- a/app/code/Magento/Sales/Model/Order/CustomerManagement.php +++ b/app/code/Magento/Sales/Model/Order/CustomerManagement.php @@ -3,8 +3,10 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Model\Order; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\AlreadyExistsException; use Magento\Quote\Model\Quote\Address as QuoteAddress; @@ -43,6 +45,11 @@ class CustomerManagement implements \Magento\Sales\Api\OrderCustomerManagementIn */ protected $objectCopyService; + /** + * @var \Magento\Quote\Model\Quote\AddressFactory + */ + private $quoteAddressFactory; + /** * @param \Magento\Framework\DataObject\Copy $objectCopyService * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement @@ -50,6 +57,7 @@ class CustomerManagement implements \Magento\Sales\Api\OrderCustomerManagementIn * @param \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory * @param \Magento\Customer\Api\Data\RegionInterfaceFactory $regionFactory * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Quote\Model\Quote\AddressFactory|null $quoteAddressFactory */ public function __construct( \Magento\Framework\DataObject\Copy $objectCopyService, @@ -57,7 +65,8 @@ public function __construct( \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory, \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory, \Magento\Customer\Api\Data\RegionInterfaceFactory $regionFactory, - \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, + \Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory = null ) { $this->objectCopyService = $objectCopyService; $this->accountManagement = $accountManagement; @@ -65,6 +74,9 @@ public function __construct( $this->customerFactory = $customerFactory; $this->addressFactory = $addressFactory; $this->regionFactory = $regionFactory; + $this->quoteAddressFactory = $quoteAddressFactory ?: ObjectManager::getInstance()->get( + \Magento\Quote\Model\Quote\AddressFactory::class + ); } /** @@ -84,6 +96,9 @@ public function create($orderId) ); $addresses = $order->getAddresses(); foreach ($addresses as $address) { + if (!$this->isNeededToSaveAddress($address->getData('quote_address_id'))) { + continue; + } $addressData = $this->objectCopyService->copyFieldsetToTarget( 'order_address', 'to_customer_address', @@ -116,7 +131,28 @@ public function create($orderId) $customer = $this->customerFactory->create(['data' => $customerData]); $account = $this->accountManagement->createAccount($customer); $order->setCustomerId($account->getId()); + $order->setCustomerIsGuest(0); $this->orderRepository->save($order); + return $account; } + + /** + * Check if we need to save address in address book. + * + * @param int $quoteAddressId + * + * @return bool + */ + private function isNeededToSaveAddress($quoteAddressId) + { + $saveInAddressBook = true; + + $quoteAddress = $this->quoteAddressFactory->create()->load($quoteAddressId); + if ($quoteAddress && $quoteAddress->getId()) { + $saveInAddressBook = (int)$quoteAddress->getData('save_in_address_book'); + } + + return $saveInAddressBook; + } } diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender.php b/app/code/Magento/Sales/Model/Order/Email/Sender.php index 8ada6a3f321d2..6d4480c4c45e0 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender.php @@ -84,6 +84,8 @@ protected function checkAndSend(Order $order) $sender->sendCopyTo(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); + + return false; } return true; diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoCommentSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoCommentSender.php index 510bc54dc05b3..ce72f0fee7786 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoCommentSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoCommentSender.php @@ -12,6 +12,7 @@ use Magento\Sales\Model\Order\Email\NotifySender; use Magento\Sales\Model\Order\Address\Renderer; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\DataObject; /** * Class CreditmemoCommentSender @@ -71,13 +72,17 @@ public function send(Creditmemo $creditmemo, $notify = true, $comment = '') 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order), ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_creditmemo_comment_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); return $this->checkAndSend($order, $notify); } diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoSender.php index a4ecd2aa7d000..8004483583114 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoSender.php @@ -14,6 +14,7 @@ use Magento\Sales\Model\ResourceModel\Order\Creditmemo as CreditmemoResource; use Magento\Sales\Model\Order\Address\Renderer; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\DataObject; /** * Class CreditmemoSender @@ -102,7 +103,7 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false) if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) { $order = $creditmemo->getOrder(); - + $transport = [ 'order' => $order, 'creditmemo' => $creditmemo, @@ -113,13 +114,17 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false) 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order), ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_creditmemo_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); if ($this->checkAndSend($order)) { $creditmemo->setEmailSent(true); diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceCommentSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceCommentSender.php index 8f6401ff1cb88..62d13eb8ce681 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceCommentSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceCommentSender.php @@ -12,6 +12,7 @@ use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Address\Renderer; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\DataObject; /** * Class InvoiceCommentSender @@ -71,13 +72,17 @@ public function send(Invoice $invoice, $notify = true, $comment = '') 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order), ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_invoice_comment_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); return $this->checkAndSend($order, $notify); } diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceSender.php index c3083ddae2dd8..994fd79945cfd 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceSender.php @@ -14,6 +14,7 @@ use Magento\Sales\Model\ResourceModel\Order\Invoice as InvoiceResource; use Magento\Sales\Model\Order\Address\Renderer; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\DataObject; /** * Class InvoiceSender @@ -113,13 +114,17 @@ public function send(Invoice $invoice, $forceSyncMode = false) 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order) ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_invoice_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); if ($this->checkAndSend($order)) { $invoice->setEmailSent(true); diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/OrderCommentSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/OrderCommentSender.php index c8c1eb10d4864..98cb9304a494b 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/OrderCommentSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/OrderCommentSender.php @@ -11,6 +11,7 @@ use Magento\Sales\Model\Order\Email\NotifySender; use Magento\Sales\Model\Order\Address\Renderer; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\DataObject; /** * Class OrderCommentSender @@ -68,13 +69,17 @@ public function send(Order $order, $notify = true, $comment = '') 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order), ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_order_comment_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); return $this->checkAndSend($order, $notify); } diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentCommentSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentCommentSender.php index 80c2ed356061b..664f8ec9fc7e5 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentCommentSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentCommentSender.php @@ -12,6 +12,7 @@ use Magento\Sales\Model\Order\Shipment; use Magento\Sales\Model\Order\Address\Renderer; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\DataObject; /** * Class ShipmentCommentSender @@ -71,13 +72,17 @@ public function send(Shipment $shipment, $notify = true, $comment = '') 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order), ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_shipment_comment_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); return $this->checkAndSend($order, $notify); } diff --git a/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php b/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php index ff2311067ba0a..6729c746f5565 100644 --- a/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php +++ b/app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php @@ -14,6 +14,7 @@ use Magento\Sales\Model\ResourceModel\Order\Shipment as ShipmentResource; use Magento\Sales\Model\Order\Address\Renderer; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\DataObject; /** * Class ShipmentSender @@ -102,7 +103,7 @@ public function send(Shipment $shipment, $forceSyncMode = false) if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) { $order = $shipment->getOrder(); - + $transport = [ 'order' => $order, 'shipment' => $shipment, @@ -113,13 +114,17 @@ public function send(Shipment $shipment, $forceSyncMode = false) 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order) ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_shipment_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); if ($this->checkAndSend($order)) { $shipment->setEmailSent(true); diff --git a/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php b/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php index 93c6f19b08690..7ec089b882972 100644 --- a/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php +++ b/app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php @@ -5,7 +5,9 @@ */ namespace Magento\Sales\Model\Order\Email; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Mail\Template\TransportBuilder; +use Magento\Framework\Mail\Template\TransportBuilderByStore; use Magento\Sales\Model\Order\Email\Container\IdentityInterface; use Magento\Sales\Model\Order\Email\Container\Template; @@ -26,19 +28,29 @@ class SenderBuilder */ protected $transportBuilder; + /** + * @var TransportBuilderByStore + */ + private $transportBuilderByStore; + /** * @param Template $templateContainer * @param IdentityInterface $identityContainer * @param TransportBuilder $transportBuilder + * @param TransportBuilderByStore $transportBuilderByStore */ public function __construct( Template $templateContainer, IdentityInterface $identityContainer, - TransportBuilder $transportBuilder + TransportBuilder $transportBuilder, + TransportBuilderByStore $transportBuilderByStore = null ) { $this->templateContainer = $templateContainer; $this->identityContainer = $identityContainer; $this->transportBuilder = $transportBuilder; + $this->transportBuilderByStore = $transportBuilderByStore ?: ObjectManager::getInstance()->get( + TransportBuilderByStore::class + ); } /** @@ -98,6 +110,9 @@ protected function configureEmailTemplate() $this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId()); $this->transportBuilder->setTemplateOptions($this->templateContainer->getTemplateOptions()); $this->transportBuilder->setTemplateVars($this->templateContainer->getTemplateVars()); - $this->transportBuilder->setFrom($this->identityContainer->getEmailIdentity()); + $this->transportBuilderByStore->setFromByStore( + $this->identityContainer->getEmailIdentity(), + $this->identityContainer->getStore()->getId() + ); } } diff --git a/app/code/Magento/Sales/Model/Order/Invoice.php b/app/code/Magento/Sales/Model/Order/Invoice.php index 014ad8fd5fe3a..3f2fa1f72f6e5 100644 --- a/app/code/Magento/Sales/Model/Order/Invoice.php +++ b/app/code/Magento/Sales/Model/Order/Invoice.php @@ -407,6 +407,9 @@ public function void() */ public function cancel() { + if (!$this->canCancel()) { + return $this; + } $order = $this->getOrder(); $order->getPayment()->cancelInvoice($this); foreach ($this->getAllItems() as $item) { diff --git a/app/code/Magento/Sales/Model/Order/Invoice/CommentRepository.php b/app/code/Magento/Sales/Model/Order/Invoice/CommentRepository.php index 858490132e0c7..00b1bb62556f7 100644 --- a/app/code/Magento/Sales/Model/Order/Invoice/CommentRepository.php +++ b/app/code/Magento/Sales/Model/Order/Invoice/CommentRepository.php @@ -7,6 +7,7 @@ use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\CouldNotDeleteException; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Sales\Api\Data\InvoiceCommentInterface; @@ -14,7 +15,15 @@ use Magento\Sales\Api\Data\InvoiceCommentSearchResultInterfaceFactory; use Magento\Sales\Api\InvoiceCommentRepositoryInterface; use Magento\Sales\Model\Spi\InvoiceCommentResourceInterface; +use Magento\Sales\Model\Order\Email\Sender\InvoiceCommentSender; +use Magento\Sales\Api\InvoiceRepositoryInterface; +use Psr\Log\LoggerInterface; +/** + * Class CommentRepository + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class CommentRepository implements InvoiceCommentRepositoryInterface { /** @@ -37,22 +46,48 @@ class CommentRepository implements InvoiceCommentRepositoryInterface */ private $collectionProcessor; + /** + * @var InvoiceCommentSender + */ + private $invoiceCommentSender; + + /** + * @var InvoiceRepositoryInterface + */ + private $invoiceRepository; + + /** + * @var LoggerInterface + */ + private $logger; + /** * @param InvoiceCommentResourceInterface $commentResource * @param InvoiceCommentInterfaceFactory $commentFactory * @param InvoiceCommentSearchResultInterfaceFactory $searchResultFactory * @param CollectionProcessorInterface $collectionProcessor + * @param InvoiceCommentSender|null $invoiceCommentSender + * @param InvoiceRepositoryInterface|null $invoiceRepository + * @param LoggerInterface|null $logger */ public function __construct( InvoiceCommentResourceInterface $commentResource, InvoiceCommentInterfaceFactory $commentFactory, InvoiceCommentSearchResultInterfaceFactory $searchResultFactory, - CollectionProcessorInterface $collectionProcessor + CollectionProcessorInterface $collectionProcessor, + InvoiceCommentSender $invoiceCommentSender = null, + InvoiceRepositoryInterface $invoiceRepository = null, + LoggerInterface $logger = null ) { $this->commentResource = $commentResource; $this->commentFactory = $commentFactory; $this->searchResultFactory = $searchResultFactory; $this->collectionProcessor = $collectionProcessor; + $this->invoiceCommentSender = $invoiceCommentSender + ?:ObjectManager::getInstance()->get(InvoiceCommentSender::class); + $this->invoiceRepository = $invoiceRepository + ?:ObjectManager::getInstance()->get(InvoiceRepositoryInterface::class); + $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class); } /** @@ -99,6 +134,13 @@ public function save(InvoiceCommentInterface $entity) } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not save the invoice comment.'), $e); } + + try { + $invoice = $this->invoiceRepository->get($entity->getParentId()); + $this->invoiceCommentSender->send($invoice, $entity->getIsCustomerNotified(), $entity->getComment()); + } catch (\Exception $exception) { + $this->logger->warning('Something went wrong while sending email.'); + } return $entity; } } diff --git a/app/code/Magento/Sales/Model/Order/Invoice/Sender/EmailSender.php b/app/code/Magento/Sales/Model/Order/Invoice/Sender/EmailSender.php index 5daab1f4d9bd3..aa0687bee504f 100644 --- a/app/code/Magento/Sales/Model/Order/Invoice/Sender/EmailSender.php +++ b/app/code/Magento/Sales/Model/Order/Invoice/Sender/EmailSender.php @@ -7,9 +7,12 @@ use Magento\Sales\Model\Order\Email\Sender; use Magento\Sales\Model\Order\Invoice\SenderInterface; +use Magento\Framework\DataObject; /** * Email notification sender for Invoice. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class EmailSender extends Sender implements SenderInterface { @@ -106,13 +109,17 @@ public function send( 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order), ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_invoice_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); if ($this->checkAndSend($order)) { $invoice->setEmailSent(true); diff --git a/app/code/Magento/Sales/Model/Order/Payment/Transaction.php b/app/code/Magento/Sales/Model/Order/Payment/Transaction.php index b9b7a142095d9..7540ee1902b57 100644 --- a/app/code/Magento/Sales/Model/Order/Payment/Transaction.php +++ b/app/code/Magento/Sales/Model/Order/Payment/Transaction.php @@ -733,7 +733,7 @@ public function getTransactionTypes() */ public function getOrderWebsiteId() { - if (is_null($this->_orderWebsiteId)) { + if ($this->_orderWebsiteId === null) { $this->_orderWebsiteId = (int)$this->getResource()->getOrderWebsiteId($this->getOrderId()); } return $this->_orderWebsiteId; diff --git a/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php b/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php index 850e9cf08413b..1b80d08e68cda 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php @@ -804,7 +804,7 @@ protected function _getRenderer($type) throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid renderer model.')); } - if (is_null($this->_renderers[$type]['renderer'])) { + if ($this->_renderers[$type]['renderer'] === null) { $this->_renderers[$type]['renderer'] = $this->_pdfItemsFactory->get($this->_renderers[$type]['model']); } @@ -953,7 +953,7 @@ public function newPage(array $settings = []) * feed int; x position (required) * font string; font style, optional: bold, italic, regular * font_file string; path to font file (optional for use your custom font) - * font_size int; font size (default 7) + * font_size int; font size (default 10) * align string; text align (also see feed parametr), optional left, right * height int;line spacing (default 10) * @@ -1005,24 +1005,8 @@ public function drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSet foreach ($lines as $line) { $maxHeight = 0; foreach ($line as $column) { - $fontSize = empty($column['font_size']) ? 10 : $column['font_size']; - if (!empty($column['font_file'])) { - $font = \Zend_Pdf_Font::fontWithPath($column['font_file']); - $page->setFont($font, $fontSize); - } else { - $fontStyle = empty($column['font']) ? 'regular' : $column['font']; - switch ($fontStyle) { - case 'bold': - $font = $this->_setFontBold($page, $fontSize); - break; - case 'italic': - $font = $this->_setFontItalic($page, $fontSize); - break; - default: - $font = $this->_setFontRegular($page, $fontSize); - break; - } - } + $font = $this->setFont($page, $column); + $fontSize = $column['font_size']; if (!is_array($column['text'])) { $column['text'] = [$column['text']]; @@ -1033,6 +1017,8 @@ public function drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSet foreach ($column['text'] as $part) { if ($this->y - $lineSpacing < 15) { $page = $this->newPage($pageSettings); + $font = $this->setFont($page, $column); + $fontSize = $column['font_size']; } $feed = $column['feed']; @@ -1066,4 +1052,42 @@ public function drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSet return $page; } + + /** + * Set page font. + * + * column array format + * font string; font style, optional: bold, italic, regular + * font_file string; path to font file (optional for use your custom font) + * font_size int; font size (default 10) + * + * @param \Zend_Pdf_Page $page + * @param array $column + * @return \Zend_Pdf_Resource_Font + * @throws \Zend_Pdf_Exception + */ + private function setFont($page, &$column) + { + $fontSize = empty($column['font_size']) ? 10 : $column['font_size']; + $column['font_size'] = $fontSize; + if (!empty($column['font_file'])) { + $font = \Zend_Pdf_Font::fontWithPath($column['font_file']); + $page->setFont($font, $fontSize); + } else { + $fontStyle = empty($column['font']) ? 'regular' : $column['font']; + switch ($fontStyle) { + case 'bold': + $font = $this->_setFontBold($page, $fontSize); + break; + case 'italic': + $font = $this->_setFontItalic($page, $fontSize); + break; + default: + $font = $this->_setFontRegular($page, $fontSize); + break; + } + } + + return $font; + } } diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php b/app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php index 6e2265315245d..74f3eebf8fcb9 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php @@ -75,12 +75,12 @@ public function __construct( protected function _drawHeader(\Zend_Pdf_Page $page) { $this->_setFontRegular($page, 10); - $page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); + $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y - 30); $this->y -= 10; - $page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0)); + $page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0)); //columns headers $lines[0][] = ['text' => __('Products'), 'feed' => 35]; diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php b/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php index 2912969a99718..ba99ed083e952 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php @@ -82,12 +82,12 @@ protected function _drawHeader(\Zend_Pdf_Page $page) { /* Add table head */ $this->_setFontRegular($page, 10); - $page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); + $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y - 15); $this->y -= 10; - $page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0)); + $page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0)); //columns headers $lines[0][] = ['text' => __('Products'), 'feed' => 35]; @@ -96,7 +96,7 @@ protected function _drawHeader(\Zend_Pdf_Page $page) $lines[0][] = ['text' => __('Qty'), 'feed' => 435, 'align' => 'right']; - $lines[0][] = ['text' => __('Price'), 'feed' => 360, 'align' => 'right']; + $lines[0][] = ['text' => __('Price'), 'feed' => 375, 'align' => 'right']; $lines[0][] = ['text' => __('Tax'), 'feed' => 495, 'align' => 'right']; diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php b/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php index bb6078e425900..7d62e839ad924 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php @@ -81,8 +81,8 @@ public function draw() // draw item Prices $i = 0; $prices = $this->getItemPricesForDisplay(); - $feedPrice = 395; - $feedSubtotal = $feedPrice + 170; + $feedPrice = 375; + $feedSubtotal = $feedPrice + 190; foreach ($prices as $priceData) { if (isset($priceData['label'])) { // draw Price label diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php b/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php index be74efda2d265..b171fccdeb05b 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php @@ -80,12 +80,12 @@ protected function _drawHeader(\Zend_Pdf_Page $page) { /* Add table head */ $this->_setFontRegular($page, 10); - $page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); + $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y - 15); $this->y -= 10; - $page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0)); + $page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0)); //columns headers $lines[0][] = ['text' => __('Products'), 'feed' => 100]; diff --git a/app/code/Magento/Sales/Model/Order/Shipment.php b/app/code/Magento/Sales/Model/Order/Shipment.php index 3adf1203981d0..64e20d5a69041 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment.php +++ b/app/code/Magento/Sales/Model/Order/Shipment.php @@ -93,6 +93,11 @@ class Shipment extends AbstractModel implements EntityInterface, ShipmentInterfa */ protected $orderRepository; + /** + * @var \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection|null + */ + private $tracksCollection = null; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -257,8 +262,6 @@ public function register() if (!$item->getOrderItem()->isDummy(true)) { $totalQty += $item->getQty(); } - } else { - $item->isDeleted(true); } } @@ -333,16 +336,11 @@ public function addItem(\Magento\Sales\Model\Order\Shipment\Item $item) */ public function getTracksCollection() { - if (!$this->hasData(ShipmentInterface::TRACKS)) { - $this->setTracks($this->_trackCollectionFactory->create()->setShipmentFilter($this->getId())); - - if ($this->getId()) { - foreach ($this->getTracks() as $track) { - $track->setShipment($this); - } - } + if ($this->tracksCollection === null) { + $this->tracksCollection = $this->_trackCollectionFactory->create()->setShipmentFilter($this->getId()); } - return $this->getTracks(); + + return $this->tracksCollection; } /** diff --git a/app/code/Magento/Sales/Model/Order/Shipment/CommentRepository.php b/app/code/Magento/Sales/Model/Order/Shipment/CommentRepository.php index b0d3b03aec4ed..4f6e6ee9c2241 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment/CommentRepository.php +++ b/app/code/Magento/Sales/Model/Order/Shipment/CommentRepository.php @@ -7,6 +7,7 @@ use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; use Magento\Framework\Api\SearchCriteriaInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\CouldNotDeleteException; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Sales\Api\Data\ShipmentCommentInterface; @@ -14,7 +15,15 @@ use Magento\Sales\Api\Data\ShipmentCommentSearchResultInterfaceFactory; use Magento\Sales\Api\ShipmentCommentRepositoryInterface; use Magento\Sales\Model\Spi\ShipmentCommentResourceInterface; +use Magento\Sales\Model\Order\Email\Sender\ShipmentCommentSender; +use Magento\Sales\Api\ShipmentRepositoryInterface; +use Psr\Log\LoggerInterface; +/** + * Class CommentRepository + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class CommentRepository implements ShipmentCommentRepositoryInterface { /** @@ -37,22 +46,48 @@ class CommentRepository implements ShipmentCommentRepositoryInterface */ private $collectionProcessor; + /** + * @var ShipmentCommentSender + */ + private $shipmentCommentSender; + + /** + * @var ShipmentRepositoryInterface + */ + private $shipmentRepository; + + /** + * @var LoggerInterface + */ + private $logger; + /** * @param ShipmentCommentResourceInterface $commentResource * @param ShipmentCommentInterfaceFactory $commentFactory * @param ShipmentCommentSearchResultInterfaceFactory $searchResultFactory * @param CollectionProcessorInterface $collectionProcessor + * @param ShipmentCommentSender|null $shipmentCommentSender + * @param ShipmentRepositoryInterface|null $shipmentRepository + * @param LoggerInterface|null $logger */ public function __construct( ShipmentCommentResourceInterface $commentResource, ShipmentCommentInterfaceFactory $commentFactory, ShipmentCommentSearchResultInterfaceFactory $searchResultFactory, - CollectionProcessorInterface $collectionProcessor + CollectionProcessorInterface $collectionProcessor, + ShipmentCommentSender $shipmentCommentSender = null, + ShipmentRepositoryInterface $shipmentRepository = null, + LoggerInterface $logger = null ) { $this->commentResource = $commentResource; $this->commentFactory = $commentFactory; $this->searchResultFactory = $searchResultFactory; $this->collectionProcessor = $collectionProcessor; + $this->shipmentCommentSender = $shipmentCommentSender + ?: ObjectManager::getInstance()->get(ShipmentCommentSender::class); + $this->shipmentRepository = $shipmentRepository + ?: ObjectManager::getInstance()->get(ShipmentRepositoryInterface::class); + $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class); } /** @@ -99,6 +134,13 @@ public function save(ShipmentCommentInterface $entity) } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not save the shipment comment.'), $e); } + + try { + $shipment = $this->shipmentRepository->get($entity->getParentId()); + $this->shipmentCommentSender->send($shipment, $entity->getIsCustomerNotified(), $entity->getComment()); + } catch (\Exception $exception) { + $this->logger->warning('Something went wrong while sending email.'); + } return $entity; } } diff --git a/app/code/Magento/Sales/Model/Order/Shipment/ItemCreation.php b/app/code/Magento/Sales/Model/Order/Shipment/ItemCreation.php index 8c018ecee544b..f600c65e05f52 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment/ItemCreation.php +++ b/app/code/Magento/Sales/Model/Order/Shipment/ItemCreation.php @@ -43,6 +43,7 @@ public function getOrderItemId() public function setOrderItemId($orderItemId) { $this->orderItemId = $orderItemId; + return $this; } /** @@ -59,6 +60,7 @@ public function getQty() public function setQty($qty) { $this->qty = $qty; + return $this; } /** diff --git a/app/code/Magento/Sales/Model/Order/Shipment/OrderRegistrar.php b/app/code/Magento/Sales/Model/Order/Shipment/OrderRegistrar.php index 9001267f6bc4a..69077749902b5 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment/OrderRegistrar.php +++ b/app/code/Magento/Sales/Model/Order/Shipment/OrderRegistrar.php @@ -17,12 +17,19 @@ class OrderRegistrar implements \Magento\Sales\Model\Order\Shipment\OrderRegistr */ public function register(OrderInterface $order, ShipmentInterface $shipment) { - /** @var \Magento\Sales\Api\Data\ShipmentItemInterface|\Magento\Sales\Model\Order\Shipment\Item $item */ + $totalQty = 0; + /** @var \Magento\Sales\Model\Order\Shipment\Item $item */ foreach ($shipment->getItems() as $item) { if ($item->getQty() > 0) { $item->register(); + + if (!$item->getOrderItem()->isDummy(true)) { + $totalQty += $item->getQty(); + } } } + $shipment->setTotalQty($totalQty); + return $order; } } diff --git a/app/code/Magento/Sales/Model/Order/Shipment/Sender/EmailSender.php b/app/code/Magento/Sales/Model/Order/Shipment/Sender/EmailSender.php index 7c17a2d2d2f64..0a393548069f5 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment/Sender/EmailSender.php +++ b/app/code/Magento/Sales/Model/Order/Shipment/Sender/EmailSender.php @@ -7,9 +7,12 @@ use Magento\Sales\Model\Order\Email\Sender; use Magento\Sales\Model\Order\Shipment\SenderInterface; +use Magento\Framework\DataObject; /** * Email notification sender for Shipment. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class EmailSender extends Sender implements SenderInterface { @@ -106,13 +109,17 @@ public function send( 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order) ]; + $transportObject = new DataObject($transport); + /** + * Event argument `transport` is @deprecated. Use `transportObject` instead. + */ $this->eventManager->dispatch( 'email_shipment_set_template_vars_before', - ['sender' => $this, 'transport' => $transport] + ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject] ); - $this->templateContainer->setTemplateVars($transport); + $this->templateContainer->setTemplateVars($transportObject->getData()); if ($this->checkAndSend($order)) { $shipment->setEmailSent(true); diff --git a/app/code/Magento/Sales/Model/Order/Shipment/TrackRepository.php b/app/code/Magento/Sales/Model/Order/Shipment/TrackRepository.php index 5bcf579a1cbf4..b412d4186b1ca 100644 --- a/app/code/Magento/Sales/Model/Order/Shipment/TrackRepository.php +++ b/app/code/Magento/Sales/Model/Order/Shipment/TrackRepository.php @@ -14,6 +14,7 @@ use Magento\Sales\Api\Data\ShipmentTrackSearchResultInterfaceFactory; use Magento\Sales\Api\ShipmentTrackRepositoryInterface; use Magento\Sales\Model\Spi\ShipmentTrackResourceInterface; +use Psr\Log\LoggerInterface; class TrackRepository implements ShipmentTrackRepositoryInterface { @@ -37,23 +38,30 @@ class TrackRepository implements ShipmentTrackRepositoryInterface */ private $collectionProcessor; + /** + * @var LoggerInterface + */ + private $logger; + /** * @param ShipmentTrackResourceInterface $trackResource * @param ShipmentTrackInterfaceFactory $trackFactory * @param ShipmentTrackSearchResultInterfaceFactory $searchResultFactory * @param CollectionProcessorInterface $collectionProcessor + * @param LoggerInterface|null $logger */ public function __construct( ShipmentTrackResourceInterface $trackResource, ShipmentTrackInterfaceFactory $trackFactory, ShipmentTrackSearchResultInterfaceFactory $searchResultFactory, - CollectionProcessorInterface $collectionProcessor + CollectionProcessorInterface $collectionProcessor, + LoggerInterface $logger = null ) { - $this->trackResource = $trackResource; $this->trackFactory = $trackFactory; $this->searchResultFactory = $searchResultFactory; $this->collectionProcessor = $collectionProcessor; + $this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance()->get(LoggerInterface::class); } /** @@ -64,6 +72,7 @@ public function getList(SearchCriteriaInterface $searchCriteria) $searchResult = $this->searchResultFactory->create(); $this->collectionProcessor->process($searchCriteria, $searchResult); $searchResult->setSearchCriteria($searchCriteria); + return $searchResult; } @@ -74,6 +83,7 @@ public function get($id) { $entity = $this->trackFactory->create(); $this->trackResource->load($entity, $id); + return $entity; } @@ -85,8 +95,10 @@ public function delete(ShipmentTrackInterface $entity) try { $this->trackResource->delete($entity); } catch (\Exception $e) { + $this->logger->error($e->getMessage()); throw new CouldNotDeleteException(__('Could not delete the shipment tracking.'), $e); } + return true; } @@ -98,8 +110,10 @@ public function save(ShipmentTrackInterface $entity) try { $this->trackResource->save($entity); } catch (\Exception $e) { + $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not save the shipment tracking.'), $e); } + return $entity; } @@ -109,6 +123,7 @@ public function save(ShipmentTrackInterface $entity) public function deleteById($id) { $entity = $this->get($id); + return $this->delete($entity); } } diff --git a/app/code/Magento/Sales/Model/Order/ShipmentDocumentFactory.php b/app/code/Magento/Sales/Model/Order/ShipmentDocumentFactory.php index 7382fdffbd1b4..c0a3f84e8846d 100644 --- a/app/code/Magento/Sales/Model/Order/ShipmentDocumentFactory.php +++ b/app/code/Magento/Sales/Model/Order/ShipmentDocumentFactory.php @@ -14,6 +14,7 @@ use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\Data\ShipmentCommentCreationInterface; use Magento\Sales\Api\Data\ShipmentCreationArgumentsInterface; +use Magento\Sales\Api\Data\OrderItemInterface; /** * Class ShipmentDocumentFactory @@ -77,49 +78,63 @@ public function create( array $packages = [], ShipmentCreationArgumentsInterface $arguments = null ) { - $shipmentItems = $this->itemsToArray($items); + $shipmentItems = empty($items) + ? $this->getQuantitiesFromOrderItems($order->getItems()) + : $this->getQuantitiesFromShipmentItems($items); + /** @var Shipment $shipment */ $shipment = $this->shipmentFactory->create( $order, $shipmentItems ); - $this->prepareTracks($shipment, $tracks); + + foreach ($tracks as $track) { + $hydrator = $this->hydratorPool->getHydrator( + \Magento\Sales\Api\Data\ShipmentTrackCreationInterface::class + ); + $shipment->addTrack($this->trackFactory->create(['data' => $hydrator->extract($track)])); + } + if ($comment) { $shipment->addComment( $comment->getComment(), $appendComment, $comment->getIsVisibleOnFront() ); + + if ($appendComment) { + $shipment->setCustomerNote($comment->getComment()); + $shipment->setCustomerNoteNotify($appendComment); + } } return $shipment; } /** - * Adds tracks to the shipment. + * Translate OrderItemInterface array to product id => product quantity array. * - * @param ShipmentInterface $shipment - * @param ShipmentTrackCreationInterface[] $tracks - * @return ShipmentInterface + * @param OrderItemInterface[] $items + * @return int[] */ - private function prepareTracks(\Magento\Sales\Api\Data\ShipmentInterface $shipment, array $tracks) + private function getQuantitiesFromOrderItems(array $items) { - foreach ($tracks as $track) { - $hydrator = $this->hydratorPool->getHydrator( - \Magento\Sales\Api\Data\ShipmentTrackCreationInterface::class - ); - $shipment->addTrack($this->trackFactory->create(['data' => $hydrator->extract($track)])); + $shipmentItems = []; + foreach ($items as $item) { + if (!$item->getIsVirtual() && (!$item->getParentItem() || $item->isShipSeparately())) { + $shipmentItems[$item->getItemId()] = $item->getQtyOrdered(); + } } - return $shipment; + return $shipmentItems; } /** - * Convert items to array + * Translate ShipmentItemCreationInterface array to product id => product quantity array. * * @param ShipmentItemCreationInterface[] $items - * @return array + * @return int[] */ - private function itemsToArray(array $items = []) + private function getQuantitiesFromShipmentItems(array $items) { $shipmentItems = []; foreach ($items as $item) { diff --git a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php index dcb2cdf1d8ed9..642f8647ef56b 100644 --- a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php +++ b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php @@ -96,14 +96,17 @@ protected function prepareItems( \Magento\Sales\Model\Order $order, array $items = [] ) { - $totalQty = 0; + $shipmentItems = []; foreach ($order->getAllItems() as $orderItem) { - if (!$this->canShipItem($orderItem, $items)) { + if ($this->validateItem($orderItem, $items) === false) { continue; } /** @var \Magento\Sales\Model\Order\Shipment\Item $item */ $item = $this->converter->itemToShipmentItem($orderItem); + if ($orderItem->getIsVirtual() || ($orderItem->getParentItemId() && !$orderItem->isShipSeparately())) { + $item->isDeleted(true); + } if ($orderItem->isDummy(true)) { $qty = 0; @@ -121,8 +124,7 @@ protected function prepareItems( $qty = min($qty, $orderItem->getSimpleQtyToShip()); $item->setQty($this->castQty($orderItem, $qty)); - $shipment->addItem($item); - + $shipmentItems[] = $item; continue; } else { $qty = 1; @@ -141,10 +143,65 @@ protected function prepareItems( } } - $totalQty += $qty; - $item->setQty($this->castQty($orderItem, $qty)); - $shipment->addItem($item); + $shipmentItems[] = $item; + } + return $this->setItemsToShipment($shipment, $shipmentItems); + } + + /** + * Validate order item before shipment + * + * @param Item $orderItem + * @param array $items + * @return bool + */ + private function validateItem(\Magento\Sales\Model\Order\Item $orderItem, array $items) + { + if (!$this->canShipItem($orderItem, $items)) { + return false; + } + + // Remove from shipment items without qty or with qty=0 + if (!$orderItem->isDummy(true) + && (!isset($items[$orderItem->getId()]) || $items[$orderItem->getId()] <= 0) + ) { + return false; + } + return true; + } + + /** + * Set prepared items to shipment document + * + * @param \Magento\Sales\Api\Data\ShipmentInterface $shipment + * @param array $shipmentItems + * @return \Magento\Sales\Api\Data\ShipmentInterface + */ + private function setItemsToShipment(\Magento\Sales\Api\Data\ShipmentInterface $shipment, $shipmentItems) + { + $totalQty = 0; + + /** + * Verify that composite products shipped separately has children, if not -> remove from collection + */ + /** @var \Magento\Sales\Model\Order\Shipment\Item $shipmentItem */ + foreach ($shipmentItems as $key => $shipmentItem) { + if ($shipmentItem->getOrderItem()->getHasChildren() + && $shipmentItem->getOrderItem()->isShipSeparately() + ) { + $containerId = $shipmentItem->getOrderItem()->getId(); + $childItems = array_filter($shipmentItems, function ($item) use ($containerId) { + return $containerId == $item->getOrderItem()->getParentItemId(); + }); + + if (count($childItems) <= 0) { + unset($shipmentItems[$key]); + continue; + } + } + $totalQty += $shipmentItem->getQty(); + $shipment->addItem($shipmentItem); } return $shipment->setTotalQty($totalQty); } diff --git a/app/code/Magento/Sales/Model/OrderIncrementIdChecker.php b/app/code/Magento/Sales/Model/OrderIncrementIdChecker.php new file mode 100644 index 0000000000000..c0000915a7d57 --- /dev/null +++ b/app/code/Magento/Sales/Model/OrderIncrementIdChecker.php @@ -0,0 +1,51 @@ +resourceModel = $resourceModel; + } + + /** + * Check if order increment ID is already used. + * + * Method can be used to avoid collisions of order IDs. + * + * @param int $orderIncrementId + * @return bool + */ + public function isIncrementIdUsed($orderIncrementId) + { + /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */ + $adapter = $this->resourceModel->getConnection(); + $bind = [':increment_id' => $orderIncrementId]; + /** @var \Magento\Framework\DB\Select $select */ + $select = $adapter->select(); + $select->from($this->resourceModel->getMainTable(), 'entity_id')->where('increment_id = :increment_id'); + $entity_id = $adapter->fetchOne($select, $bind); + if ($entity_id > 0) { + return true; + } + + return false; + } +} diff --git a/app/code/Magento/Sales/Model/OrderRepository.php b/app/code/Magento/Sales/Model/OrderRepository.php index 26e833c44d70a..691b803166050 100644 --- a/app/code/Magento/Sales/Model/OrderRepository.php +++ b/app/code/Magento/Sales/Model/OrderRepository.php @@ -5,7 +5,9 @@ */ namespace Magento\Sales\Model; +use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\InputException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Sales\Api\Data\OrderExtensionFactory; @@ -15,7 +17,6 @@ use Magento\Sales\Api\Data\ShippingAssignmentInterface; use Magento\Sales\Model\Order\ShippingAssignmentBuilder; use Magento\Sales\Model\ResourceModel\Metadata; -use Magento\Framework\App\ObjectManager; /** * Repository class @@ -54,6 +55,11 @@ class OrderRepository implements \Magento\Sales\Api\OrderRepositoryInterface */ protected $registry = []; + /** + * @var JoinProcessorInterface + */ + private $extensionAttributesJoinProcessor; + /** * Constructor * @@ -61,12 +67,14 @@ class OrderRepository implements \Magento\Sales\Api\OrderRepositoryInterface * @param SearchResultFactory $searchResultFactory * @param CollectionProcessorInterface|null $collectionProcessor * @param \Magento\Sales\Api\Data\OrderExtensionFactory|null $orderExtensionFactory + * @param JoinProcessorInterface $extensionAttributesJoinProcessor */ public function __construct( Metadata $metadata, SearchResultFactory $searchResultFactory, CollectionProcessorInterface $collectionProcessor = null, - \Magento\Sales\Api\Data\OrderExtensionFactory $orderExtensionFactory = null + \Magento\Sales\Api\Data\OrderExtensionFactory $orderExtensionFactory = null, + JoinProcessorInterface $extensionAttributesJoinProcessor = null ) { $this->metadata = $metadata; $this->searchResultFactory = $searchResultFactory; @@ -74,6 +82,8 @@ public function __construct( ->get(\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class); $this->orderExtensionFactory = $orderExtensionFactory ?: ObjectManager::getInstance() ->get(\Magento\Sales\Api\Data\OrderExtensionFactory::class); + $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor + ?: ObjectManager::getInstance()->get(JoinProcessorInterface::class); } /** @@ -112,6 +122,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr /** @var \Magento\Sales\Api\Data\OrderSearchResultInterface $searchResult */ $searchResult = $this->searchResultFactory->create(); $this->collectionProcessor->process($searchCriteria, $searchResult); + $this->extensionAttributesJoinProcessor->process($searchResult); $searchResult->setSearchCriteria($searchCriteria); foreach ($searchResult->getItems() as $order) { $this->setShippingAssignments($order); diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Creditmemo.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Creditmemo.php index f95a3206ce786..5ecbbd777a14e 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Creditmemo.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Creditmemo.php @@ -50,6 +50,10 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) $object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId()); } + if (!$object->getInvoiceId() && $object->getInvoice()) { + $object->setInvoiceId($object->getInvoice()->getId()); + } + return parent::_beforeSave($object); } } diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Relation.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Relation.php index 5851b2d936139..9c8671d02c578 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Relation.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Relation.php @@ -62,8 +62,8 @@ public function processRelation(\Magento\Framework\Model\AbstractModel $object) $this->shipmentItemResource->save($item); } } - if (null !== $object->getTracks()) { - foreach ($object->getTracks() as $track) { + if (null !== $object->getTracksCollection()) { + foreach ($object->getTracksCollection() as $track) { $track->setParentId($object->getId()); $this->shipmentTrackResource->save($track); } diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Track.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Track.php index 4879df7d5f44a..9790983ab857b 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Track.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Shipment/Track.php @@ -5,6 +5,7 @@ */ namespace Magento\Sales\Model\ResourceModel\Order\Shipment; +use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Model\ResourceModel\EntityAbstract as SalesResource; use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot; use Magento\Sales\Model\Spi\ShipmentTrackResourceInterface; @@ -74,7 +75,7 @@ protected function _construct() * * @param \Magento\Framework\Model\AbstractModel $object * @return $this - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { @@ -86,11 +87,16 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) parent::_beforeSave($object); $errors = $this->validator->validate($object); if (!empty($errors)) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __("Cannot save track:\n%1", implode("\n", $errors)) ); } + if ($object->getShipment()->getOrder()->getId() != $object->getOrderId()) { + $errorMessage = 'Shipment with requested ID %1 doesn\'t correspond with Order with requested ID %2.'; + throw new LocalizedException(__($errorMessage, $object->getParentId(), $object->getOrderId())); + } + return $this; } } diff --git a/app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedAtListProvider.php b/app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedAtListProvider.php new file mode 100644 index 0000000000000..846fa46572fde --- /dev/null +++ b/app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedAtListProvider.php @@ -0,0 +1,60 @@ +connection = $resourceConnection->getConnection('sales'); + $this->resourceConnection = $resourceConnection; + } + + /** + * @inheritdoc + */ + public function getIds($mainTableName, $gridTableName) + { + $mainTableName = $this->resourceConnection->getTableName($mainTableName); + $gridTableName = $this->resourceConnection->getTableName($gridTableName); + $select = $this->connection->select() + ->from($mainTableName, [$mainTableName . '.entity_id']) + ->joinInner( + [$gridTableName => $gridTableName], + sprintf( + '%s.entity_id = %s.entity_id AND %s.updated_at > %s.updated_at', + $mainTableName, + $gridTableName, + $mainTableName, + $gridTableName + ), + [] + ); + + return $this->connection->fetchAll($select, [], \Zend_Db::FETCH_COLUMN); + } +} diff --git a/app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedIdListProvider.php b/app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedIdListProvider.php index 59906c79215fa..42c6e9d650315 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedIdListProvider.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedIdListProvider.php @@ -38,10 +38,12 @@ public function __construct( */ public function getIds($mainTableName, $gridTableName) { + $mainTableName = $this->resourceConnection->getTableName($mainTableName); + $gridTableName = $this->resourceConnection->getTableName($gridTableName); $select = $this->getConnection()->select() - ->from($this->getConnection()->getTableName($mainTableName), [$mainTableName . '.entity_id']) + ->from($mainTableName, [$mainTableName . '.entity_id']) ->joinLeft( - [$gridTableName => $this->getConnection()->getTableName($gridTableName)], + [$gridTableName => $gridTableName], sprintf( '%s.%s = %s.%s', $mainTableName, diff --git a/app/code/Magento/Sales/Model/ResourceModel/Report/Bestsellers/Collection.php b/app/code/Magento/Sales/Model/ResourceModel/Report/Bestsellers/Collection.php index 7f0aaff02d104..fa4fccb1b17e7 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Report/Bestsellers/Collection.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Report/Bestsellers/Collection.php @@ -255,8 +255,8 @@ protected function _beforeLoad() $selectUnions = []; // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $periodFrom = !is_null($this->_from) ? new \DateTime($this->_from) : null; - $periodTo = !is_null($this->_to) ? new \DateTime($this->_to) : null; + $periodFrom = ($this->_from !== null) ? new \DateTime($this->_from) : null; + $periodTo = ($this->_to !== null) ? new \DateTime($this->_to) : null; if ('year' == $this->_period) { if ($periodFrom) { // not the first day of the year diff --git a/app/code/Magento/Sales/Model/Service/CreditmemoService.php b/app/code/Magento/Sales/Model/Service/CreditmemoService.php index 2f08c26de9058..24f56c0dbd595 100644 --- a/app/code/Magento/Sales/Model/Service/CreditmemoService.php +++ b/app/code/Magento/Sales/Model/Service/CreditmemoService.php @@ -195,7 +195,7 @@ public function refund( */ protected function validateForRefund(\Magento\Sales\Api\Data\CreditmemoInterface $creditmemo) { - if ($creditmemo->getId()) { + if ($creditmemo->getId() && $creditmemo->getState() != \Magento\Sales\Model\Order\Creditmemo::STATE_OPEN) { throw new \Magento\Framework\Exception\LocalizedException( __('We cannot register an existing credit memo.') ); diff --git a/app/code/Magento/Sales/Model/Service/OrderService.php b/app/code/Magento/Sales/Model/Service/OrderService.php index d187f7d8e4d24..1eb3fad11278f 100644 --- a/app/code/Magento/Sales/Model/Service/OrderService.php +++ b/app/code/Magento/Sales/Model/Service/OrderService.php @@ -87,7 +87,8 @@ public function __construct( public function cancel($id) { $order = $this->orderRepository->get($id); - if ((bool)$order->cancel()) { + if ($order->canCancel()) { + $order->cancel(); $this->orderRepository->save($order); return true; } diff --git a/app/code/Magento/Sales/Observer/Backend/SubtractQtyFromQuotesObserver.php b/app/code/Magento/Sales/Observer/Backend/SubtractQtyFromQuotesObserver.php index 775a7dab95cfe..cd8c705750d6c 100644 --- a/app/code/Magento/Sales/Observer/Backend/SubtractQtyFromQuotesObserver.php +++ b/app/code/Magento/Sales/Observer/Backend/SubtractQtyFromQuotesObserver.php @@ -31,6 +31,6 @@ public function __construct(\Magento\Quote\Model\ResourceModel\Quote $quote) public function execute(\Magento\Framework\Event\Observer $observer) { $product = $observer->getEvent()->getProduct(); - $this->_quote->substractProductFromQuotes($product); + $this->_quote->subtractProductFromQuotes($product); } } diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 8b104b0b35590..16455d616d853 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -3,18 +3,25 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Setup; use Magento\Eav\Model\Config; +use Magento\Framework\App\State; use Magento\Framework\DB\AggregatedFieldDataConverter; use Magento\Framework\DB\DataConverter\SerializedToJson; use Magento\Framework\DB\FieldToConvert; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\UpgradeDataInterface; +use Magento\Quote\Model\QuoteFactory; +use Magento\Sales\Model\OrderFactory; +use Magento\Sales\Model\ResourceModel\Order\Address\CollectionFactory as AddressCollectionFactory; /** * Data upgrade script + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class UpgradeData implements UpgradeDataInterface { @@ -36,20 +43,50 @@ class UpgradeData implements UpgradeDataInterface private $aggregatedFieldConverter; /** - * Constructor - * + * @var AddressCollectionFactory + */ + private $addressCollectionFactory; + + /** + * @var OrderFactory + */ + private $orderFactory; + + /** + * @var QuoteFactory + */ + private $quoteFactory; + + /** + * @var State + */ + private $state; + + /** * @param SalesSetupFactory $salesSetupFactory * @param Config $eavConfig * @param AggregatedFieldDataConverter $aggregatedFieldConverter + * @param AddressCollectionFactory $addressCollFactory + * @param OrderFactory $orderFactory + * @param QuoteFactory $quoteFactory + * @param State $state */ public function __construct( SalesSetupFactory $salesSetupFactory, Config $eavConfig, - AggregatedFieldDataConverter $aggregatedFieldConverter + AggregatedFieldDataConverter $aggregatedFieldConverter, + AddressCollectionFactory $addressCollFactory, + OrderFactory $orderFactory, + QuoteFactory $quoteFactory, + State $state ) { $this->salesSetupFactory = $salesSetupFactory; $this->eavConfig = $eavConfig; $this->aggregatedFieldConverter = $aggregatedFieldConverter; + $this->addressCollectionFactory = $addressCollFactory; + $this->orderFactory = $orderFactory; + $this->quoteFactory = $quoteFactory; + $this->state = $state; } /** @@ -64,6 +101,21 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface if (version_compare($context->getVersion(), '2.0.6', '<')) { $this->convertSerializedDataToJson($context->getVersion(), $salesSetup); } + if (version_compare($context->getVersion(), '2.0.8', '<')) { + $this->state->emulateAreaCode( + \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + [$this, 'fillQuoteAddressIdInSalesOrderAddress'], + [$setup] + ); + } + if (version_compare($context->getVersion(), '2.0.9', '<')) { + //Correct wrong source model for "invoice" entity type, introduced by mistake in 2.0.1 upgrade. + $salesSetup->updateEntityType( + 'invoice', + 'entity_model', + \Magento\Sales\Model\ResourceModel\Order\Invoice::class + ); + } $this->eavConfig->clear(); } @@ -118,4 +170,34 @@ private function convertSerializedDataToJson($setupVersion, SalesSetup $salesSet } $this->aggregatedFieldConverter->convert($fieldsToUpdate, $salesSetup->getConnection()); } + + /** + * Fill quote_address_id in table sales_order_address if it is empty. + */ + public function fillQuoteAddressIdInSalesOrderAddress() + { + $addressCollection = $this->addressCollectionFactory->create(); + /** @var \Magento\Sales\Model\Order\Address $orderAddress */ + foreach ($addressCollection as $orderAddress) { + if (!$orderAddress->getData('quote_address_id')) { + $orderId = $orderAddress->getParentId(); + $addressType = $orderAddress->getAddressType(); + + /** @var \Magento\Sales\Model\Order $order */ + $order = $this->orderFactory->create()->load($orderId); + $quoteId = $order->getQuoteId(); + $quote = $this->quoteFactory->create()->load($quoteId); + + if ($addressType == \Magento\Sales\Model\Order\Address::TYPE_SHIPPING) { + $quoteAddressId = $quote->getShippingAddress()->getId(); + $orderAddress->setData('quote_address_id', $quoteAddressId); + } elseif ($addressType == \Magento\Sales\Model\Order\Address::TYPE_BILLING) { + $quoteAddressId = $quote->getBillingAddress()->getId(); + $orderAddress->setData('quote_address_id', $quoteAddressId); + } + + $orderAddress->save(); + } + } + } } diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractItemsTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractItemsTest.php index 20f7a7061b6b0..a390c43276085 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractItemsTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractItemsTest.php @@ -84,7 +84,7 @@ public function testGetItemRenderer() */ public function testGetItemRendererThrowsExceptionForNonexistentRenderer() { - $renderer = $this->createMock(\StdClass::class); + $renderer = $this->createMock(\stdClass::class); $layout = $this->createPartialMock( \Magento\Framework\View\Layout::class, ['getChildName', 'getBlock', '__wakeup'] diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractTest.php index 311e5f697675b..a34373f516c42 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractTest.php @@ -62,7 +62,7 @@ public function testGetItemRenderer() */ public function testGetItemRendererThrowsExceptionForNonexistentRenderer() { - $renderer = $this->createMock(\StdClass::class); + $renderer = $this->createMock(\stdClass::class); $layout = $this->createPartialMock( \Magento\Framework\View\Layout::class, ['getChildName', 'getBlock', '__wakeup'] diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Address/FormTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Address/FormTest.php new file mode 100644 index 0000000000000..8a11717c95420 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Address/FormTest.php @@ -0,0 +1,92 @@ +formFactoryMock = $this->createMock(\Magento\Framework\Data\FormFactory::class); + $this->customerFormFactoryMock = $this->createMock(\Magento\Customer\Model\Metadata\FormFactory::class); + $this->coreRegistryMock = $this->createMock(\Magento\Framework\Registry::class); + $this->countriesCollection = $this->createMock( + \Magento\Directory\Model\ResourceModel\Country\Collection::class + ); + + $this->addressBlock = $objectManager->getObject( + \Magento\Sales\Block\Adminhtml\Order\Address\Form::class, + [ + '_formFactory' => $this->formFactoryMock, + '_customerFormFactory' => $this->customerFormFactoryMock, + '_coreRegistry' => $this->coreRegistryMock, + 'countriesCollection' => $this->countriesCollection, + ] + ); + } + + public function testGetForm() + { + $formMock = $this->createMock(\Magento\Framework\Data\Form::class); + $fieldsetMock = $this->createMock(\Magento\Framework\Data\Form\Element\Fieldset::class); + $addressFormMock = $this->createMock(\Magento\Customer\Model\Metadata\Form::class); + $addressMock = $this->createMock(\Magento\Sales\Model\Order\Address::class); + $selectMock = $this->createMock(\Magento\Framework\Data\Form\Element\Select::class); + $orderMock = $this->createMock(\Magento\Sales\Model\Order::class); + + $this->formFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($formMock); + $formMock->expects($this->atLeastOnce())->method('addFieldset')->willReturn($fieldsetMock); + $this->customerFormFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($addressFormMock); + $addressFormMock->expects($this->atLeastOnce())->method('getAttributes')->willReturn([]); + $this->coreRegistryMock->expects($this->atLeastOnce())->method('registry')->willReturn($addressMock); + $formMock->expects($this->atLeastOnce())->method('getElement')->willReturnOnConsecutiveCalls( + $selectMock, + $selectMock, + $selectMock, + $selectMock, + $selectMock, + $selectMock, + $selectMock, + null + ); + $addressMock->expects($this->once())->method('getOrder')->willReturn($orderMock); + $orderMock->expects($this->once())->method('getStoreId')->willReturn(5); + $this->countriesCollection->expects($this->atLeastOnce())->method('loadByStore') + ->willReturn($this->countriesCollection); + + $this->addressBlock->getForm(); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php index 447fd7791ecbd..e010674ca354e 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php @@ -3,8 +3,10 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Create; +use Magento\Catalog\Model\Product; use Magento\Catalog\Pricing\Price\FinalPrice; class AbstractCreateTest extends \PHPUnit\Framework\TestCase @@ -67,4 +69,34 @@ public function testGetItemPrice() ->willReturn($resultPrice); $this->assertEquals($resultPrice, $this->model->getItemPrice($this->productMock)); } + + /** + * @param $item + * + * @dataProvider getProductDataProvider + */ + public function testGetProduct($item) + { + $product = $this->model->getProduct($item); + + self::assertInstanceOf(Product::class, $product); + } + + /** + * DataProvider for testGetProduct. + * + * @return array + */ + public function getProductDataProvider() + { + $productMock = $this->createMock(Product::class); + + $itemMock = $this->createMock(\Magento\Wishlist\Model\Item::class); + $itemMock->expects($this->once())->method('getProduct')->willReturn($productMock); + + return [ + [$productMock], + [$itemMock], + ]; + } } diff --git a/app/code/Magento/Sales/Test/Unit/Block/Order/TotalsTest.php b/app/code/Magento/Sales/Test/Unit/Block/Order/TotalsTest.php new file mode 100644 index 0000000000000..7ad21f26a8bea --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Block/Order/TotalsTest.php @@ -0,0 +1,59 @@ +context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); + $this->block = new Totals($this->context, new Registry); + $this->block->setOrder($this->createMock(Order::class)); + } + + public function testApplySortOrder() + { + $this->block->addTotal(new Total(['code' => 'one']), 'last'); + $this->block->addTotal(new Total(['code' => 'two']), 'last'); + $this->block->addTotal(new Total(['code' => 'three']), 'last'); + $this->block->applySortOrder( + [ + 'one' => 10, + 'two' => 30, + 'three' => 20, + ] + ); + $this->assertEqualsSorted( + [ + 'one' => new Total(['code' => 'one']), + 'three' => new Total(['code' => 'three']), + 'two' => new Total(['code' => 'two']), + ], + $this->block->getTotals() + ); + } + + private function assertEqualsSorted(array $expected, array $actual) + { + $this->assertEquals($expected, $actual, 'Array contents should be equal.'); + $this->assertEquals(array_keys($expected), array_keys($actual), 'Array sort order should be equal.'); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/CustomerData/LastOrderedItemsTest.php b/app/code/Magento/Sales/Test/Unit/CustomerData/LastOrderedItemsTest.php index 0802bafd5ac34..28e1c95026108 100644 --- a/app/code/Magento/Sales/Test/Unit/CustomerData/LastOrderedItemsTest.php +++ b/app/code/Magento/Sales/Test/Unit/CustomerData/LastOrderedItemsTest.php @@ -48,6 +48,11 @@ class LastOrderedItemsTest extends \PHPUnit\Framework\TestCase */ private $orderMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $productRepository; + /** * @var \Magento\Sales\CustomerData\LastOrderedItems */ @@ -74,62 +79,93 @@ protected function setUp() $this->orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class) ->disableOriginalConstructor() ->getMock(); + $this->productRepository = $this->getMockBuilder(\Magento\Catalog\Api\ProductRepositoryInterface::class) + ->getMockForAbstractClass(); $this->section = new \Magento\Sales\CustomerData\LastOrderedItems( $this->orderCollectionFactoryMock, $this->orderConfigMock, $this->customerSessionMock, $this->stockRegistryMock, - $this->storeManagerMock + $this->storeManagerMock, + $this->productRepository ); } public function testGetSectionData() { + $storeId = 1; $websiteId = 4; - $expectedItem = [ + $expectedItem1 = [ 'id' => 1, - 'name' => 'Product Name', + 'name' => 'Product Name 1', 'url' => 'http://example.com', 'is_saleable' => true, ]; - $productId = 10; + $expectedItem2 = [ + 'id' => 2, + 'name' => 'Product Name 2', + 'url' => null, + 'is_saleable' => true, + ]; + $productIdVisible = 1; + $productIdNotVisible = 2; $stockItemMock = $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemInterface::class) ->getMockForAbstractClass(); - $itemWithProductMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class) + $itemWithVisibleProduct = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class) ->disableOriginalConstructor() ->getMock(); - $itemWithoutProductMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class) + $itemWithNotVisibleProduct = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class) ->disableOriginalConstructor() ->getMock(); - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + $productVisible = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->disableOriginalConstructor() ->getMock(); - $items = [$itemWithoutProductMock, $itemWithProductMock]; + $productNotVisible = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $items = [$itemWithVisibleProduct, $itemWithNotVisibleProduct]; $this->getLastOrderMock(); $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMockForAbstractClass(); - $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock); $storeMock->expects($this->any())->method('getWebsiteId')->willReturn($websiteId); + $storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->orderMock->expects($this->once()) ->method('getParentItemsRandomCollection') ->with(\Magento\Sales\CustomerData\LastOrderedItems::SIDEBAR_ORDER_LIMIT) ->willReturn($items); - $itemWithProductMock->expects($this->once())->method('hasData')->with('product')->willReturn(true); - $itemWithProductMock->expects($this->any())->method('getProduct')->willReturn($productMock); - $productMock->expects($this->once())->method('getWebsiteIds')->willReturn([1, 4]); - $itemWithProductMock->expects($this->once())->method('getId')->willReturn($expectedItem['id']); - $itemWithProductMock->expects($this->once())->method('getName')->willReturn($expectedItem['name']); - $productMock->expects($this->once())->method('getProductUrl')->willReturn($expectedItem['url']); - $this->stockRegistryMock->expects($this->once())->method('getStockItem')->willReturn($stockItemMock); - $productMock->expects($this->once())->method('getId')->willReturn($productId); - $itemWithProductMock->expects($this->once())->method('getStore')->willReturn($storeMock); + $productVisible->expects($this->once())->method('isVisibleInSiteVisibility')->willReturn(true); + $productVisible->expects($this->once())->method('getProductUrl')->willReturn($expectedItem1['url']); + $productVisible->expects($this->once())->method('getWebsiteIds')->willReturn([1, 4]); + $productVisible->expects($this->once())->method('getId')->willReturn($productIdVisible); + $productNotVisible->expects($this->once())->method('isVisibleInSiteVisibility')->willReturn(false); + $productNotVisible->expects($this->never())->method('getProductUrl'); + $productNotVisible->expects($this->once())->method('getWebsiteIds')->willReturn([1, 4]); + $productNotVisible->expects($this->once())->method('getId')->willReturn($productIdNotVisible); + $itemWithVisibleProduct->expects($this->once())->method('getProductId')->willReturn($productIdVisible); + $itemWithVisibleProduct->expects($this->once())->method('getProduct')->willReturn($productVisible); + $itemWithVisibleProduct->expects($this->once())->method('getId')->willReturn($expectedItem1['id']); + $itemWithVisibleProduct->expects($this->once())->method('getName')->willReturn($expectedItem1['name']); + $itemWithVisibleProduct->expects($this->once())->method('getStore')->willReturn($storeMock); + $itemWithNotVisibleProduct->expects($this->once())->method('getProductId')->willReturn($productIdNotVisible); + $itemWithNotVisibleProduct->expects($this->once())->method('getProduct')->willReturn($productNotVisible); + $itemWithNotVisibleProduct->expects($this->once())->method('getId')->willReturn($expectedItem2['id']); + $itemWithNotVisibleProduct->expects($this->once())->method('getName')->willReturn($expectedItem2['name']); + $itemWithNotVisibleProduct->expects($this->once())->method('getStore')->willReturn($storeMock); + $this->productRepository->expects($this->any()) + ->method('getById') + ->willReturnMap([ + [$productIdVisible, false, $storeId, false, $productVisible], + [$productIdNotVisible, false, $storeId, false, $productNotVisible], + ]); $this->stockRegistryMock - ->expects($this->once()) + ->expects($this->any()) ->method('getStockItem') - ->with($productId, $websiteId) - ->willReturn($stockItemMock); - $stockItemMock->expects($this->once())->method('getIsInStock')->willReturn($expectedItem['is_saleable']); - $itemWithoutProductMock->expects($this->once())->method('hasData')->with('product')->willReturn(false); - $this->assertEquals(['items' => [$expectedItem]], $this->section->getSectionData()); + ->willReturnMap([ + [$productIdVisible, $websiteId, $stockItemMock], + [$productIdNotVisible, $websiteId, $stockItemMock], + ]); + $stockItemMock->expects($this->exactly(2))->method('getIsInStock')->willReturn($expectedItem1['is_saleable']); + $this->assertEquals(['items' => [$expectedItem1, $expectedItem2]], $this->section->getSectionData()); } private function getLastOrderMock() diff --git a/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php b/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php index a265d39bafd93..fc2341b02e94a 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php @@ -8,8 +8,26 @@ namespace Magento\Sales\Test\Unit\Model\AdminOrder; +use Magento\Backend\Model\Session\Quote as SessionQuote; +use Magento\Customer\Api\Data\AttributeMetadataInterface; +use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Customer\Api\Data\CustomerInterfaceFactory; +use Magento\Customer\Api\Data\GroupInterface; +use Magento\Customer\Api\GroupRepositoryInterface; +use Magento\Customer\Model\Customer\Mapper; +use Magento\Customer\Model\Metadata\Form; +use Magento\Customer\Model\Metadata\FormFactory; +use Magento\Framework\Api\DataObjectHelper; +use Magento\Framework\App\RequestInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\Quote\Address; +use Magento\Quote\Model\Quote\Item; +use Magento\Quote\Model\Quote\Item\Updater; +use Magento\Sales\Model\AdminOrder\Create; use Magento\Sales\Model\AdminOrder\Product; +use Magento\Quote\Model\QuoteFactory; +use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -19,162 +37,97 @@ class CreateTest extends \PHPUnit\Framework\TestCase { const CUSTOMER_ID = 1; - /** @var \Magento\Sales\Model\AdminOrder\Create */ - protected $adminOrderCreate; - - /** @var \Magento\Backend\Model\Session\Quote|\PHPUnit_Framework_MockObject_MockObject */ - protected $sessionQuoteMock; - - /** @var \Magento\Customer\Model\Metadata\FormFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $formFactoryMock; - - /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $customerFactoryMock; - - /** @var \Magento\Quote\Model\Quote\Item\Updater|\PHPUnit_Framework_MockObject_MockObject */ - protected $itemUpdater; - - /** @var \Magento\Customer\Model\Customer\Mapper|\PHPUnit_Framework_MockObject_MockObject */ - protected $customerMapper; - /** - * @var Product\Quote\Initializer|\PHPUnit_Framework_MockObject_MockObject + * @var Create */ - protected $quoteInitializerMock; + private $adminOrderCreate; /** - * @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Quote\Api\CartRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $customerRepositoryMock; + private $quoteRepository; /** - * @var \Magento\Customer\Api\AddressRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Quote\Model\QuoteFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $addressRepositoryMock; + private $quoteFactory; /** - * @var \Magento\Customer\Api\Data\AddressInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject + * @var SessionQuote|MockObject */ - protected $addressFactoryMock; + private $sessionQuote; /** - * @var \Magento\Customer\Api\GroupRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var FormFactory|MockObject */ - protected $groupRepositoryMock; + private $formFactory; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + * @var CustomerInterfaceFactory|MockObject */ - protected $scopeConfigMock; + private $customerFactory; /** - * @var \Magento\Sales\Model\AdminOrder\EmailSender|\PHPUnit_Framework_MockObject_MockObject + * @var Updater|MockObject */ - protected $emailSenderMock; + private $itemUpdater; /** - * @var \Magento\Customer\Api\AccountManagementInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Mapper|MockObject */ - protected $accountManagementMock; + private $customerMapper; /** - * @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject + * @var GroupRepositoryInterface|MockObject */ - protected $dataObjectHelper; + private $groupRepository; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var DataObjectHelper|MockObject */ - protected $objectFactory; + private $dataObjectHelper; - /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ protected function setUp() { - $objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class); - $eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); - $registryMock = $this->createMock(\Magento\Framework\Registry::class); - $configMock = $this->createMock(\Magento\Sales\Model\Config::class); - $this->sessionQuoteMock = $this->createMock(\Magento\Backend\Model\Session\Quote::class); - $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class); - $copyMock = $this->createMock(\Magento\Framework\DataObject\Copy::class); - $messageManagerMock = $this->createMock(\Magento\Framework\Message\ManagerInterface::class); - $this->formFactoryMock = $this->createPartialMock(\Magento\Customer\Model\Metadata\FormFactory::class, ['create']); - $this->customerFactoryMock = $this->createPartialMock(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class, ['create']); - - $this->itemUpdater = $this->createMock(\Magento\Quote\Model\Quote\Item\Updater::class); - - $this->objectFactory = $this->getMockBuilder(\Magento\Framework\DataObject\Factory::class) + $this->formFactory = $this->createPartialMock(FormFactory::class, ['create']); + $this->quoteFactory = $this->createPartialMock(QuoteFactory::class, ['create']); + $this->customerFactory = $this->createPartialMock(CustomerInterfaceFactory::class, ['create']); + + $this->itemUpdater = $this->createMock(Updater::class); + + $this->quoteRepository = $this->getMockBuilder(\Magento\Quote\Api\CartRepositoryInterface::class) + ->disableOriginalConstructor() + ->setMethods(['getForCustomer']) + ->getMockForAbstractClass(); + + $this->sessionQuote = $this->getMockBuilder(\Magento\Backend\Model\Session\Quote::class) ->disableOriginalConstructor() - ->setMethods(['create']) + ->setMethods(['getQuote', 'getStoreId', 'getCustomerId']) ->getMock(); - $this->customerMapper = $this->getMockBuilder( - \Magento\Customer\Model\Customer\Mapper::class - )->setMethods(['toFlatArray'])->disableOriginalConstructor()->getMock(); + $this->customerMapper = $this->getMockBuilder(Mapper::class) + ->setMethods(['toFlatArray']) + ->disableOriginalConstructor() + ->getMock(); - $this->quoteInitializerMock = $this->createMock(\Magento\Sales\Model\AdminOrder\Product\Quote\Initializer::class); - $this->customerRepositoryMock = $this->getMockForAbstractClass( - \Magento\Customer\Api\CustomerRepositoryInterface::class, - [], - '', - false - ); - $this->addressRepositoryMock = $this->getMockForAbstractClass( - \Magento\Customer\Api\AddressRepositoryInterface::class, - [], - '', - false - ); - $this->addressFactoryMock = $this->createMock(\Magento\Customer\Api\Data\AddressInterfaceFactory::class); - $this->groupRepositoryMock = $this->getMockForAbstractClass( - \Magento\Customer\Api\GroupRepositoryInterface::class, - [], - '', - false - ); - $this->scopeConfigMock = $this->getMockForAbstractClass( - \Magento\Framework\App\Config\ScopeConfigInterface::class, - [], - '', - false - ); - $this->emailSenderMock = $this->createMock(\Magento\Sales\Model\AdminOrder\EmailSender::class); - $this->accountManagementMock = $this->getMockForAbstractClass( - \Magento\Customer\Api\AccountManagementInterface::class, - [], - '', - false - ); - $this->dataObjectHelper = $this->getMockBuilder(\Magento\Framework\Api\DataObjectHelper::class) + $this->groupRepository = $this->getMockForAbstractClass(GroupRepositoryInterface::class); + $this->dataObjectHelper = $this->getMockBuilder(DataObjectHelper::class) ->disableOriginalConstructor() ->getMock(); $objectManagerHelper = new ObjectManagerHelper($this); $this->adminOrderCreate = $objectManagerHelper->getObject( - \Magento\Sales\Model\AdminOrder\Create::class, + Create::class, [ - 'objectManager' => $objectManagerMock, - 'eventManager' => $eventManagerMock, - 'coreRegistry' => $registryMock, - 'salesConfig' => $configMock, - 'quoteSession' => $this->sessionQuoteMock, - 'logger' => $loggerMock, - 'objectCopyService' => $copyMock, - 'messageManager' => $messageManagerMock, - 'quoteInitializer' => $this->quoteInitializerMock, - 'customerRepository' => $this->customerRepositoryMock, - 'addressRepository' => $this->addressRepositoryMock, - 'addressFactory' => $this->addressFactoryMock, - 'metadataFormFactory' => $this->formFactoryMock, - 'customerFactory' => $this->customerFactoryMock, - 'groupRepository' => $this->groupRepositoryMock, + 'quoteSession' => $this->sessionQuote, + 'metadataFormFactory' => $this->formFactory, + 'customerFactory' => $this->customerFactory, + 'groupRepository' => $this->groupRepository, 'quoteItemUpdater' => $this->itemUpdater, 'customerMapper' => $this->customerMapper, - 'objectFactory' => $this->objectFactory, - 'accountManagement' => $this->accountManagementMock, 'dataObjectHelper' => $this->dataObjectHelper, + 'quoteRepository' => $this->quoteRepository, + 'quoteFactory' => $this->quoteFactory, ] ); } @@ -188,64 +141,60 @@ public function testSetAccountData() ]; $attributeMocks = []; - foreach ($attributes as $attribute) { - $attributeMock = $this->createMock(\Magento\Customer\Api\Data\AttributeMetadataInterface::class); + foreach ($attributes as $value) { + $attribute = $this->createMock(AttributeMetadataInterface::class); + $attribute->method('getAttributeCode') + ->willReturn($value[0]); - $attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attribute[0])); - - $attributeMocks[] = $attributeMock; + $attributeMocks[] = $attribute; } - $customerGroupMock = $this->getMockForAbstractClass( - \Magento\Customer\Api\Data\GroupInterface::class, - [], - '', - false, - true, - true, - ['getTaxClassId'] - ); - $customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId)); - $customerFormMock = $this->createMock(\Magento\Customer\Model\Metadata\Form::class); - $customerFormMock->expects($this->any()) - ->method('getAttributes') - ->will($this->returnValue([$attributeMocks[1]])); - $customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue([])); - $customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue(['group_id' => 1])); - - $customerFormMock->expects($this->any()) - ->method('prepareRequest') - ->will($this->returnValue($this->createMock(\Magento\Framework\App\RequestInterface::class))); - - $customerMock = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class); - $this->customerMapper->expects($this->atLeastOnce()) + $customerGroup = $this->getMockForAbstractClass(GroupInterface::class); + $customerGroup->method('getTaxClassId') + ->willReturn($taxClassId); + $customerForm = $this->createMock(Form::class); + $customerForm->method('getAttributes') + ->willReturn([$attributeMocks[1]]); + $customerForm + ->method('extractData') + ->willReturn([]); + $customerForm + ->method('restoreData') + ->willReturn(['group_id' => 1]); + + $customerForm->method('prepareRequest') + ->willReturn($this->createMock(RequestInterface::class)); + + $customer = $this->createMock(CustomerInterface::class); + $this->customerMapper->expects(self::atLeastOnce()) ->method('toFlatArray') ->willReturn(['group_id' => 1]); - $quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class); - $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock)); - $quoteMock->expects($this->once()) - ->method('addData') + $quote = $this->createMock(Quote::class); + $quote->method('getCustomer')->willReturn($customer); + $quote->method('addData') ->with( [ 'customer_group_id' => $attributes[1][1], 'customer_tax_class_id' => $taxClassId ] ); - $this->dataObjectHelper->expects($this->once()) - ->method('populateWithArray') + $this->dataObjectHelper->method('populateWithArray') ->with( - $customerMock, - ['group_id' => 1], \Magento\Customer\Api\Data\CustomerInterface::class + $customer, + ['group_id' => 1], CustomerInterface::class ); - $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock)); - $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); - $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerMock)); + $this->formFactory->method('create') + ->willReturn($customerForm); + $this->sessionQuote + ->method('getQuote') + ->willReturn($quote); + $this->customerFactory->method('create') + ->willReturn($customer); - $this->groupRepositoryMock->expects($this->once()) - ->method('getById') - ->will($this->returnValue($customerGroupMock)); + $this->groupRepository->method('getById') + ->willReturn($customerGroup); $this->adminOrderCreate->setAccountData(['group_id' => 1]); } @@ -253,7 +202,7 @@ public function testSetAccountData() public function testUpdateQuoteItemsNotArray() { $object = $this->adminOrderCreate->updateQuoteItems('string'); - $this->assertEquals($this->adminOrderCreate, $object); + self::assertEquals($this->adminOrderCreate, $object); } public function testUpdateQuoteItemsEmptyConfiguredOption() @@ -266,22 +215,21 @@ public function testUpdateQuoteItemsEmptyConfiguredOption() ] ]; - $itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class); + $item = $this->createMock(Item::class); - $quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class); - $quoteMock->expects($this->once()) - ->method('getItemById') - ->will($this->returnValue($itemMock)); + $quote = $this->createMock(Quote::class); + $quote->method('getItemById') + ->willReturn($item); - $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); - $this->itemUpdater->expects($this->once()) - ->method('update') - ->with($this->equalTo($itemMock), $this->equalTo($items[1])) - ->will($this->returnSelf()); + $this->sessionQuote->method('getQuote') + ->willReturn($quote); + $this->itemUpdater->method('update') + ->with(self::equalTo($item), self::equalTo($items[1])) + ->willReturnSelf(); $this->adminOrderCreate->setRecollect(false); $object = $this->adminOrderCreate->updateQuoteItems($items); - $this->assertEquals($this->adminOrderCreate, $object); + self::assertEquals($this->adminOrderCreate, $object); } public function testUpdateQuoteItemsWithConfiguredOption() @@ -295,43 +243,77 @@ public function testUpdateQuoteItemsWithConfiguredOption() ] ]; - $itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class); - $itemMock->expects($this->once()) - ->method('getQty') - ->will($this->returnValue($qty)); + $item = $this->createMock(Item::class); + $item->method('getQty') + ->willReturn($qty); - $quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class); - $quoteMock->expects($this->once()) - ->method('updateItem') - ->will($this->returnValue($itemMock)); + $quote = $this->createMock(Quote::class); + $quote->method('updateItem') + ->willReturn($item); - $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); + $this->sessionQuote + ->method('getQuote') + ->willReturn($quote); $expectedInfo = $items[1]; $expectedInfo['qty'] = $qty; - $this->itemUpdater->expects($this->once()) - ->method('update') - ->with($this->equalTo($itemMock), $this->equalTo($expectedInfo)); + $this->itemUpdater->method('update') + ->with(self::equalTo($item), self::equalTo($expectedInfo)); $this->adminOrderCreate->setRecollect(false); $object = $this->adminOrderCreate->updateQuoteItems($items); - $this->assertEquals($this->adminOrderCreate, $object); + self::assertEquals($this->adminOrderCreate, $object); } public function testApplyCoupon() { - $couponCode = ''; - $quoteMock = $this->createPartialMock(\Magento\Quote\Model\Quote::class, ['getShippingAddress', 'setCouponCode']); - $this->sessionQuoteMock->expects($this->once())->method('getQuote')->willReturn($quoteMock); + $couponCode = '123'; + $quote = $this->createPartialMock(Quote::class, ['getShippingAddress', 'setCouponCode']); + $this->sessionQuote->method('getQuote') + ->willReturn($quote); + + $address = $this->createPartialMock(Address::class, ['setCollectShippingRates', 'setFreeShipping']); + $quote->method('getShippingAddress') + ->willReturn($address); + $quote->method('setCouponCode') + ->with($couponCode) + ->willReturnSelf(); + + $address->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + $address->method('setFreeShipping') + ->with(0) + ->willReturnSelf(); + + $object = $this->adminOrderCreate->applyCoupon($couponCode); + self::assertEquals($this->adminOrderCreate, $object); + } + + public function testGetCustomerCart() + { + $storeId = 2; + $customerId = 2; + $cartResult = [ + 'cart' => true + ]; - $addressMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Address::class, ['setCollectShippingRates', 'setFreeShipping']); - $quoteMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($addressMock); - $quoteMock->expects($this->once())->method('setCouponCode')->with($couponCode)->willReturnSelf(); + $this->quoteFactory->expects($this->once()) + ->method('create'); - $addressMock->expects($this->once())->method('setCollectShippingRates')->with(true)->willReturnSelf(); - $addressMock->expects($this->once())->method('setFreeShipping')->with(0)->willReturnSelf(); + $this->sessionQuote->expects($this->once()) + ->method('getStoreId') + ->willReturn($storeId); - $object = $this->adminOrderCreate->applyCoupon($couponCode); - $this->assertEquals($this->adminOrderCreate, $object); + $this->sessionQuote->expects($this->once()) + ->method('getCustomerId') + ->willReturn($customerId); + + $this->quoteRepository->expects($this->once()) + ->method('getForCustomer') + ->with($customerId, [$storeId]) + ->willReturn($cartResult); + + $this->assertEquals($cartResult, $this->adminOrderCreate->getCustomerCart()); } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index f3a35e485c166..86419c0c905b6 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -23,18 +23,41 @@ class ConfigTest extends \PHPUnit\Framework\TestCase */ protected $orderStatusCollectionFactoryMock; + /** + * @var \Magento\Sales\Model\Order\StatusFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $statusFactoryMock; + + /** + * @var \Magento\Sales\Model\Order\Status + */ + protected $orderStatusModel; + + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $storeManagerMock; + protected function setUp() { - $orderStatusFactory = $this->createMock(\Magento\Sales\Model\Order\StatusFactory::class); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->orderStatusModel = $objectManager->getObject(\Magento\Sales\Model\Order\Status::class, [ + 'storeManager' => $this->storeManagerMock, + ]); + $this->statusFactoryMock = $this->getMockBuilder(\Magento\Sales\Model\Order\StatusFactory::class) + ->setMethods(['load', 'create']) + ->getMock(); $this->orderStatusCollectionFactoryMock = $this->createPartialMock( \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class, ['create'] ); - $this->salesConfig = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)) + $this->salesConfig = $objectManager ->getObject( \Magento\Sales\Model\Order\Config::class, [ - 'orderStatusFactory' => $orderStatusFactory, + 'orderStatusFactory' => $this->statusFactoryMock, 'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock ] ); @@ -147,6 +170,22 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR ->method('joinStates') ->will($this->returnValue($collectionData)); + $this->statusFactoryMock->method('create') + ->willReturnSelf(); + + $this->statusFactoryMock->method('load') + ->willReturn($this->orderStatusModel); + + $storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class); + $storeMock->method('getId') + ->willReturn(1); + + $this->storeManagerMock->method('getStore') + ->with($this->anything()) + ->willReturn($storeMock); + + $this->orderStatusModel->setData('store_labels', [1 => 'Pending label']); + $result = $this->salesConfig->getStateStatuses($state, $joinLabels); $this->assertSame($expectedResult, $result); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/CommentRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/CommentRepositoryTest.php new file mode 100644 index 0000000000000..115cb4bc7c91c --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/CommentRepositoryTest.php @@ -0,0 +1,187 @@ +commentResource = $this->getMockBuilder(CreditmemoCommentResourceInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->commentFactory = $this->getMockBuilder(CreditmemoCommentInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->searchResultFactory = $this->getMockBuilder(CreditmemoCommentSearchResultInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->collectionProcessor = $this->getMockBuilder(CollectionProcessorInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->creditmemoRepositoryMock = $this->getMockBuilder(CreditmemoRepositoryInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->creditmemoCommentSender = $this->getMockBuilder(CreditmemoCommentSender::class) + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock(); + + $this->creditmemoMock = $this->getMockBuilder(Creditmemo::class)->disableOriginalConstructor()->getMock(); + $this->commentMock = $this->getMockBuilder(Comment::class)->disableOriginalConstructor()->getMock(); + + $this->commentRepository = new CommentRepository( + $this->commentResource, + $this->commentFactory, + $this->searchResultFactory, + $this->collectionProcessor, + $this->creditmemoCommentSender, + $this->creditmemoRepositoryMock, + $this->loggerMock + ); + } + + public function testSave() + { + $comment = "Comment text"; + $creditmemoId = 123; + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willReturnSelf(); + $this->commentMock->expects($this->once()) + ->method('getIsCustomerNotified') + ->willReturn(1); + $this->commentMock->expects($this->once()) + ->method('getParentId') + ->willReturn($creditmemoId); + $this->commentMock->expects($this->once()) + ->method('getComment') + ->willReturn($comment); + + $this->creditmemoRepositoryMock->expects($this->once()) + ->method('get') + ->with($creditmemoId) + ->willReturn($this->creditmemoMock); + $this->creditmemoCommentSender->expects($this->once()) + ->method('send') + ->with($this->creditmemoMock, true, $comment) + ->willReturn(true); + $this->commentRepository->save($this->commentMock); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + * @expectedExceptionMessage Could not save the creditmemo comment. + */ + public function testSaveWithException() + { + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willThrowException( + new \Magento\Framework\Exception\CouldNotSaveException(__('Could not save the creditmemo comment.')) + ); + + $this->commentRepository->save($this->commentMock); + } + + public function testSaveSendCatchException() + { + $comment = "Comment text"; + $creditmemoId = 123; + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willReturnSelf(); + $this->commentMock->expects($this->once()) + ->method('getIsCustomerNotified') + ->willReturn(1); + $this->commentMock->expects($this->once()) + ->method('getParentId') + ->willReturn($creditmemoId); + $this->commentMock->expects($this->once()) + ->method('getComment') + ->willReturn($comment); + + $this->creditmemoRepositoryMock->expects($this->once()) + ->method('get') + ->with($creditmemoId) + ->willReturn($this->creditmemoMock); + $this->creditmemoCommentSender->expects($this->once()) + ->method('send') + ->willThrowException(new \Exception()); + $this->loggerMock->expects($this->once()) + ->method('warning'); + + $this->commentRepository->save($this->commentMock); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Sender/EmailSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Sender/EmailSenderTest.php index fa155cfd1d4ed..9fd2a8b0d929f 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Sender/EmailSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Sender/EmailSenderTest.php @@ -262,6 +262,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending 'formattedShippingAddress' => 'Formatted address', 'formattedBillingAddress' => 'Formatted address', ]; + $transport = new \Magento\Framework\DataObject($transport); $this->eventManagerMock->expects($this->once()) ->method('dispatch') @@ -269,13 +270,14 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending 'email_creditmemo_set_template_vars_before', [ 'sender' => $this->subject, - 'transport' => $transport, + 'transport' => $transport->getData(), + 'transportObject' => $transport ] ); $this->templateContainerMock->expects($this->once()) ->method('setTemplateVars') - ->with($transport); + ->with($transport->getData()); $this->identityContainerMock->expects($this->once()) ->method('isEnabled') diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php index 8a2305543c490..2794860793ed6 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php @@ -6,6 +6,7 @@ namespace Magento\Sales\Test\Unit\Model\Order; use Magento\Quote\Model\Quote\Address; +use Magento\Sales\Api\Data\OrderAddressInterface; /** * Class BuilderTest @@ -49,6 +50,11 @@ class CustomerManagementTest extends \PHPUnit\Framework\TestCase */ protected $service; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $quoteAddressFactory; + protected function setUp() { $this->objectCopyService = $this->createMock(\Magento\Framework\DataObject\Copy::class); @@ -66,6 +72,7 @@ protected function setUp() ['create'] ); $this->orderRepository = $this->createMock(\Magento\Sales\Api\OrderRepositoryInterface::class); + $this->quoteAddressFactory = $this->createMock(\Magento\Quote\Model\Quote\AddressFactory::class); $this->service = new \Magento\Sales\Model\Order\CustomerManagement( $this->objectCopyService, @@ -73,7 +80,8 @@ protected function setUp() $this->customerFactory, $this->addressFactory, $this->regionFactory, - $this->orderRepository + $this->orderRepository, + $this->quoteAddressFactory ); } @@ -94,12 +102,12 @@ public function testCreateCreatesCustomerBasedonGuestOrder() $orderMock->expects($this->once())->method('getCustomerId')->will($this->returnValue(null)); $orderMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue('billing_address')); - $orderBillingAddress = $this->createMock(\Magento\Sales\Api\Data\OrderAddressInterface::class); + $orderBillingAddress = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['getData']); $orderBillingAddress->expects($this->once()) ->method('getAddressType') ->willReturn(Address::ADDRESS_TYPE_BILLING); - $orderShippingAddress = $this->createMock(\Magento\Sales\Api\Data\OrderAddressInterface::class); + $orderShippingAddress = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['getData']); $orderShippingAddress->expects($this->once()) ->method('getAddressType') ->willReturn(Address::ADDRESS_TYPE_SHIPPING); @@ -108,6 +116,17 @@ public function testCreateCreatesCustomerBasedonGuestOrder() ->method('getAddresses') ->will($this->returnValue([$orderBillingAddress, $orderShippingAddress])); + $billingQuoteAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class); + $billingQuoteAddress->expects($this->once())->method('load')->willReturn($billingQuoteAddress); + $billingQuoteAddress->expects($this->once())->method('getId')->willReturn(4); + $billingQuoteAddress->expects($this->once())->method('getData')->with('save_in_address_book')->willReturn(1); + + $shippingQuoteAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class); + $shippingQuoteAddress->expects($this->once())->method('load')->willReturn($shippingQuoteAddress); + $shippingQuoteAddress->expects($this->once())->method('getId')->willReturn(5); + $shippingQuoteAddress->expects($this->once())->method('getData')->with('save_in_address_book')->willReturn(1); + $this->quoteAddressFactory->expects($this->exactly(2))->method('create') + ->willReturnOnConsecutiveCalls($billingQuoteAddress, $shippingQuoteAddress); $this->orderRepository->expects($this->once())->method('get')->with(1)->will($this->returnValue($orderMock)); $this->objectCopyService->expects($this->any())->method('copyFieldsetToTarget')->will($this->returnValueMap( [ @@ -142,4 +161,25 @@ public function testCreateCreatesCustomerBasedonGuestOrder() $this->orderRepository->expects($this->once())->method('save')->with($orderMock); $this->assertEquals($customerMock, $this->service->create(1)); } + + /** + * Get mock for abstract class with methods. + * + * @param string $className + * @param array $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function createPartialMockForAbstractClass($className, $methods = []) + { + return $this->getMockForAbstractClass( + $className, + [], + '', + true, + true, + true, + $methods + ); + } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php index 411dd9e1433d7..46c44c03b1514 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php @@ -53,10 +53,11 @@ protected function setUp() * @param int $configValue * @param bool|null $forceSyncMode * @param bool|null $emailSendingResult - * @dataProvider sendDataProvider + * @param $senderSendException * @return void + * @dataProvider sendDataProvider */ - public function testSend($configValue, $forceSyncMode, $emailSendingResult) + public function testSend($configValue, $forceSyncMode, $emailSendingResult, $senderSendException) { $address = 'address_test'; $configPath = 'sales_email/general/async_sending'; @@ -110,19 +111,23 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult) $this->senderMock->expects($this->once())->method('send'); - $this->senderMock->expects($this->once())->method('sendCopyTo'); + if ($senderSendException) { + $this->checkSenderSendExceptionCase(); + } else { + $this->senderMock->expects($this->once())->method('sendCopyTo'); - $this->orderMock->expects($this->once()) - ->method('setEmailSent') - ->with(true); + $this->orderMock->expects($this->once()) + ->method('setEmailSent') + ->with(true); - $this->orderResourceMock->expects($this->once()) - ->method('saveAttribute') - ->with($this->orderMock, ['send_email', 'email_sent']); + $this->orderResourceMock->expects($this->once()) + ->method('saveAttribute') + ->with($this->orderMock, ['send_email', 'email_sent']); - $this->assertTrue( - $this->sender->send($this->orderMock) - ); + $this->assertTrue( + $this->sender->send($this->orderMock) + ); + } } else { $this->orderResourceMock->expects($this->once()) ->method('saveAttribute') @@ -146,19 +151,42 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult) } } + /** + * Methods check case when method "send" in "senderMock" throw exception. + * + * @return void + */ + protected function checkSenderSendExceptionCase() + { + $this->senderMock->expects($this->once()) + ->method('send') + ->willThrowException(new \Exception('exception')); + + $this->orderResourceMock->expects($this->once()) + ->method('saveAttribute') + ->with($this->orderMock, 'send_email'); + + $this->assertFalse( + $this->sender->send($this->orderMock) + ); + } + /** * @return array */ public function sendDataProvider() { return [ - [0, 0, true], - [0, 0, true], - [0, 0, false], - [0, 0, false], - [0, 1, true], - [0, 1, true], - [1, null, null, null] + [0, 0, true, false], + [0, 0, true, false], + [0, 0, true, true], + [0, 0, false, false], + [0, 0, false, false], + [0, 0, false, true], + [0, 1, true, false], + [0, 1, true, false], + [0, 1, true, false], + [1, null, null, false] ]; } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php index 5319aa510bedf..38209bb22aef4 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php @@ -3,8 +3,10 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Test\Unit\Model\Order\Email; +use Magento\Framework\Mail\Template\TransportBuilderByStore; use Magento\Sales\Model\Order\Email\SenderBuilder; class SenderBuilderTest extends \PHPUnit\Framework\TestCase @@ -29,6 +31,16 @@ class SenderBuilderTest extends \PHPUnit\Framework\TestCase */ protected $transportBuilder; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $storeMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $transportBuilderByStore; + protected function setUp() { $templateId = 'test_template_id'; @@ -42,7 +54,11 @@ protected function setUp() ['getTemplateVars', 'getTemplateOptions', 'getTemplateId'] ); - $this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getStoreId', '__wakeup']); + $this->storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, [ + 'getStoreId', + '__wakeup', + 'getId', + ]); $this->identityContainerMock = $this->createPartialMock( \Magento\Sales\Model\Order\Email\Container\ShipmentIdentity::class, @@ -52,15 +68,24 @@ protected function setUp() 'getCustomerName', 'getTemplateOptions', 'getEmailCopyTo', - 'getCopyMethod' + 'getCopyMethod', + 'getStore', ] ); - $this->transportBuilder = $this->createPartialMock(\Magento\Framework\Mail\Template\TransportBuilder::class, [ - 'addTo', 'addBcc', 'getTransport', - 'setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars', - 'setFrom', - ]); + $this->transportBuilder = $this->createPartialMock( + \Magento\Framework\Mail\Template\TransportBuilder::class, + [ + 'addTo', + 'addBcc', + 'getTransport', + 'setTemplateIdentifier', + 'setTemplateOptions', + 'setTemplateVars', + ] + ); + + $this->transportBuilderByStore = $this->createMock(TransportBuilderByStore::class); $this->templateContainerMock->expects($this->once()) ->method('getTemplateId') @@ -84,8 +109,8 @@ protected function setUp() $this->identityContainerMock->expects($this->once()) ->method('getEmailIdentity') ->will($this->returnValue($emailIdentity)); - $this->transportBuilder->expects($this->once()) - ->method('setFrom') + $this->transportBuilderByStore->expects($this->once()) + ->method('setFromByStore') ->with($this->equalTo($emailIdentity)); $this->identityContainerMock->expects($this->once()) @@ -95,7 +120,8 @@ protected function setUp() $this->senderBuilder = new SenderBuilder( $this->templateContainerMock, $this->identityContainerMock, - $this->transportBuilder + $this->transportBuilder, + $this->transportBuilderByStore ); } @@ -119,6 +145,12 @@ public function testSend() $this->identityContainerMock->expects($this->once()) ->method('getCustomerName') ->will($this->returnValue($customerName)); + $this->identityContainerMock->expects($this->once()) + ->method('getStore') + ->willReturn($this->storeMock); + $this->storeMock->expects($this->once()) + ->method('getId') + ->willReturn(1); $this->transportBuilder->expects($this->once()) ->method('addTo') ->with($this->equalTo($customerEmail), $this->equalTo($customerName)); @@ -145,7 +177,12 @@ public function testSendCopyTo() $this->transportBuilder->expects($this->once()) ->method('addTo') ->with($this->equalTo('example@mail.com')); - + $this->identityContainerMock->expects($this->once()) + ->method('getStore') + ->willReturn($this->storeMock); + $this->storeMock->expects($this->once()) + ->method('getId') + ->willReturn(1); $this->transportBuilder->expects($this->once()) ->method('getTransport') ->will($this->returnValue($transportMock)); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/CommentRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/CommentRepositoryTest.php new file mode 100644 index 0000000000000..4790490c1ecf3 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/CommentRepositoryTest.php @@ -0,0 +1,187 @@ +commentResource = $this->getMockBuilder(InvoiceCommentResourceInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->commentFactory = $this->getMockBuilder(InvoiceCommentInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->searchResultFactory = $this->getMockBuilder(InvoiceCommentSearchResultInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->collectionProcessor = $this->getMockBuilder(CollectionProcessorInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->invoiceRepositoryMock = $this->getMockBuilder(InvoiceRepositoryInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->invoiceCommentSender = $this->getMockBuilder(InvoiceCommentSender::class) + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock(); + + $this->invoiceMock = $this->getMockBuilder(Invoice::class)->disableOriginalConstructor()->getMock(); + $this->commentMock = $this->getMockBuilder(Comment::class)->disableOriginalConstructor()->getMock(); + + $this->commentRepository = new CommentRepository( + $this->commentResource, + $this->commentFactory, + $this->searchResultFactory, + $this->collectionProcessor, + $this->invoiceCommentSender, + $this->invoiceRepositoryMock, + $this->loggerMock + ); + } + + public function testSave() + { + $comment = "Comment text"; + $invoiceId = 123; + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willReturnSelf(); + $this->commentMock->expects($this->once()) + ->method('getIsCustomerNotified') + ->willReturn(1); + $this->commentMock->expects($this->once()) + ->method('getParentId') + ->willReturn($invoiceId); + $this->commentMock->expects($this->once()) + ->method('getComment') + ->willReturn($comment); + + $this->invoiceRepositoryMock->expects($this->once()) + ->method('get') + ->with($invoiceId) + ->willReturn($this->invoiceMock); + $this->invoiceCommentSender->expects($this->once()) + ->method('send') + ->with($this->invoiceMock, true, $comment) + ->willReturn(true); + $this->commentRepository->save($this->commentMock); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + * @expectedExceptionMessage Could not save the invoice comment. + */ + public function testSaveWithException() + { + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willThrowException( + new \Magento\Framework\Exception\CouldNotSaveException(__('Could not save the invoice comment.')) + ); + + $this->commentRepository->save($this->commentMock); + } + + public function testSaveSendCatchException() + { + $comment = "Comment text"; + $creditmemoId = 123; + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willReturnSelf(); + $this->commentMock->expects($this->once()) + ->method('getIsCustomerNotified') + ->willReturn(1); + $this->commentMock->expects($this->once()) + ->method('getParentId') + ->willReturn($creditmemoId); + $this->commentMock->expects($this->once()) + ->method('getComment') + ->willReturn($comment); + + $this->invoiceRepositoryMock->expects($this->once()) + ->method('get') + ->with($creditmemoId) + ->willReturn($this->invoiceMock); + $this->invoiceCommentSender->expects($this->once()) + ->method('send') + ->willThrowException(new \Exception()); + $this->loggerMock->expects($this->once()) + ->method('warning'); + + $this->commentRepository->save($this->commentMock); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Sender/EmailSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Sender/EmailSenderTest.php index f470b097dd73f..8a4e2920ba207 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Sender/EmailSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Sender/EmailSenderTest.php @@ -260,6 +260,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending 'formattedShippingAddress' => 'Formatted address', 'formattedBillingAddress' => 'Formatted address', ]; + $transport = new \Magento\Framework\DataObject($transport); $this->eventManagerMock->expects($this->once()) ->method('dispatch') @@ -267,13 +268,14 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending 'email_invoice_set_template_vars_before', [ 'sender' => $this->subject, - 'transport' => $transport, + 'transport' => $transport->getData(), + 'transportObject' => $transport, ] ); $this->templateContainerMock->expects($this->once()) ->method('setTemplateVars') - ->with($transport); + ->with($transport->getData()); $this->identityContainerMock->expects($this->once()) ->method('isEnabled') diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceTest.php index 0962e32dfb6ed..0517da8b85cf0 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceTest.php @@ -8,6 +8,7 @@ namespace Magento\Sales\Test\Unit\Model\Order; +use Magento\Sales\Api\Data\InvoiceInterface; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\ResourceModel\OrderFactory; use Magento\Sales\Model\Order; @@ -72,7 +73,7 @@ protected function setUp() ->setMethods( [ 'getPayment', '__wakeup', 'load', 'setHistoryEntityName', 'getStore', 'getBillingAddress', - 'getShippingAddress' + 'getShippingAddress', 'getConfig', ] ) ->getMock(); @@ -83,7 +84,7 @@ protected function setUp() $this->paymentMock = $this->getMockBuilder( \Magento\Sales\Model\Order\Payment::class )->disableOriginalConstructor()->setMethods( - ['canVoid', '__wakeup', 'canCapture', 'capture', 'pay'] + ['canVoid', '__wakeup', 'canCapture', 'capture', 'pay', 'cancelInvoice'] )->getMock(); $this->orderFactory = $this->createPartialMock(\Magento\Sales\Model\OrderFactory::class, ['create']); @@ -407,4 +408,58 @@ private function getOrderInvoiceCollection() return $collection; } + + /** + * Assert open invoice can be canceled, and its status changes + */ + public function testCancelOpenInvoice() + { + $orderConfigMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Config::class) + ->disableOriginalConstructor()->setMethods( + ['getStateDefaultStatus'] + )->getMock(); + $orderConfigMock->expects($this->once())->method('getStateDefaultStatus') + ->with(Order::STATE_PROCESSING) + ->willReturn(Order::STATE_PROCESSING); + $this->order->expects($this->once())->method('getPayment')->willReturn($this->paymentMock); + $this->order->expects($this->once())->method('getConfig')->willReturn($orderConfigMock); + $this->paymentMock->expects($this->once())->method('cancelInvoice')->willReturn($this->paymentMock); + $this->eventManagerMock->expects($this->once()) + ->method('dispatch') + ->with('sales_order_invoice_cancel'); + $this->model->setData(InvoiceInterface::ITEMS, []); + $this->model->setState(Invoice::STATE_OPEN); + $this->model->cancel(); + self::assertEquals(Invoice::STATE_CANCELED, $this->model->getState()); + } + + /** + * Assert open invoice can be canceled, and its status changes + * + * @param $initialInvoiceStatus + * @param $finalInvoiceStatus + * @dataProvider getNotOpenedInvoiceStatuses + */ + public function testCannotCancelNotOpenedInvoice($initialInvoiceStatus, $finalInvoiceStatus) + { + $this->order->expects($this->never())->method('getPayment'); + $this->paymentMock->expects($this->never())->method('cancelInvoice'); + $this->eventManagerMock->expects($this->never()) + ->method('dispatch') + ->with('sales_order_invoice_cancel'); + $this->model->setState($initialInvoiceStatus); + $this->model->cancel(); + self::assertEquals($finalInvoiceStatus, $this->model->getState()); + } + + /** + * @return array + */ + public function getNotOpenedInvoiceStatuses() + { + return [ + [Invoice::STATE_PAID, Invoice::STATE_PAID], + [Invoice::STATE_CANCELED, Invoice::STATE_CANCELED], + ]; + } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/InfoTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/InfoTest.php index 70e5ad127e44c..293c2eea1231d 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/InfoTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Payment/InfoTest.php @@ -179,7 +179,7 @@ public function testDecrypt() */ public function testSetAdditionalInformationException() { - $this->info->setAdditionalInformation('object', new \StdClass()); + $this->info->setAdditionalInformation('object', new \stdClass()); } /** diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php index c91d4edb155a4..0761b5abb5d45 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php @@ -19,7 +19,7 @@ public function testInsertTotals() // Setup parameters, that will be passed to the tested model method $page = $this->createMock(\Zend_Pdf_Page::class); - $order = new \StdClass(); + $order = new \stdClass(); $source = $this->createMock(\Magento\Sales\Model\Order\Invoice::class); $source->expects($this->any())->method('getOrder')->will($this->returnValue($order)); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/Config/ReaderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/Config/ReaderTest.php index b1b51c3f12330..b808a4139e84e 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/Config/ReaderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/Config/ReaderTest.php @@ -87,7 +87,7 @@ protected function setUp() public function testRead() { $expectedResult = new \stdClass(); - $constraint = function (\DOMDOcument $actual) { + $constraint = function (\DOMDocument $actual) { try { $expected = __DIR__ . '/_files/pdf_merged.xml'; \PHPUnit\Framework\Assert::assertXmlStringEqualsXmlFile($expected, $actual->saveXML()); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/CommentRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/CommentRepositoryTest.php new file mode 100644 index 0000000000000..9cab366ef2c33 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/CommentRepositoryTest.php @@ -0,0 +1,186 @@ +commentResource = $this->getMockBuilder(ShipmentCommentResourceInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->commentFactory = $this->getMockBuilder(ShipmentCommentInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->searchResultFactory = $this->getMockBuilder(ShipmentCommentSearchResultInterfaceFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->collectionProcessor = $this->getMockBuilder(CollectionProcessorInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->shipmentRepositoryMock = $this->getMockBuilder(ShipmentRepositoryInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->shipmentCommentSender = $this->getMockBuilder(ShipmentCommentSender::class) + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock(); + + $this->shipmentMock = $this->getMockBuilder(Shipment::class)->disableOriginalConstructor()->getMock(); + $this->commentMock = $this->getMockBuilder(Comment::class)->disableOriginalConstructor()->getMock(); + + $this->commentRepository = new CommentRepository( + $this->commentResource, + $this->commentFactory, + $this->searchResultFactory, + $this->collectionProcessor, + $this->shipmentCommentSender, + $this->shipmentRepositoryMock, + $this->loggerMock + ); + } + + public function testSave() + { + $comment = "Comment text"; + $shipmentId = 123; + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willReturnSelf(); + $this->commentMock->expects($this->once()) + ->method('getIsCustomerNotified') + ->willReturn(1); + $this->commentMock->expects($this->once()) + ->method('getParentId') + ->willReturn($shipmentId); + $this->commentMock->expects($this->once()) + ->method('getComment') + ->willReturn($comment); + + $this->shipmentRepositoryMock->expects($this->once()) + ->method('get') + ->with($shipmentId) + ->willReturn($this->shipmentMock); + $this->shipmentCommentSender->expects($this->once()) + ->method('send') + ->with($this->shipmentMock, true, $comment); + $this->assertEquals($this->commentMock, $this->commentRepository->save($this->commentMock)); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + * @expectedExceptionMessage Could not save the shipment comment. + */ + public function testSaveWithException() + { + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willThrowException( + new \Magento\Framework\Exception\CouldNotSaveException(__('Could not save the shipment comment.')) + ); + + $this->commentRepository->save($this->commentMock); + } + + public function testSaveSendCatchException() + { + $comment = "Comment text"; + $creditmemoId = 123; + $this->commentResource->expects($this->once()) + ->method('save') + ->with($this->commentMock) + ->willReturnSelf(); + $this->commentMock->expects($this->once()) + ->method('getIsCustomerNotified') + ->willReturn(1); + $this->commentMock->expects($this->once()) + ->method('getParentId') + ->willReturn($creditmemoId); + $this->commentMock->expects($this->once()) + ->method('getComment') + ->willReturn($comment); + + $this->shipmentRepositoryMock->expects($this->once()) + ->method('get') + ->with($creditmemoId) + ->willReturn($this->shipmentMock); + $this->shipmentCommentSender->expects($this->once()) + ->method('send') + ->willThrowException(new \Exception()); + $this->loggerMock->expects($this->once()) + ->method('warning'); + + $this->commentRepository->save($this->commentMock); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/OrderRegistrarTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/OrderRegistrarTest.php index ecc37a2cd427d..9eb6be5f6d66e 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/OrderRegistrarTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/OrderRegistrarTest.php @@ -37,23 +37,20 @@ protected function setUp() public function testRegister() { $item1 = $this->getShipmentItemMock(); - $item1->expects($this->once()) - ->method('getQty') - ->willReturn(0); - $item1->expects($this->never()) - ->method('register'); + $item1->expects($this->once())->method('getQty')->willReturn(0); + $item1->expects($this->never())->method('register'); + $item1->expects($this->never())->method('getOrderItem'); $item2 = $this->getShipmentItemMock(); - $item2->expects($this->once()) - ->method('getQty') - ->willReturn(0.5); - $item2->expects($this->once()) - ->method('register'); + $item2->expects($this->atLeastOnce())->method('getQty')->willReturn(0.5); + $item2->expects($this->once())->method('register'); + + $orderItemMock = $this->createMock(\Magento\Sales\Model\Order\Item::class); + $orderItemMock->expects($this->once())->method('isDummy')->with(true)->willReturn(false); + $item2->expects($this->once())->method('getOrderItem')->willReturn($orderItemMock); $items = [$item1, $item2]; - $this->shipmentMock->expects($this->once()) - ->method('getItems') - ->willReturn($items); + $this->shipmentMock->expects($this->once())->method('getItems')->willReturn($items); $this->assertEquals( $this->orderMock, $this->model->register($this->orderMock, $this->shipmentMock) @@ -67,7 +64,7 @@ private function getShipmentItemMock() { return $this->getMockBuilder(\Magento\Sales\Api\Data\ShipmentItemInterface::class) ->disableOriginalConstructor() - ->setMethods(['register']) + ->setMethods(['register', 'getOrderItem']) ->getMockForAbstractClass(); } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/Sender/EmailSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/Sender/EmailSenderTest.php index 3d37018a61bb3..94347e8b32d54 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/Sender/EmailSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Shipment/Sender/EmailSenderTest.php @@ -262,6 +262,7 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending 'formattedShippingAddress' => 'Formatted address', 'formattedBillingAddress' => 'Formatted address', ]; + $transport = new \Magento\Framework\DataObject($transport); $this->eventManagerMock->expects($this->once()) ->method('dispatch') @@ -269,13 +270,14 @@ public function testSend($configValue, $forceSyncMode, $isComment, $emailSending 'email_shipment_set_template_vars_before', [ 'sender' => $this->subject, - 'transport' => $transport, + 'transport' => $transport->getData(), + 'transportObject' => $transport, ] ); $this->templateContainerMock->expects($this->once()) ->method('setTemplateVars') - ->with($transport); + ->with($transport->getData()); $this->identityContainerMock->expects($this->once()) ->method('isEnabled') diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentDocumentFactoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentDocumentFactoryTest.php index 54f3cb49cee6d..e681edf3e542f 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentDocumentFactoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentDocumentFactoryTest.php @@ -18,7 +18,7 @@ use Magento\Framework\EntityManager\HydratorInterface; /** - * Class ShipmentDocumentFactoryTest + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ShipmentDocumentFactoryTest extends \PHPUnit\Framework\TestCase { @@ -92,7 +92,7 @@ protected function setUp() $this->shipmentMock = $this->getMockBuilder(ShipmentInterface::class) ->disableOriginalConstructor() - ->setMethods(['addComment', 'addTrack']) + ->setMethods(['addComment', 'addTrack', 'setCustomerNote', 'setCustomerNoteNotify']) ->getMockForAbstractClass(); $this->hydratorPoolMock = $this->getMockBuilder(HydratorPool::class) @@ -128,14 +128,8 @@ public function testCreate() $packages = []; $items = [1 => 10]; - $this->itemMock->expects($this->once()) - ->method('getOrderItemId') - ->willReturn(1); - - $this->itemMock->expects($this->once()) - ->method('getQty') - ->willReturn(10); - + $this->itemMock->expects($this->once())->method('getOrderItemId')->willReturn(1); + $this->itemMock->expects($this->once())->method('getQty')->willReturn(10); $this->shipmentFactoryMock->expects($this->once()) ->method('create') ->with( @@ -166,7 +160,7 @@ public function testCreate() if ($appendComment) { $comment = "New comment!"; $visibleOnFront = true; - $this->commentMock->expects($this->once()) + $this->commentMock->expects($this->exactly(2)) ->method('getComment') ->willReturn($comment); @@ -178,6 +172,10 @@ public function testCreate() ->method('addComment') ->with($comment, $appendComment, $visibleOnFront) ->willReturnSelf(); + + $this->shipmentMock->expects($this->once()) + ->method('setCustomerNoteNotify') + ->with(true); } $this->assertEquals( diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentFactoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentFactoryTest.php index b4fb645c02f8b..e65b1b8330b93 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentFactoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentFactoryTest.php @@ -71,18 +71,31 @@ protected function setUp() */ public function testCreate($tracks) { - $orderItem = $this->createPartialMock(\Magento\Sales\Model\Order\Item::class, ['getId', 'getQtyOrdered']); + $orderItem = $this->createPartialMock( + \Magento\Sales\Model\Order\Item::class, + ['getId', 'getQtyOrdered', 'getParentItemId', 'getIsVirtual'] + ); $orderItem->expects($this->any()) ->method('getId') ->willReturn(1); $orderItem->expects($this->any()) ->method('getQtyOrdered') ->willReturn(5); + $orderItem->expects($this->any())->method('getParentItemId')->willReturn(false); + $orderItem->expects($this->any())->method('getIsVirtual')->willReturn(false); - $shipmentItem = $this->createPartialMock(\Magento\Sales\Model\Order\Shipment\Item::class, ['setQty']); + $shipmentItem = $this->createPartialMock( + \Magento\Sales\Model\Order\Shipment\Item::class, + ['setQty', 'getOrderItem', 'getQty'] + ); $shipmentItem->expects($this->once()) ->method('setQty') ->with(5); + $shipmentItem->expects($this->once()) + ->method('getQty') + ->willReturn(5); + + $shipmentItem->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($orderItem); $order = $this->createPartialMock(\Magento\Sales\Model\Order::class, ['getAllItems']); $order->expects($this->any()) diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderIncrementIdCheckerTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderIncrementIdCheckerTest.php new file mode 100644 index 0000000000000..612b1f6f4fe44 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderIncrementIdCheckerTest.php @@ -0,0 +1,84 @@ +selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) + ->disableOriginalConstructor() + ->getMock(); + $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf()); + $this->selectMock->expects($this->any())->method('where'); + + $this->adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class) + ->disableOriginalConstructor() + ->getMock(); + $this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock)); + + $this->resourceMock = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resourceMock->expects( + $this->any() + )->method( + 'getConnection' + )->will( + $this->returnValue($this->adapterMock) + ); + + $this->model = $objectManagerHelper->getObject( + \Magento\Sales\Model\OrderIncrementIdChecker::class, + [ + 'resourceModel' => $this->resourceMock + ] + ); + } + + /** + * Unit test to verify if isOrderIncrementIdUsed method works with different types increment ids + * + * @param array $value + * @dataProvider isOrderIncrementIdUsedDataProvider + */ + public function testIsIncrementIdUsed($value) + { + $expectedBind = [':increment_id' => $value]; + $this->adapterMock->expects($this->once())->method('fetchOne')->with($this->selectMock, $expectedBind); + $this->model->isIncrementIdUsed($value); + } + + /** + * @return array + */ + public function isOrderIncrementIdUsedDataProvider() + { + return [[100000001], ['10000000001'], ['M10000000001']]; + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php index dab92632426fa..fb1970638753f 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php @@ -7,6 +7,8 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory; +use Magento\Framework\Locale\ResolverInterface; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order; use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory as HistoryCollectionFactory; @@ -73,6 +75,16 @@ class OrderTest extends \PHPUnit\Framework\TestCase */ protected $productCollectionFactoryMock; + /** + * @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $localeResolver; + + /** + * @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $timezone; + protected function setUp() { $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -124,6 +136,8 @@ protected function setUp() true, ['round'] ); + $this->localeResolver = $this->createMock(ResolverInterface::class); + $this->timezone = $this->createMock(TimezoneInterface::class); $this->incrementId = '#00000001'; $this->eventManager = $this->createMock(\Magento\Framework\Event\Manager::class); $context = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']); @@ -138,7 +152,9 @@ protected function setUp() 'historyCollectionFactory' => $this->historyCollectionFactoryMock, 'salesOrderCollectionFactory' => $this->salesOrderCollectionFactoryMock, 'priceCurrency' => $this->priceCurrency, - 'productListFactory' => $this->productCollectionFactoryMock + 'productListFactory' => $this->productCollectionFactoryMock, + 'localeResolver' => $this->localeResolver, + 'timezone' => $this->timezone, ] ); } @@ -1044,6 +1060,22 @@ public function testResetOrderWillResetPayment() ); } + public function testGetCreatedAtFormattedUsesCorrectLocale() + { + $localeCode = 'nl_NL'; + + $this->localeResolver->expects($this->once())->method('getDefaultLocale')->willReturn($localeCode); + $this->timezone->expects($this->once())->method('formatDateTime') + ->with( + $this->anything(), + $this->anything(), + $this->anything(), + $localeCode + ); + + $this->order->getCreatedAtFormatted(\IntlDateFormatter::SHORT); + } + public function notInvoicingStatesProvider() { return [ diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/RelationTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/RelationTest.php index 787e6f8e065d2..a7a615fb0f508 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/RelationTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/RelationTest.php @@ -86,7 +86,8 @@ protected function setUp() 'getId', 'getItems', 'getTracks', - 'getComments' + 'getComments', + 'getTracksCollection', ] ) ->getMock(); @@ -123,7 +124,7 @@ public function testProcessRelations() ->method('getComments') ->willReturn([$this->commentMock]); $this->shipmentMock->expects($this->exactly(2)) - ->method('getTracks') + ->method('getTracksCollection') ->willReturn([$this->trackMock]); $this->itemMock->expects($this->once()) ->method('setParentId') diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/TrackTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/TrackTest.php index ea19ce7d7ff9d..588101167de17 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/TrackTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/TrackTest.php @@ -89,6 +89,8 @@ protected function setUp() */ public function testSave() { + $shipmentMock = $this->createMock(\Magento\Sales\Model\Order\Shipment::class); + $orderMock = $this->createMock(\Magento\Sales\Model\Order::class); $this->entitySnapshotMock->expects($this->once()) ->method('isModified') ->with($this->trackModelMock) @@ -98,6 +100,8 @@ public function testSave() ->with($this->equalTo($this->trackModelMock)) ->will($this->returnValue([])); $this->trackModelMock->expects($this->any())->method('getData')->willReturn([]); + $this->trackModelMock->expects($this->atLeastOnce())->method('getShipment')->willReturn($shipmentMock); + $shipmentMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($orderMock); $this->trackResource->save($this->trackModelMock); $this->assertTrue(true); } diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Provider/NotSyncedDataProviderTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Provider/NotSyncedDataProviderTest.php index 8e248d239a501..5ed60f8de306f 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Provider/NotSyncedDataProviderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Provider/NotSyncedDataProviderTest.php @@ -5,15 +5,11 @@ */ namespace Magento\Sales\Test\Unit\Model\ResourceModel\Provider; -use Magento\Framework\ObjectManager\TMap; use Magento\Framework\ObjectManager\TMapFactory; use Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProvider; use Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProviderInterface; use PHPUnit_Framework_MockObject_MockObject as MockObject; -/** - * Class NotSyncedDataProviderTest - */ class NotSyncedDataProviderTest extends \PHPUnit\Framework\TestCase { public function testGetIdsEmpty() @@ -23,30 +19,14 @@ public function testGetIdsEmpty() ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $tMap = $this->getMockBuilder(TMap::class) - ->disableOriginalConstructor() - ->getMock(); - $tMapFactory->expects(static::once()) - ->method('create') - ->with( - [ - 'array' => [], - 'type' => NotSyncedDataProviderInterface::class - ] - ) - ->willReturn($tMap); - $tMap->expects(static::once()) - ->method('getIterator') - ->willReturn(new \ArrayIterator([])); + $tMapFactory->method('create') + ->willReturn([]); - $provider = new NotSyncedDataProvider($tMapFactory, []); - static::assertEquals([], $provider->getIds('main_table', 'grid_table')); + $provider = new NotSyncedDataProvider($tMapFactory); + self::assertEquals([], $provider->getIds('main_table', 'grid_table')); } - /** - * @covers \Magento\Sales\Model\ResourceModel\Provider\NotSyncedDataProvider::getIds - */ public function testGetIds() { /** @var TMapFactory|MockObject $tMapFactory */ @@ -54,46 +34,31 @@ public function testGetIds() ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $tMap = $this->getMockBuilder(TMap::class) - ->disableOriginalConstructor() - ->getMock(); $provider1 = $this->getMockBuilder(NotSyncedDataProviderInterface::class) ->getMockForAbstractClass(); - $provider1->expects(static::once()) - ->method('getIds') + $provider1->method('getIds') ->willReturn([1, 2]); $provider2 = $this->getMockBuilder(NotSyncedDataProviderInterface::class) ->getMockForAbstractClass(); - $provider2->expects(static::once()) - ->method('getIds') + $provider2->method('getIds') ->willReturn([2, 3, 4]); - $tMapFactory->expects(static::once()) - ->method('create') - ->with( + $tMapFactory->method('create') + ->with(self::equalTo( [ - 'array' => [ - 'provider1' => NotSyncedDataProviderInterface::class, - 'provider2' => NotSyncedDataProviderInterface::class - ], + 'array' => [$provider1, $provider2], 'type' => NotSyncedDataProviderInterface::class ] - ) - ->willReturn($tMap); - $tMap->expects(static::once()) - ->method('getIterator') - ->willReturn(new \ArrayIterator([$provider1, $provider2])); + )) + ->willReturn([$provider1, $provider2]); - $provider = new NotSyncedDataProvider( - $tMapFactory, - [ - 'provider1' => NotSyncedDataProviderInterface::class, - 'provider2' => NotSyncedDataProviderInterface::class, - ] - ); + $provider = new NotSyncedDataProvider($tMapFactory, [$provider1, $provider2]); - static::assertEquals([1, 2, 3, 4], array_values($provider->getIds('main_table', 'grid_table'))); + self::assertEquals( + [1, 2, 3, 4], + array_values($provider->getIds('main_table', 'grid_table')) + ); } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Service/CreditmemoServiceTest.php b/app/code/Magento/Sales/Test/Unit/Model/Service/CreditmemoServiceTest.php index 9ecab6cf9ab52..2e668f0b0d6f1 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Service/CreditmemoServiceTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Service/CreditmemoServiceTest.php @@ -243,6 +243,78 @@ public function testRefund() $this->assertSame($creditMemoMock, $this->creditmemoService->refund($creditMemoMock, true)); } + public function testRefundPendingCreditMemo() + { + $creditMemoMock = $this->getMockBuilder(\Magento\Sales\Api\Data\CreditmemoInterface::class) + ->setMethods(['getId', 'getOrder', 'getState', 'getInvoice']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $creditMemoMock->expects($this->once())->method('getId')->willReturn(444); + $creditMemoMock->expects($this->once())->method('getState') + ->willReturn(\Magento\Sales\Model\Order\Creditmemo::STATE_OPEN); + $orderMock = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + + $creditMemoMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($orderMock); + $orderMock->expects($this->once())->method('getBaseTotalRefunded')->willReturn(0); + $orderMock->expects($this->once())->method('getBaseTotalPaid')->willReturn(10); + $creditMemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(10); + + $this->priceCurrencyMock->expects($this->any()) + ->method('round') + ->willReturnArgument(0); + + // Set payment adapter dependency + $refundAdapterMock = $this->getMockBuilder(\Magento\Sales\Model\Order\RefundAdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->objectManagerHelper->setBackwardCompatibleProperty( + $this->creditmemoService, + 'refundAdapter', + $refundAdapterMock + ); + + // Set resource dependency + $resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerHelper->setBackwardCompatibleProperty( + $this->creditmemoService, + 'resource', + $resourceMock + ); + + // Set order repository dependency + $orderRepositoryMock = $this->getMockBuilder(\Magento\Sales\Api\OrderRepositoryInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->objectManagerHelper->setBackwardCompatibleProperty( + $this->creditmemoService, + 'orderRepository', + $orderRepositoryMock + ); + + $adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $resourceMock->expects($this->once())->method('getConnection')->with('sales')->willReturn($adapterMock); + $adapterMock->expects($this->once())->method('beginTransaction'); + $refundAdapterMock->expects($this->once()) + ->method('refund') + ->with($creditMemoMock, $orderMock, false) + ->willReturn($orderMock); + $orderRepositoryMock->expects($this->once()) + ->method('save') + ->with($orderMock); + $creditMemoMock->expects($this->once()) + ->method('getInvoice') + ->willReturn(null); + $adapterMock->expects($this->once())->method('commit'); + $this->creditmemoRepositoryMock->expects($this->once()) + ->method('save'); + + $this->assertSame($creditMemoMock, $this->creditmemoService->refund($creditMemoMock, true)); + } + /** * @expectedExceptionMessage The most money available to refund is 1. * @expectedException \Magento\Framework\Exception\LocalizedException diff --git a/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php b/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php index 14e1d3bac6a35..067f83d1e5b32 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php @@ -163,9 +163,30 @@ public function testCancel() $this->orderMock->expects($this->once()) ->method('cancel') ->willReturn($this->orderMock); + $this->orderMock->expects($this->once()) + ->method('canCancel') + ->willReturn(true); $this->assertTrue($this->orderService->cancel(123)); } + /** + * test for Order::cancel() fail case + */ + public function testCancelFailed() + { + $this->orderRepositoryMock->expects($this->once()) + ->method('get') + ->with(123) + ->willReturn($this->orderMock); + $this->orderMock->expects($this->never()) + ->method('cancel') + ->willReturn($this->orderMock); + $this->orderMock->expects($this->once()) + ->method('canCancel') + ->willReturn(false); + $this->assertFalse($this->orderService->cancel(123)); + } + public function testGetCommentsList() { $this->filterBuilderMock->expects($this->once()) diff --git a/app/code/Magento/Sales/Test/Unit/Observer/Backend/SubtractQtyFromQuotesObserverTest.php b/app/code/Magento/Sales/Test/Unit/Observer/Backend/SubtractQtyFromQuotesObserverTest.php index a6a828c888fc0..6b94605108866 100644 --- a/app/code/Magento/Sales/Test/Unit/Observer/Backend/SubtractQtyFromQuotesObserverTest.php +++ b/app/code/Magento/Sales/Test/Unit/Observer/Backend/SubtractQtyFromQuotesObserverTest.php @@ -15,12 +15,12 @@ class SubtractQtyFromQuotesObserverTest extends \PHPUnit\Framework\TestCase protected $_model; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Quote\Model\ResourceModel\Quote|\PHPUnit_Framework_MockObject_MockObject */ protected $_quoteMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject */ protected $_observerMock; @@ -48,7 +48,7 @@ public function testSubtractQtyFromQuotes() ['getId', 'getStatus', '__wakeup'] ); $this->_eventMock->expects($this->once())->method('getProduct')->will($this->returnValue($productMock)); - $this->_quoteMock->expects($this->once())->method('substractProductFromQuotes')->with($productMock); + $this->_quoteMock->expects($this->once())->method('subtractProductFromQuotes')->with($productMock); $this->_model->execute($this->_observerMock); } } diff --git a/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/AddressTest.php b/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/AddressTest.php index 1a903ab68952c..c79b06da60c4e 100644 --- a/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/AddressTest.php +++ b/app/code/Magento/Sales/Test/Unit/Ui/Component/Listing/Column/AddressTest.php @@ -47,7 +47,7 @@ public function testPrepareDataSource() { $itemName = 'itemName'; $oldItemValue = "itemValue\n"; - $newItemValue = 'itemValue
        '; + $newItemValue = "itemValue
        \n"; $dataSource = [ 'data' => [ 'items' => [ @@ -57,7 +57,7 @@ public function testPrepareDataSource() ]; $this->model->setData('name', $itemName); - $this->escaper->expects($this->once())->method('escapeHtml')->with($newItemValue)->willReturnArgument(0); + $this->escaper->expects($this->any())->method('escapeHtml')->with($oldItemValue)->willReturnArgument(0); $dataSource = $this->model->prepareDataSource($dataSource); $this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]); } diff --git a/app/code/Magento/Sales/Ui/Component/Listing/Column/Address.php b/app/code/Magento/Sales/Ui/Component/Listing/Column/Address.php index 23a6e7a41a5b7..d900bb7ba670f 100644 --- a/app/code/Magento/Sales/Ui/Component/Listing/Column/Address.php +++ b/app/code/Magento/Sales/Ui/Component/Listing/Column/Address.php @@ -49,9 +49,7 @@ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { - $item[$this->getData('name')] = $this->escaper->escapeHtml( - str_replace("\n", '
        ', $item[$this->getData('name')]) - ); + $item[$this->getData('name')] = nl2br($this->escaper->escapeHtml($item[$this->getData('name')])); } } diff --git a/app/code/Magento/Sales/composer.json b/app/code/Magento/Sales/composer.json index b4bdf144b42bd..55e6a4dda763a 100644 --- a/app/code/Magento/Sales/composer.json +++ b/app/code/Magento/Sales/composer.json @@ -4,35 +4,36 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-customer": "100.2.*", + "magento/module-catalog": "102.0.*", + "magento/module-bundle": "100.2.*", + "magento/module-customer": "101.0.*", "magento/module-authorization": "100.2.*", "magento/module-payment": "100.2.*", "magento/module-checkout": "100.2.*", "magento/module-theme": "100.2.*", - "magento/module-sales-rule": "100.2.*", + "magento/module-sales-rule": "101.0.*", "magento/module-sales-sequence": "100.2.*", "magento/module-backend": "100.2.*", - "magento/module-widget": "100.2.*", + "magento/module-widget": "101.0.*", "magento/module-directory": "100.2.*", - "magento/module-eav": "100.2.*", + "magento/module-eav": "101.0.*", "magento/module-tax": "100.2.*", "magento/module-gift-message": "100.2.*", "magento/module-reports": "100.2.*", "magento/module-catalog-inventory": "100.2.*", - "magento/module-wishlist": "100.2.*", + "magento/module-wishlist": "101.0.*", "magento/module-shipping": "100.2.*", - "magento/module-config": "100.2.*", + "magento/module-config": "101.0.*", "magento/module-media-storage": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-ui": "100.2.*", - "magento/module-quote": "100.2.*" + "magento/framework": "101.0.*", + "magento/module-ui": "101.0.*", + "magento/module-quote": "101.0.*" }, "suggest": { "magento/module-sales-sample-data": "Sample Data version:100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "101.0.2", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 9de3f238d6a39..df2088aa7b3e8 100644 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -470,6 +470,15 @@ CreditmemoRelationsComposite + + + + + Magento\Sales\Model\ResourceModel\Provider\UpdatedIdListProvider + Magento\Sales\Model\ResourceModel\Provider\UpdatedAtListProvider + + + sales_order @@ -520,6 +529,7 @@ sales_order_payment.method sales_order.total_refunded + Magento\Sales\Model\ResourceModel\Provider\NotSyncedOrderDataProvider @@ -676,7 +686,7 @@ BillingAddressAggregator ShippingAddressAggregator sales_order.shipping_description - sales_order.base_subtotal + sales_invoice.base_subtotal sales_order.base_shipping_amount sales_invoice.base_grand_total sales_invoice.grand_total diff --git a/app/code/Magento/Sales/etc/fieldset.xml b/app/code/Magento/Sales/etc/fieldset.xml index 3d29575063fef..0c8208b4167f5 100644 --- a/app/code/Magento/Sales/etc/fieldset.xml +++ b/app/code/Magento/Sales/etc/fieldset.xml @@ -279,7 +279,7 @@ - + @@ -486,6 +486,12 @@ + + + + + + diff --git a/app/code/Magento/Sales/etc/module.xml b/app/code/Magento/Sales/etc/module.xml index 4c1a534faddf7..b234cdad876cc 100644 --- a/app/code/Magento/Sales/etc/module.xml +++ b/app/code/Magento/Sales/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/app/code/Magento/Sales/i18n/en_US.csv b/app/code/Magento/Sales/i18n/en_US.csv index 6568284300225..58febfda3d6ca 100644 --- a/app/code/Magento/Sales/i18n/en_US.csv +++ b/app/code/Magento/Sales/i18n/en_US.csv @@ -233,7 +233,6 @@ Sales,Sales "You can't create an invoice without products.","You can't create an invoice without products." "New Invoice","New Invoice" "We can't save the invoice right now.","We can't save the invoice right now." -"The invoice and the shipment have been created. The shipping label cannot be created now.","The invoice and the shipment have been created. The shipping label cannot be created now." "You created the invoice and shipment.","You created the invoice and shipment." "The invoice has been created.","The invoice has been created." "We can't send the invoice email right now.","We can't send the invoice email right now." @@ -804,3 +803,4 @@ Created,Created "PDF Shipments","PDF Shipments" "PDF Creditmemos","PDF Creditmemos" Refunds,Refunds +"Shipment with requested ID %1 doesn't correspond with Order with requested ID %2.","Shipment with requested ID %1 doesn't correspond with Order with requested ID %2." diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_customer_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_customer_block.xml index 5cd530defd493..c321bee460e46 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_customer_block.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_customer_block.xml @@ -27,26 +27,26 @@ Magento\Backend\Model\Widget\Grid\Row\UrlGeneratorId - + ID entity_id right - + Name name - + Email email - + Phone billing_telephone @@ -54,26 +54,26 @@ col-phone - + ZIP/Post Code billing_postcode - + Country billing_country_id country - + State/Province billing_regione - + Signed-up Point store_name @@ -81,7 +81,7 @@ - + Website website_name diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml index 79b686f7d0a0c..eb0a7685e5e22 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml @@ -21,7 +21,7 @@ - + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_grid_block.xml index 3ee6753d743d2..7f14ff3728a47 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_grid_block.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_grid_block.xml @@ -30,7 +30,7 @@ - + Credit Memo text @@ -40,7 +40,7 @@ col-memo - + billing_name Bill-to Name @@ -49,7 +49,7 @@ col-name - + Created datetime @@ -59,7 +59,7 @@ col-period - + state Status @@ -70,7 +70,7 @@ col-status - + base_grand_total Refunded diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml index e1db288398c7b..0c1b395b5116d 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml @@ -18,7 +18,7 @@ - + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml index e373eb0461dc5..29a61308391c6 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml @@ -9,7 +9,7 @@ - + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_view.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_view.xml index ffae243c3e5bc..61dda8e23301d 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_view.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_view.xml @@ -17,7 +17,7 @@ - + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_grid_block.xml index 52492c0f250e3..941696f0ce898 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_grid_block.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_grid_block.xml @@ -30,7 +30,7 @@ - + Invoice text @@ -40,7 +40,7 @@ col-invoice-number - + billing_name Bill-to Name @@ -49,7 +49,7 @@ col-name - + Invoice Date datetime @@ -59,7 +59,7 @@ col-period - + state Status @@ -70,7 +70,7 @@ col-status - + grand_total Amount diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_new.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_new.xml index 9f443425e1ac3..def5ebaf546cd 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_new.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_new.xml @@ -21,7 +21,7 @@ - + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_updateqty.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_updateqty.xml index 2e972172fd10a..4df3f057f6a58 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_updateqty.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_updateqty.xml @@ -9,7 +9,7 @@ - + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_view.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_view.xml index 2a6598d69462e..6227412852c84 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_view.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_view.xml @@ -18,7 +18,7 @@ - + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_shipment_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_shipment_grid_block.xml index 8d783975a404f..0180efd29d2fc 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_shipment_grid_block.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_shipment_grid_block.xml @@ -30,7 +30,7 @@ - + Shipment text @@ -40,7 +40,7 @@ col-memo - + shipping_name Ship-to Name @@ -49,7 +49,7 @@ col-name - + Ship Date datetime @@ -59,7 +59,7 @@ col-period - + total_qty Total Quantity diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_status_index.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_status_index.xml index e96932789e70e..87d7644a4b00f 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_status_index.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_status_index.xml @@ -27,13 +27,13 @@ 1 - + Status label - + Status Code status @@ -42,7 +42,7 @@ 200 - + Default Status is_default @@ -62,7 +62,7 @@ - + Visible On Storefront visible_on_front @@ -82,14 +82,14 @@ - + State Code and Title state text - + Action unassign diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml index 12b4cfdf98920..e1a406346fc1a 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml @@ -41,21 +41,21 @@ Row Total - - - - col-product - col-status - col-price-original - col-price - col-ordered-qty - col-subtotal - col-tax-amount - col-tax-percent - col-discont - col-total - - + + + + col-product + col-status + col-price-original + col-price + col-ordered-qty + col-subtotal + col-tax-amount + col-tax-percent + col-discont + col-total + + diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/billing/method/form.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/billing/method/form.phtml index 9dda4e7e067ed..2133d7996f470 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/billing/method/form.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/billing/method/form.phtml @@ -6,49 +6,50 @@ ?> hasMethods()) : ?> -
        -
        - getMethods(); - $_methodsCount = count($_methods); - $_counter = 0; - ?> - getCode(); - $_counter++; - ?> -
        - 1) : ?> - getSelectedMethodCode() == $_code) : ?> - checked="checked" +
        +
        + getMethods(); + $_methodsCount = count($_methods); + $_counter = 0; + $currentSelectedMethod = $block->getSelectedMethodCode(); + ?> + getCode(); + $_counter++; + ?> +
        + 1) : ?> + getSelectedMethodCode() == $_code) : ?> + checked="checked" + + + class="admin__control-radioescapeHtml($className); ?>"/> + + + + - - class="admin__control-radioescapeHtml($className); ?>"/> - - - - - - -
        -
        - getChildHtml('payment.method.' . $_code) ?> -
        - -
        -
        + +
        +
        + getChildHtml('payment.method.' . $_code) ?> +
        + +
        +
        diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml index 2ca2420934519..2dbf717f73439 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml @@ -67,11 +67,7 @@ canDisplayPrice()): ?> - getDataId() == 'cart'): ?> - getItemPrice($_item->getProduct()) ?> - - getItemPrice($_item) ?> - + getItemPrice($block->getProduct($_item)) ?> diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/creditmemo/create/items.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/creditmemo/create/items.phtml index fcf4ccad7060b..a73740c249b67 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/creditmemo/create/items.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/creditmemo/create/items.phtml @@ -4,6 +4,9 @@ * See COPYING.txt for license details. */ +/** + * @var Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items $block + */ // @codingStandardsIgnoreFile ?> @@ -101,6 +104,7 @@
        getChildHtml('creditmemo_totals') ?> +
        getUpdateTotalsButtonHtml() ?>
        getSource() ?> @@ -24,7 +27,7 @@ @@ -34,7 +37,7 @@ + diff --git a/app/code/Magento/Sitemap/Model/Observer.php b/app/code/Magento/Sitemap/Model/Observer.php index 3ae3061310a0b..840a6a1858fae 100644 --- a/app/code/Magento/Sitemap/Model/Observer.php +++ b/app/code/Magento/Sitemap/Model/Observer.php @@ -113,7 +113,6 @@ public function scheduledGenerateSitemaps() $sitemap->generateXml(); } catch (\Exception $e) { $errors[] = $e->getMessage(); - throw $e; } } @@ -122,8 +121,7 @@ public function scheduledGenerateSitemaps() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ) ) { - $translate = $this->_translateModel->getTranslateInline(); - $this->_translateModel->setTranslateInline(false); + $this->inlineTranslation->suspend(); $this->_transportBuilder->setTemplateIdentifier( $this->_scopeConfig->getValue( diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php index 4305c9af90162..8d7caca12b96f 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php @@ -192,9 +192,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=') * * @param int $storeId * @param string $attributeCode + * @param string $column Add attribute value to given column * @return void */ - protected function _joinAttribute($storeId, $attributeCode) + protected function _joinAttribute($storeId, $attributeCode, $column = null) { $connection = $this->getConnection(); $attribute = $this->_getAttribute($attributeCode); @@ -207,6 +208,8 @@ protected function _joinAttribute($storeId, $attributeCode) . ' AND ' . $connection->quoteInto($attrTableAlias . '.attribute_id = ?', $attribute['attribute_id']), [] ); + // Global scope attribute value + $columnValue = 't1_' . $attributeCode . '.value'; if (!$attribute['is_global']) { $attrTableAlias2 = 't2_' . $attributeCode; @@ -217,6 +220,15 @@ protected function _joinAttribute($storeId, $attributeCode) . ' AND ' . $connection->quoteInto($attrTableAlias2 . '.store_id = ?', $storeId), [] ); + // Store scope attribute value + $columnValue = $this->getConnection()->getIfNullSql('t2_' . $attributeCode . '.value', $columnValue); + } + + // Add attribute value to result set if needed + if (isset($column)) { + $this->_select->columns([ + $column => $columnValue + ]); } } @@ -285,30 +297,16 @@ public function getCollection($storeId) // Join product images required attributes $imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId()); if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) { - $this->_joinAttribute($store->getId(), 'name'); - $this->_select->columns( - ['name' => $this->getConnection()->getIfNullSql('t2_name.value', 't1_name.value')] - ); + $this->_joinAttribute($store->getId(), 'name', 'name'); if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) { - $this->_joinAttribute($store->getId(), 'thumbnail'); - $this->_select->columns( - [ - 'thumbnail' => $this->getConnection()->getIfNullSql( - 't2_thumbnail.value', - 't1_thumbnail.value' - ), - ] - ); + $this->_joinAttribute($store->getId(), 'thumbnail', 'thumbnail'); } elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) { - $this->_joinAttribute($store->getId(), 'image'); - $this->_select->columns( - ['image' => $this->getConnection()->getIfNullSql('t2_image.value', 't1_image.value')] - ); + $this->_joinAttribute($store->getId(), 'image', 'image'); } } - $query = $connection->query($this->_select); + $query = $connection->query($this->prepareSelectStatement($this->_select)); while ($row = $query->fetch()) { $product = $this->_prepareProduct($row, $store->getId()); $products[$product->getId()] = $product; @@ -425,6 +423,17 @@ protected function _getMediaConfig() return $this->_mediaConfig; } + /** + * Allow to modify select statement with plugins + * + * @param \Magento\Framework\DB\Select $select + * @return \Magento\Framework\DB\Select + */ + public function prepareSelectStatement(\Magento\Framework\DB\Select $select) + { + return $select; + } + /** * Get product image URL from image filename and path * diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php b/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php index d050ea84ecccb..01addd0c19666 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php @@ -6,12 +6,15 @@ namespace Magento\Sitemap\Model\ResourceModel\Cms; use Magento\Cms\Api\Data\PageInterface; -use Magento\Framework\EntityManager\MetadataPool; -use Magento\Framework\Model\ResourceModel\Db\Context; -use Magento\Framework\Model\AbstractModel; +use Magento\Cms\Api\GetUtilityPageIdentifiersInterface; use Magento\Cms\Model\Page as CmsPage; +use Magento\Framework\App\ObjectManager; use Magento\Framework\DB\Select; use Magento\Framework\EntityManager\EntityManager; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Context; /** * Sitemap cms page collection model @@ -19,7 +22,7 @@ * @api * @since 100.0.2 */ -class Page extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Page extends AbstractDb { /** * @var MetadataPool @@ -34,19 +37,29 @@ class Page extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb protected $entityManager; /** - * @param Context $context - * @param MetadataPool $metadataPool - * @param EntityManager $entityManager - * @param string $connectionName + * @var GetUtilityPageIdentifiersInterface + * @since 100.2.0 + */ + private $getUtilityPageIdentifiers; + + /** + * @param Context $context + * @param MetadataPool $metadataPool + * @param EntityManager $entityManager + * @param string $connectionName + * @param GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers */ public function __construct( Context $context, MetadataPool $metadataPool, EntityManager $entityManager, - $connectionName = null + $connectionName = null, + GetUtilityPageIdentifiersInterface $getUtilityPageIdentifiers = null ) { - $this->metadataPool = $metadataPool; - $this->entityManager = $entityManager; + $this->metadataPool = $metadataPool; + $this->entityManager = $entityManager; + $this->getUtilityPageIdentifiers = $getUtilityPageIdentifiers ?: + ObjectManager::getInstance()->get(GetUtilityPageIdentifiersInterface::class); parent::__construct($context, $connectionName); } @@ -90,8 +103,8 @@ public function getCollection($storeId) )->where( 'main_table.is_active = 1' )->where( - 'main_table.identifier != ?', - \Magento\Cms\Model\Page::NOROUTE_PAGE_ID + 'main_table.identifier NOT IN (?)', + $this->getUtilityPageIdentifiers->execute() )->where( 'store_table.store_id IN(?)', [0, $storeId] diff --git a/app/code/Magento/Sitemap/Model/Sitemap.php b/app/code/Magento/Sitemap/Model/Sitemap.php index 515caebe1ef27..cad8023bd2794 100644 --- a/app/code/Magento/Sitemap/Model/Sitemap.php +++ b/app/code/Magento/Sitemap/Model/Sitemap.php @@ -43,6 +43,11 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento const TYPE_URL = 'url'; + /** + * Last mode date min value + */ + const LAST_MOD_MIN_VAL = '0000-01-01 00:00:00'; + /** * Real file path * @@ -157,6 +162,13 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento */ protected $_cacheTag = true; + /** + * Last mode min timestamp value + * + * @var int + */ + private $lastModMinTsVal; + /** * Initialize dependencies. * @@ -261,6 +273,7 @@ public function collectSitemapItems() /** @var $helper \Magento\Sitemap\Helper\Data */ $helper = $this->_sitemapData; $storeId = $this->getStoreId(); + $this->_storeManager->setCurrentStore($storeId); $this->addSitemapItem(new DataObject( [ @@ -661,7 +674,11 @@ protected function _getMediaUrl($url) */ protected function _getFormattedLastmodDate($date) { - return date('c', strtotime($date)); + if ($this->lastModMinTsVal === null) { + $this->lastModMinTsVal = strtotime(self::LAST_MOD_MIN_VAL); + } + $timestamp = max(strtotime($date), $this->lastModMinTsVal); + return date('c', $timestamp); } /** diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php index 92e6f4e2e2293..ac88f23ff9d69 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php @@ -7,6 +7,10 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +/** + * Class ObserverTest + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class ObserverTest extends \PHPUnit\Framework\TestCase { /** @@ -96,11 +100,11 @@ protected function setUp() ); } - /** - * @expectedException \Exception - */ - public function testScheduledGenerateSitemapsThrowsException() + public function testScheduledGenerateSitemapsSendsExceptionEmail() { + $exception = 'Sitemap Exception'; + $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class); + $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true); $this->collectionFactoryMock->expects($this->once()) @@ -111,7 +115,55 @@ public function testScheduledGenerateSitemapsThrowsException() ->method('getIterator') ->willReturn(new \ArrayIterator([$this->sitemapMock])); - $this->sitemapMock->expects($this->once())->method('generateXml')->willThrowException(new \Exception()); + $this->sitemapMock->expects($this->once()) + ->method('generateXml') + ->willThrowException(new \Exception($exception)); + + $this->scopeConfigMock->expects($this->at(1)) + ->method('getValue') + ->with( + \Magento\Sitemap\Model\Observer::XML_PATH_ERROR_RECIPIENT, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ->willReturn('error-recipient@example.com'); + + $this->inlineTranslationMock->expects($this->once()) + ->method('suspend'); + + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateIdentifier') + ->will($this->returnSelf()); + + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateOptions') + ->with([ + 'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, + ]) + ->will($this->returnSelf()); + + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateVars') + ->with(['warnings' => $exception]) + ->will($this->returnSelf()); + + $this->transportBuilderMock->expects($this->once()) + ->method('setFrom') + ->will($this->returnSelf()); + + $this->transportBuilderMock->expects($this->once()) + ->method('addTo') + ->will($this->returnSelf()); + + $this->transportBuilderMock->expects($this->once()) + ->method('getTransport') + ->willReturn($transport); + + $transport->expects($this->once()) + ->method('sendMessage'); + + $this->inlineTranslationMock->expects($this->once()) + ->method('resume'); $this->observer->scheduledGenerateSitemaps(); } diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php index 40b72cbd53c00..4f55653fad311 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php @@ -253,6 +253,8 @@ public function testGenerateXml($maxLines, $maxFileSize, $expectedFile, $expecte $expectedWrites, null ); + $this->storeManagerMock->expects($this->once())->method('setCurrentStore')->with(1); + $model->generateXml(); $this->assertCount(count($expectedFile), $actualData, 'Number of generated files is incorrect'); @@ -360,6 +362,8 @@ public function testAddSitemapToRobotsTxt($maxLines, $maxFileSize, $expectedFile $expectedWrites, $robotsInfo ); + $this->storeManagerMock->expects($this->once())->method('setCurrentStore')->with(1); + $model->generateXml(); } @@ -540,7 +544,7 @@ protected function _getModelMock($mockBeforeSave = false) $this->returnValue( [ new \Magento\Framework\DataObject( - ['url' => 'product.html', 'updated_at' => '2012-12-21 00:00:00'] + ['url' => 'product.html', 'updated_at' => '0000-00-00 00:00:00'] ), new \Magento\Framework\DataObject( [ diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-3.xml b/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-3.xml index 3a0357cf30c51..519464cf76cf1 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-3.xml +++ b/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-3.xml @@ -10,7 +10,7 @@ xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> http://store.com/product.html - 2012-12-21T00:00:00-08:00 + 0000-01-01T00:00:00-08:00 monthly 0.5 diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-single.xml b/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-single.xml index e79e022c98995..cc2ff96dd28f2 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-single.xml +++ b/app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-single.xml @@ -22,7 +22,7 @@ http://store.com/product.html - 2012-12-21T00:00:00-08:00 + 0000-01-01T00:00:00-08:00 monthly 0.5 diff --git a/app/code/Magento/Sitemap/composer.json b/app/code/Magento/Sitemap/composer.json index d5e7b41a72add..678e6f5fe198e 100644 --- a/app/code/Magento/Sitemap/composer.json +++ b/app/code/Magento/Sitemap/composer.json @@ -4,21 +4,21 @@ "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", "magento/module-store": "100.2.*", - "magento/module-catalog": "101.1.*", - "magento/module-eav": "100.2.*", - "magento/module-cms": "101.1.*", + "magento/module-catalog": "102.0.*", + "magento/module-eav": "101.0.*", + "magento/module-cms": "102.0.*", "magento/module-backend": "100.2.*", "magento/module-catalog-url-rewrite": "100.2.*", "magento/module-media-storage": "100.2.*", - "magento/framework": "100.2.*", - "magento/module-config": "100.2.*", + "magento/framework": "101.0.*", + "magento/module-config": "101.0.*", "magento/module-robots": "100.2.*" }, "suggest": { - "magento/module-config": "100.2.*" + "magento/module-config": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.2", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Sitemap/etc/module.xml b/app/code/Magento/Sitemap/etc/module.xml index 0edfcf84f644f..0cfe3d551d162 100644 --- a/app/code/Magento/Sitemap/etc/module.xml +++ b/app/code/Magento/Sitemap/etc/module.xml @@ -9,6 +9,7 @@ + diff --git a/app/code/Magento/Sitemap/view/adminhtml/layout/adminhtml_sitemap_index_grid_block.xml b/app/code/Magento/Sitemap/view/adminhtml/layout/adminhtml_sitemap_index_grid_block.xml index 23c96db891a15..cdaa6575d559c 100644 --- a/app/code/Magento/Sitemap/view/adminhtml/layout/adminhtml_sitemap_index_grid_block.xml +++ b/app/code/Magento/Sitemap/view/adminhtml/layout/adminhtml_sitemap_index_grid_block.xml @@ -24,7 +24,7 @@ - + ID sitemap_id @@ -32,25 +32,25 @@ col-id - + Filename sitemap_filename - + Path sitemap_path - + Link for Google Magento\Sitemap\Block\Adminhtml\Grid\Renderer\Link - + Last Generated sitemap_time @@ -59,7 +59,7 @@ col-date - + Store View store @@ -68,7 +68,7 @@ true - + Action 0 diff --git a/app/code/Magento/Store/App/Action/Plugin/Context.php b/app/code/Magento/Store/App/Action/Plugin/Context.php index 66fec992b38d7..133bc9c4fa004 100644 --- a/app/code/Magento/Store/App/Action/Plugin/Context.php +++ b/app/code/Magento/Store/App/Action/Plugin/Context.php @@ -7,7 +7,10 @@ namespace Magento\Store\App\Action\Plugin; use Magento\Framework\App\Http\Context as HttpContext; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Phrase; +use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Api\StoreCookieManagerInterface; use Magento\Store\Api\StoreResolverInterface; use Magento\Store\Model\StoreManagerInterface; @@ -65,35 +68,94 @@ public function __construct( * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeDispatch(AbstractAction $subject, RequestInterface $request) - { - /** @var \Magento\Store\Model\Store $defaultStore */ - $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); + public function beforeDispatch( + AbstractAction $subject, + RequestInterface $request + ) { + if ($this->isAlreadySet()) { + //If required store related value were already set for + //HTTP processors then just continuing as we were. + return; + } + /** @var string|array|null $storeCode */ $storeCode = $request->getParam( StoreResolverInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie() ); - if (is_array($storeCode)) { if (!isset($storeCode['_data']['code'])) { - throw new \InvalidArgumentException(new Phrase('Invalid store parameter.')); + $this->processInvalidStoreRequested(); } $storeCode = $storeCode['_data']['code']; } - /** @var \Magento\Store\Model\Store $currentStore */ - $currentStore = $storeCode ? $this->storeManager->getStore($storeCode) : $defaultStore; + if ($storeCode === '') { + //Empty code - is an invalid code and it was given explicitly + //(the value would be null if the code wasn't found). + $this->processInvalidStoreRequested(); + } + try { + $currentStore = $this->storeManager->getStore($storeCode); + } catch (NoSuchEntityException $exception) { + $this->processInvalidStoreRequested($exception); + } + + $this->updateContext($currentStore); + } + + /** + * Take action in case of invalid store requested. + * + * @param \Throwable|null $previousException + * + * @throws NotFoundException + */ + private function processInvalidStoreRequested( + \Throwable $previousException = null + ) { + $store = $this->storeManager->getStore(); + $this->updateContext($store); + throw new NotFoundException( + $previousException + ? __($previousException->getMessage()) + : __('Invalid store requested.'), + $previousException + ); + } + + /** + * Update context accordingly to the store found. + * + * @param StoreInterface $store + */ + private function updateContext(StoreInterface $store) + { $this->httpContext->setValue( StoreManagerInterface::CONTEXT_STORE, - $currentStore->getCode(), + $store->getCode(), $this->storeManager->getDefaultStoreView()->getCode() ); + /** @var StoreInterface $defaultStore */ + $defaultStore = $this->storeManager->getWebsite()->getDefaultStore(); $this->httpContext->setValue( HttpContext::CONTEXT_CURRENCY, - $this->session->getCurrencyCode() ?: $currentStore->getDefaultCurrencyCode(), + $this->session->getCurrencyCode() + ?: $store->getDefaultCurrencyCode(), $defaultStore->getDefaultCurrencyCode() ); } + + /** + * Check if there a need to find the current store. + * + * @return bool + */ + private function isAlreadySet(): bool + { + $storeKey = StoreManagerInterface::CONTEXT_STORE; + + return $this->httpContext->getValue($storeKey) !== null; + } } diff --git a/app/code/Magento/Store/App/Request/PathInfoProcessor.php b/app/code/Magento/Store/App/Request/PathInfoProcessor.php index ebea50588f9e5..3fa78dc94aa35 100644 --- a/app/code/Magento/Store/App/Request/PathInfoProcessor.php +++ b/app/code/Magento/Store/App/Request/PathInfoProcessor.php @@ -6,6 +6,7 @@ namespace Magento\Store\App\Request; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Store\Model\Store; class PathInfoProcessor implements \Magento\Framework\App\Request\PathInfoProcessorInterface { @@ -42,8 +43,8 @@ public function process(\Magento\Framework\App\RequestInterface $request, $pathI } if ($store->isUseStoreInUrl()) { - if (!$request->isDirectAccessFrontendName($storeCode)) { - $this->storeManager->setCurrentStore($storeCode); + if (!$request->isDirectAccessFrontendName($storeCode) && $storeCode != Store::ADMIN_CODE) { + $this->storeManager->setCurrentStore($store->getCode()); $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : ''); return $pathInfo; } elseif (!empty($storeCode)) { diff --git a/app/code/Magento/Store/Block/Switcher.php b/app/code/Magento/Store/Block/Switcher.php index 074dcb0262040..3d8d46983b5aa 100644 --- a/app/code/Magento/Store/Block/Switcher.php +++ b/app/code/Magento/Store/Block/Switcher.php @@ -223,9 +223,12 @@ public function getStoreName() */ public function getTargetStorePostData(\Magento\Store\Model\Store $store, $data = []) { - $data[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME] = $store->getCode(); + $data[\Magento\Store\Api\StoreResolverInterface::PARAM_NAME] + = $store->getCode(); + //We need to fromStore as true because it will enable proper URL + //rewriting during store switching. return $this->_postDataHelper->getPostData( - $store->getCurrentUrl(false), + $store->getCurrentUrl(true), $data ); } diff --git a/app/code/Magento/Store/Model/Address/Renderer.php b/app/code/Magento/Store/Model/Address/Renderer.php index 1f44b9dcec3e3..1d0fdd7284848 100644 --- a/app/code/Magento/Store/Model/Address/Renderer.php +++ b/app/code/Magento/Store/Model/Address/Renderer.php @@ -15,6 +15,12 @@ */ class Renderer { + const DEFAULT_TEMPLATE = "{{var name}}\n" . + "{{var street_line1}}\n" . + "{{depend street_line2}}{{var street_line2}}\n{{/depend}}" . + "{{depend city}}{{var city}},{{/depend}} {{var region}} {{depend postcode}}{{var postcode}},{{/depend}}\n" . + "{{var country}}"; + /** * @var EventManager */ @@ -25,18 +31,26 @@ class Renderer */ protected $filterManager; + /** + * @var string + */ + private $template; + /** * Constructor * * @param EventManager $eventManager * @param FilterManager $filterManager + * @param string $template */ public function __construct( EventManager $eventManager, - FilterManager $filterManager + FilterManager $filterManager, + $template = self::DEFAULT_TEMPLATE ) { $this->eventManager = $eventManager; $this->filterManager = $filterManager; + $this->template = $template; } /** @@ -50,9 +64,7 @@ public function format(DataObject $storeInfo, $type = 'html') { $this->eventManager->dispatch('store_address_format', ['type' => $type, 'store_info' => $storeInfo]); $address = $this->filterManager->template( - "{{var name}}\n{{var street_line1}}\n{{depend street_line2}}{{var street_line2}}\n{{/depend}}" . - "{{depend city}}{{var city}},{{/depend}} {{var region}} {{depend postcode}}{{var postcode}},{{/depend}}\n" . - "{{var country}}", + $this->template, ['variables' => $storeInfo->getData()] ); diff --git a/app/code/Magento/Store/Model/Config/Placeholder.php b/app/code/Magento/Store/Model/Config/Placeholder.php index b08e58c59c1a7..4e4139d47bd92 100644 --- a/app/code/Magento/Store/Model/Config/Placeholder.php +++ b/app/code/Magento/Store/Model/Config/Placeholder.php @@ -91,8 +91,9 @@ protected function _processPlaceholders($value, $data) if ($url) { $value = str_replace('{{' . $placeholder . '}}', $url, $value); } elseif (strpos($value, $this->urlPlaceholder) !== false) { - // localhost is replaced for cli requests, for http requests method getDistroBaseUrl is used - $value = str_replace($this->urlPlaceholder, 'http://localhost/', $value); + $distroBaseUrl = $this->request->getDistroBaseUrl(); + + $value = str_replace($this->urlPlaceholder, $distroBaseUrl, $value); } if (null !== $this->_getPlaceholder($value)) { diff --git a/app/code/Magento/Store/Model/ResourceModel/Website.php b/app/code/Magento/Store/Model/ResourceModel/Website.php index 4359f89e0639a..0b77dfb09e80b 100644 --- a/app/code/Magento/Store/Model/ResourceModel/Website.php +++ b/app/code/Magento/Store/Model/ResourceModel/Website.php @@ -53,7 +53,7 @@ public function readAllWebsites() ->select() ->from($this->getTable('store_website')); - foreach($this->getConnection()->fetchAll($select) as $websiteData) { + foreach ($this->getConnection()->fetchAll($select) as $websiteData) { $websites[$websiteData['code']] = $websiteData; } @@ -69,7 +69,7 @@ public function readAllWebsites() */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { - if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) { + if (!preg_match('/^[a-z]+[a-z0-9_]*$/i', $object->getCode())) { throw new \Magento\Framework\Exception\LocalizedException( __( 'Website code may only contain letters (a-z), numbers (0-9) or underscore (_),' diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index 1d100da274465..56751f2188411 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -12,10 +12,10 @@ use Magento\Framework\App\Http\Context; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\ScopeInterface as AppScopeInterface; -use Magento\Framework\Filesystem; use Magento\Framework\DataObject\IdentityInterface; -use Magento\Framework\Url\ScopeInterface as UrlScopeInterface; +use Magento\Framework\Filesystem; use Magento\Framework\Model\AbstractExtensibleModel; +use Magento\Framework\Url\ScopeInterface as UrlScopeInterface; use Magento\Framework\UrlInterface; use Magento\Store\Api\Data\StoreInterface; @@ -463,7 +463,7 @@ protected function _getValidationRulesBeforeSave() $storeLabelRule->setMessage(__('Name is required'), \Zend_Validate_NotEmpty::IS_EMPTY); $validator->addRule($storeLabelRule, 'name'); - $storeCodeRule = new \Zend_Validate_Regex('/^[a-z]+[a-z0-9_]*$/'); + $storeCodeRule = new \Zend_Validate_Regex('/^[a-z]+[a-z0-9_]*$/i'); $storeCodeRule->setMessage( __( 'The store code may contain only letters (a-z), numbers (0-9) or underscore (_),' @@ -1136,7 +1136,14 @@ public function isDefault() public function getCurrentUrl($fromStore = true) { $sidQueryParam = $this->_sidResolver->getSessionIdQueryParam($this->_getSession()); - $requestString = $this->_url->escape(ltrim($this->_request->getRequestString(), '/')); + /** @var string $requestString Request path without query parameters */ + $requestString = $this->_url->escape( + preg_replace( + '/\?.*?$/', + '', + ltrim($this->_request->getRequestString(), '/') + ) + ); $storeUrl = $this->getUrl('', ['_secure' => $this->_storeManager->getStore()->isCurrentlySecure()]); @@ -1166,18 +1173,29 @@ public function getCurrentUrl($fromStore = true) if (!$this->isUseStoreInUrl()) { $storeParsedQuery['___store'] = $this->getCode(); } + if ($fromStore !== false) { $storeParsedQuery['___from_store'] = $fromStore === true ? $this->_storeManager->getStore()->getCode() : $fromStore; } + $requestStringParts = explode('?', $requestString, 2); + $requestStringPath = $requestStringParts[0]; + if (isset($requestStringParts[1])) { + parse_str($requestStringParts[1], $requestString); + } else { + $requestString = []; + } + + $currentUrlQueryParams = array_merge($requestString, $storeParsedQuery); + $currentUrl = $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') . $storeParsedUrl['path'] - . $requestString - . ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : ''); + . $requestStringPath + . ($currentUrlQueryParams ? '?' . http_build_query($currentUrlQueryParams, '', '&') : ''); return $currentUrl; } diff --git a/app/code/Magento/Store/Model/StoreManagerInterface.php b/app/code/Magento/Store/Model/StoreManagerInterface.php index 84e498851ec32..220155c47f6df 100644 --- a/app/code/Magento/Store/Model/StoreManagerInterface.php +++ b/app/code/Magento/Store/Model/StoreManagerInterface.php @@ -6,6 +6,8 @@ namespace Magento\Store\Model; +use Magento\Framework\Exception\NoSuchEntityException; + /** * Store manager interface * @@ -46,6 +48,7 @@ public function isSingleStoreMode(); * * @param null|string|bool|int|\Magento\Store\Api\Data\StoreInterface $storeId * @return \Magento\Store\Api\Data\StoreInterface + * @throws NoSuchEntityException If given store doesn't exist. */ public function getStore($storeId = null); diff --git a/app/code/Magento/Store/Setup/InstallSchema.php b/app/code/Magento/Store/Setup/InstallSchema.php index f6cdfb6fcba71..69b3f86ebdd7b 100644 --- a/app/code/Magento/Store/Setup/InstallSchema.php +++ b/app/code/Magento/Store/Setup/InstallSchema.php @@ -270,7 +270,13 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con */ $connection->insertForce( $installer->getTable('store_group'), - ['group_id' => 0, 'website_id' => 0, 'name' => 'Default', 'root_category_id' => 0, 'default_store_id' => 0] + [ + 'group_id' => 0, + 'website_id' => 0, + 'name' => 'Default', + 'root_category_id' => 0, + 'default_store_id' => 0 + ] ); $connection->insertForce( $installer->getTable('store_group'), diff --git a/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php b/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php index d44724fe302d0..615542a852e34 100644 --- a/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php @@ -8,8 +8,10 @@ use Magento\Framework\App\Action\AbstractAction; use Magento\Framework\App\Http\Context; use Magento\Framework\App\RequestInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Model\StoreManagerInterface; +use Magento\Framework\App\Http\Context as HttpContext; /** * Class ContextPluginTest @@ -33,7 +35,7 @@ class ContextTest extends \PHPUnit\Framework\TestCase protected $sessionMock; /** - * @var \Magento\Framework\App\Http\Context|\PHPUnit_Framework_MockObject_MockObject + * @var HttpContext|\PHPUnit_Framework_MockObject_MockObject */ protected $httpContextMock; @@ -78,7 +80,11 @@ class ContextTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->sessionMock = $this->createPartialMock(\Magento\Framework\Session\Generic::class, ['getCurrencyCode']); - $this->httpContextMock = $this->createMock(\Magento\Framework\App\Http\Context::class); + $this->httpContextMock = $this->createMock(HttpContext::class); + $this->httpContextMock->expects($this->once()) + ->method('getValue') + ->with(StoreManagerInterface::CONTEXT_STORE) + ->willReturn(null); $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); $this->storeCookieManager = $this->createMock(\Magento\Store\Api\StoreCookieManagerInterface::class); $this->storeMock = $this->createMock(\Magento\Store\Model\Store::class); @@ -98,19 +104,12 @@ protected function setUp() 'session' => $this->sessionMock, 'httpContext' => $this->httpContextMock, 'storeManager' => $this->storeManager, - 'storeCookieManager' => $this->storeCookieManager, + 'storeCookieManager' => $this->storeCookieManager ] ); - $this->storeManager->expects($this->once()) - ->method('getWebsite') - ->will($this->returnValue($this->websiteMock)); + $this->storeManager->method('getDefaultStoreView') ->willReturn($this->storeMock); - - $this->websiteMock->expects($this->once()) - ->method('getDefaultStore') - ->will($this->returnValue($this->storeMock)); - $this->storeCookieManager->expects($this->once()) ->method('getStoreCodeFromCookie') ->will($this->returnValue('storeCookie')); @@ -121,6 +120,13 @@ protected function setUp() public function testBeforeDispatchCurrencyFromSession() { + $this->storeManager->expects($this->once()) + ->method('getWebsite') + ->will($this->returnValue($this->websiteMock)); + $this->websiteMock->expects($this->once()) + ->method('getDefaultStore') + ->will($this->returnValue($this->storeMock)); + $this->storeMock->expects($this->once()) ->method('getDefaultCurrencyCode') ->will($this->returnValue(self::CURRENCY_DEFAULT)); @@ -145,19 +151,37 @@ public function testBeforeDispatchCurrencyFromSession() ->method('getCurrencyCode') ->will($this->returnValue(self::CURRENCY_SESSION)); - $this->httpContextMock->expects($this->at(0)) - ->method('setValue') - ->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default'); - /** Make sure that current currency is taken from session if available */ $this->httpContextMock->expects($this->at(1)) ->method('setValue') - ->with(Context::CONTEXT_CURRENCY, self::CURRENCY_SESSION, self::CURRENCY_DEFAULT); - - $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock); + ->with( + StoreManagerInterface::CONTEXT_STORE, + 'custom_store', + 'default' + ); + // Make sure that current currency is taken from session if available. + $this->httpContextMock->expects($this->at(2)) + ->method('setValue') + ->with( + Context::CONTEXT_CURRENCY, + self::CURRENCY_SESSION, + self::CURRENCY_DEFAULT + ); + + $this->plugin->beforeDispatch( + $this->subjectMock, + $this->requestMock + ); } public function testDispatchCurrentStoreCurrency() { + $this->storeManager->expects($this->once()) + ->method('getWebsite') + ->will($this->returnValue($this->websiteMock)); + $this->websiteMock->expects($this->once()) + ->method('getDefaultStore') + ->will($this->returnValue($this->storeMock)); + $this->storeMock->expects($this->once()) ->method('getDefaultCurrencyCode') ->will($this->returnValue(self::CURRENCY_DEFAULT)); @@ -178,19 +202,38 @@ public function testDispatchCurrentStoreCurrency() ->with('default') ->willReturn($this->currentStoreMock); - $this->httpContextMock->expects($this->at(0)) - ->method('setValue') - ->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default'); - /** Make sure that current currency is taken from current store if no value is provided in session */ $this->httpContextMock->expects($this->at(1)) ->method('setValue') - ->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT); - - $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock); + ->with( + StoreManagerInterface::CONTEXT_STORE, + 'custom_store', + 'default' + ); + // Make sure that current currency is taken from current store + //if no value is provided in session. + $this->httpContextMock->expects($this->at(2)) + ->method('setValue') + ->with( + Context::CONTEXT_CURRENCY, + self::CURRENCY_CURRENT_STORE, + self::CURRENCY_DEFAULT + ); + + $this->plugin->beforeDispatch( + $this->subjectMock, + $this->requestMock + ); } public function testDispatchStoreParameterIsArray() { + $this->storeManager->expects($this->once()) + ->method('getWebsite') + ->will($this->returnValue($this->websiteMock)); + $this->websiteMock->expects($this->once()) + ->method('getDefaultStore') + ->will($this->returnValue($this->storeMock)); + $this->storeMock->expects($this->once()) ->method('getDefaultCurrencyCode') ->will($this->returnValue(self::CURRENCY_DEFAULT)); @@ -218,28 +261,45 @@ public function testDispatchStoreParameterIsArray() ->with('500') ->willReturn($this->currentStoreMock); - $this->httpContextMock->expects($this->at(0)) - ->method('setValue') - ->with(StoreManagerInterface::CONTEXT_STORE, 'custom_store', 'default'); - /** Make sure that current currency is taken from current store if no value is provided in session */ $this->httpContextMock->expects($this->at(1)) ->method('setValue') - ->with(Context::CONTEXT_CURRENCY, self::CURRENCY_CURRENT_STORE, self::CURRENCY_DEFAULT); - - $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock); + ->with( + StoreManagerInterface::CONTEXT_STORE, + 'custom_store', + 'default' + ); + //Make sure that current currency is taken from current store + //if no value is provided in session. + $this->httpContextMock->expects($this->at(2)) + ->method('setValue') + ->with( + Context::CONTEXT_CURRENCY, + self::CURRENCY_CURRENT_STORE, + self::CURRENCY_DEFAULT + ); + + $this->plugin->beforeDispatch( + $this->subjectMock, + $this->requestMock + ); } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid store parameter. + * @expectedException \Magento\Framework\Exception\NotFoundException */ public function testDispatchStoreParameterIsInvalidArray() { - $this->storeMock->expects($this->never()) + $this->storeManager->expects($this->once()) + ->method('getWebsite') + ->will($this->returnValue($this->websiteMock)); + $this->websiteMock->expects($this->once()) + ->method('getDefaultStore') + ->will($this->returnValue($this->storeMock)); + $this->storeMock->expects($this->exactly(2)) ->method('getDefaultCurrencyCode') ->will($this->returnValue(self::CURRENCY_DEFAULT)); - $this->storeMock->expects($this->never()) + $this->storeMock->expects($this->exactly(2)) ->method('getCode') ->willReturn('default'); $this->currentStoreMock->expects($this->never()) @@ -256,6 +316,51 @@ public function testDispatchStoreParameterIsInvalidArray() ->method('getParam') ->with($this->equalTo('___store')) ->will($this->returnValue($store)); + $this->storeManager->expects($this->once()) + ->method('getStore') + ->with() + ->willReturn($this->storeMock); + $this->plugin->beforeDispatch( + $this->subjectMock, + $this->requestMock + ); + } + + /** + * @expectedException \Magento\Framework\Exception\NotFoundException + */ + public function testDispatchNonExistingStore() + { + $storeId = 'NonExisting'; + $this->requestMock->expects($this->once()) + ->method('getParam') + ->with('___store') + ->willReturn($storeId); + $this->storeManager->expects($this->at(0)) + ->method('getStore') + ->with($storeId) + ->willThrowException(new NoSuchEntityException()); + $this->storeManager->expects($this->at(1)) + ->method('getStore') + ->with() + ->willReturn($this->storeMock); + $this->storeManager->expects($this->once()) + ->method('getWebsite') + ->will($this->returnValue($this->websiteMock)); + $this->websiteMock->expects($this->once()) + ->method('getDefaultStore') + ->will($this->returnValue($this->storeMock)); + $this->storeMock->expects($this->exactly(2)) + ->method('getDefaultCurrencyCode') + ->will($this->returnValue(self::CURRENCY_DEFAULT)); + + $this->storeMock->expects($this->exactly(2)) + ->method('getCode') + ->willReturn('default'); + $this->currentStoreMock->expects($this->never()) + ->method('getCode') + ->willReturn('custom_store'); + $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock); } } diff --git a/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php b/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php index f2bd401cea3fb..7d2fb54014967 100644 --- a/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Request/PathInfoProcessorTest.php @@ -47,6 +47,7 @@ public function testProcessIfStoreExistsAndIsNotDirectAcccessToFrontName() )->with( 'storeCode' )->willReturn($store); + $store->expects($this->once())->method('getCode')->will($this->returnValue('storeCode')); $store->expects($this->once())->method('isUseStoreInUrl')->will($this->returnValue(true)); $this->_requestMock->expects( $this->once() diff --git a/app/code/Magento/Store/Test/Unit/Block/SwitcherTest.php b/app/code/Magento/Store/Test/Unit/Block/SwitcherTest.php index 5f0ba6c0b42d3..8b4799d2b3437 100644 --- a/app/code/Magento/Store/Test/Unit/Block/SwitcherTest.php +++ b/app/code/Magento/Store/Test/Unit/Block/SwitcherTest.php @@ -53,7 +53,7 @@ public function testGetTargetStorePostData() $storeSwitchUrl = 'http://domain.com/stores/store/switch'; $store->expects($this->atLeastOnce()) ->method('getCurrentUrl') - ->with(false) + ->with(true) ->willReturn($storeSwitchUrl); $this->corePostDataHelper->expects($this->any()) ->method('getPostData') diff --git a/app/code/Magento/Store/Test/Unit/Model/Config/PlaceholderTest.php b/app/code/Magento/Store/Test/Unit/Model/Config/PlaceholderTest.php index fd42be4cb8f6c..e44eacc79b82f 100644 --- a/app/code/Magento/Store/Test/Unit/Model/Config/PlaceholderTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/Config/PlaceholderTest.php @@ -23,7 +23,7 @@ protected function setUp() { $this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class); $this->_requestMock->expects( - $this->any() + $this->once() )->method( 'getDistroBaseUrl' )->will( diff --git a/app/code/Magento/Store/Test/Unit/Model/StoreTest.php b/app/code/Magento/Store/Test/Unit/Model/StoreTest.php index aef54a47971ff..c05584c2d8bcb 100644 --- a/app/code/Magento/Store/Test/Unit/Model/StoreTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/StoreTest.php @@ -370,10 +370,11 @@ public function testGetBaseUrlWrongType() * @param boolean $secure * @param string $url * @param string $expected + * @param bool|string $fromStore */ - public function testGetCurrentUrl($secure, $url, $expected) + public function testGetCurrentUrl($secure, $url, $expected, $fromStore) { - $defaultStore = $this->createPartialMock(\Magento\Store\Model\Store::class, [ + $defaultStore = $this->createPartialMock(Store::class, [ 'getId', 'isCurrentlySecure', '__wakeup' @@ -386,15 +387,31 @@ public function testGetCurrentUrl($secure, $url, $expected) $config = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ReinitableConfigInterface::class); - $this->requestMock->expects($this->atLeastOnce())->method('getRequestString')->will($this->returnValue('')); + $requestString = preg_replace( + '/http(s?)\:\/\/[a-z0-9\-]+\//i', + '', + $url + ); + $this->requestMock + ->expects($this->atLeastOnce()) + ->method('getRequestString') + ->willReturn($requestString); $this->requestMock->expects($this->atLeastOnce())->method('getQueryValue')->will($this->returnValue([ 'SID' => 'sid' ])); $urlMock = $this->getMockForAbstractClass(\Magento\Framework\UrlInterface::class); - $urlMock->expects($this->atLeastOnce())->method('setScope')->will($this->returnSelf()); - $urlMock->expects($this->any())->method('getUrl') - ->will($this->returnValue($url)); + $urlMock + ->expects($this->atLeastOnce()) + ->method('setScope') + ->will($this->returnSelf()); + $urlMock->expects($this->any()) + ->method('getUrl') + ->will($this->returnValue(str_replace($requestString, '', $url))); + $urlMock + ->expects($this->atLeastOnce()) + ->method('escape') + ->willReturnArgument(0); $storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class); $storeManager->expects($this->any()) @@ -409,7 +426,7 @@ public function testGetCurrentUrl($secure, $url, $expected) $model->setStoreId(2); $model->setCode('scope_code'); - $this->assertEquals($expected, $model->getCurrentUrl(false)); + $this->assertEquals($expected, $model->getCurrentUrl($fromStore)); } /** @@ -418,9 +435,31 @@ public function testGetCurrentUrl($secure, $url, $expected) public function getCurrentUrlDataProvider() { return [ - [true, 'http://test/url', 'http://test/url?SID=sid&___store=scope_code'], - [true, 'http://test/url?SID=sid1&___store=scope', 'http://test/url?SID=sid&___store=scope_code'], - [false, 'https://test/url', 'https://test/url?SID=sid&___store=scope_code'] + [ + true, + 'http://test/url', + 'http://test/url?SID=sid&___store=scope_code', + false + ], + [ + true, + 'http://test/url?SID=sid1&___store=scope', + 'http://test/url?SID=sid&___store=scope_code', + false + ], + [ + false, + 'https://test/url', + 'https://test/url?SID=sid&___store=scope_code', + false + ], + [ + true, + 'http://test/u/u.2?__store=scope_code', + 'http://test/u/u.2?' + . 'SID=sid&___store=scope_code&___from_store=old-store', + 'old-store' + ] ]; } diff --git a/app/code/Magento/Store/composer.json b/app/code/Magento/Store/composer.json index 08166068b743b..b3bbb680bcd78 100644 --- a/app/code/Magento/Store/composer.json +++ b/app/code/Magento/Store/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-catalog": "101.1.*", + "magento/module-catalog": "102.0.*", "magento/module-directory": "100.2.*", - "magento/module-ui": "100.2.*", - "magento/module-config": "100.2.*", + "magento/module-ui": "101.0.*", + "magento/module-config": "101.0.*", "magento/module-media-storage": "100.2.*", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "suggest": { "magento/module-deploy": "100.2.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.2", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Store/etc/config.xml b/app/code/Magento/Store/etc/config.xml index 470337a97dcd9..bb5b23620df4b 100644 --- a/app/code/Magento/Store/etc/config.xml +++ b/app/code/Magento/Store/etc/config.xml @@ -115,6 +115,10 @@ php + php3 + php4 + php5 + php7 htaccess jsp pl diff --git a/app/code/Magento/Store/etc/frontend/di.xml b/app/code/Magento/Store/etc/frontend/di.xml index fd42a0367aa93..c39d5df863939 100644 --- a/app/code/Magento/Store/etc/frontend/di.xml +++ b/app/code/Magento/Store/etc/frontend/di.xml @@ -18,7 +18,7 @@ Magento\Framework\App\Router\Base false - 20 + 30 Magento\Framework\App\Router\DefaultRouter diff --git a/app/code/Magento/Swagger/Block/Index.php b/app/code/Magento/Swagger/Block/Index.php new file mode 100644 index 0000000000000..afa642bfb905c --- /dev/null +++ b/app/code/Magento/Swagger/Block/Index.php @@ -0,0 +1,32 @@ +getRequest()->getParam('store') ?: 'all'; + } + + /** + * @return string + */ + public function getSchemaUrl() + { + return rtrim($this->getBaseUrl(), '/') . '/rest/' . $this->getParamStore() . '/schema?services=all'; + } +} diff --git a/app/code/Magento/Swagger/composer.json b/app/code/Magento/Swagger/composer.json index c49e3e6bffb6f..787d58891c9e0 100644 --- a/app/code/Magento/Swagger/composer.json +++ b/app/code/Magento/Swagger/composer.json @@ -3,10 +3,10 @@ "description": "N/A", "require": { "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/framework": "100.2.*" + "magento/framework": "101.0.*" }, "type": "magento2-module", - "version": "100.2.0-dev", + "version": "100.2.1", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml b/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml index a28b01ac8df69..f6dbd1592cb63 100644 --- a/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml +++ b/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml @@ -10,32 +10,18 @@ Swagger UI - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + @@ -43,9 +29,10 @@ + - + diff --git a/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml b/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml index 79040081f115d..b20da68734579 100644 --- a/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml +++ b/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml @@ -12,11 +12,48 @@ * Modified by Magento, Modifications Copyright © Magento, Inc. All rights reserved. */ -/** @var \Magento\Framework\View\Element\Template $block */ +/** @var \Magento\Swagger\Block\Index $block + * + * @codingStandardsIgnoreFile + */ -$schemaUrl = rtrim($block->getBaseUrl(), '/') . '/rest/all/schema?services=all'; +$schemaUrl = $block->getSchemaUrl(); ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +