Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Checkout
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
2 Nov 2016 at 13:51 UTC
Updated:
30 Mar 2017 at 13:04 UTC
Jump to comment: Most recent
The checkout process lacks some access checks. Let's copy commerce 1.x behavior.
What we have in 2.x:
Drupal\commerce_checkout\Controller\CheckoutController::checkAccess()
All of the above is in 1.x (see commerce_checkout_access() and commerce_checkout_router(). Additional checks in 1.x:
commerce_checkout_page_access(). commerce_checkout_page_access(). commerce_checkout_page_access().All these missing checks can go to Drupal\commerce_checkout\Controller\CheckoutController::checkAccess().
Comments
Comment #2
czigor commentedComment #3
bojanz commentedThanks! This is way more important than "normal".
Comment #4
czigor commentedI'm working on this.
Comment #5
czigor commentedThat's where I am right now: https://github.com/czigor/commerce/commit/5edbfd3cf8860ce41a310274a31d4e...
I got stuck in the test when trying to get the checkout_flow belonging to an order (which I need in line 179). Any help would be appreciated.
Comment #6
bojanz commented$order->checkout_flow is an entity reference, you should be able to use that.
Comment #7
czigor commentedYes, that's what I thought, but
does not seem to work for me (Fatal error: Call to undefined method Drupal\Core\Field\EntityReferenceFieldItemList::getPlugin()) . Weirdly,
returns an order entity. I get this behaviour in devel/php for any order, regardless whether the order is in checkout or completed, whether the order was created on the UI or from code (based on CheckoutOrderTest::testOrderAccess()). The code I use in devel/php is:
Am I missing something or could this be a commerce bug?
Comment #8
bojanz commentedJust general entity_reference unpleasantness :)
$order->checkout_flow->entity->getPlugin()->getNextStepId()
(->entity is not the same as ->getEntity() which just returns the parent entity. DX++)
Comment #9
czigor commentedThanks for the hints! In the end the main problem was that I was trying to access checkoutFlow steps outside the checkout, which is not possible.
Here are my PRs:
https://github.com/drupalcommerce/commerce/pull/551 (only tests, should fail)
https://github.com/drupalcommerce/commerce/pull/550
(Is this the recommended way to do tests?)
Comment #10
steveoliver commentedSo close! Commented on the PR here -- https://github.com/drupalcommerce/commerce/pull/550#pullrequestreview-20.... Just need to add a store to the order under test.
Comment #11
czigor commentedRebased the PR, tests are green now.
Comment #12
czigor commentedThey are not green.
Comment #13
bojanz commentedMy turn.
Comment #15
bojanz commentedProblems I had with the PR:
1) CheckoutFlowBase still had its own step ID handling, which duplicated the controller logic.
2) The controller logic couldn't be reused, made more sense on a service such as CheckoutOrderManager
3) The logic didn't account for "allow access to a previously completed step".
4) Tests were failing due to the hacky way CheckoutFlowBase was assigning the step at __construct(), which was too early and magical.
Many rewrites later, the final commit has been pushed.
We now have a single source of the checkout step, and plenty of new tests.