Jump to content

Get current checkout step into (checkout-process.tpl file)


Recommended Posts

I added a progress bar to show checkout steps.
The bar has been added into "checkout-process.tpl" just before this foreach loop.

{foreach from=$steps item="step" key="index"}
  {render identifier  =  $step.identifier
          position    =  ($index + 1)
          ui          =  $step.ui
  }
{/foreach}

This is the html code:

<ol id="progress-bar">
  <li class="step-done">Personal info</li>
  <li class="step-done">Address</li>
  <li class="step-active">Shipping</li>
  <li class="step-to-do">Payment</li>
</ol>

Do you now how can I get current checkout step?
I need it to add "step-" classes based on the step.

Link to comment
Share on other sites

I tried using something like this script but it not working properly, in particular when the checkout skip some steps because already completed.
Instead of using on click funcion I also tried MutationObserver but I got the same result.

$(document).ready(function() {
$("body").click(function() {
	if ($("#checkout-delivery-step").hasClass("-complete")) {
      $("#bar-step1").removeClass().addClass("step-done");
	  $("#bar-step2").removeClass().addClass("step-done");
	  $("#bar-step3").removeClass().addClass("step-done");
	  $("#bar-step4").removeClass().addClass("step-active");
    } else if ($("#checkout-delivery-step").hasClass("-current")) {
      $("#bar-step1").removeClass().addClass("step-done");
	  $("#bar-step2").removeClass().addClass("step-done");
	  $("#bar-step3").removeClass().addClass("step-active");
	  $("#bar-step4").removeClass().addClass("step-todo");
    } else if ($("#checkout-addresses-step").hasClass("-current")) {
      $("#bar-step1").removeClass().addClass("step-done");
	  $("#bar-step2").removeClass().addClass("step-active");
	  $("#bar-step3").removeClass().addClass("step-todo");
	  $("#bar-step4").removeClass().addClass("step-todo");
    } else if ($("#checkout-personal-information-step").hasClass("-current")) {
      $("#bar-step1").removeClass().addClass("step-active");
	  $("#bar-step2").removeClass().addClass("step-todo");
	  $("#bar-step3").removeClass().addClass("step-todo");
	  $("#bar-step4").removeClass().addClass("step-todo");
    }
  });
});

 

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 1 month later...

Hello @Ali Samie, i'm in the same position as you were but i can't find my way in this problem. Do you have a working example of what you achieved to do ? I need a multi step checkout with step above the content and the ability to move from one step to another but I can't make it work !


Same question for you @DARKF3D3, did you manage to find a way to do what you wanted to do ? I would love to have some example.


Thanks for your help.

Edited by Lucas.S (see edit history)
Link to comment
Share on other sites

11 minutes ago, Ali Samie said:

@Lucas.S just use this line in your templates

Context::getContext()->controller->getCheckoutProcess()

then you have access to all steps and their properties. you can then create buttons for next and previous steps

Thanks for your reply @Ali Samie, I tried it but the steps object is private and I it seems that I can't access them easily. Maybe I can use them, but I don't know how ?

Link to comment
Share on other sites

7 minutes ago, Lucas.S said:

Thanks for your reply @Ali Samie, I tried it but the steps object is private and I it seems that I can't access them easily. Maybe I can use them, but I don't know how ?

this is my template for the checkout page at this path

mytheme/templates/checkout/_partials/header.tpl

{block name='header_nav'}
  <nav class="header-nav">
    <div class="container">
      <div class="checkout-header">
        <div class="hidden-sm-down" id="_desktop_logo">
          {renderLogo}
        </div>
        <div class="hidden-md-up text-sm-center mobile">
          <div class="top-logo" id="_mobile_logo"></div>
        </div>
        <div class="checkout-progress">
          {foreach Context::getContext()->controller->getCheckoutProcess()->getSteps() as $index => $step}
            <div class="{[
                        'checkout-progress-step'   => true,
                        '-current'        => $step->isCurrent(),
                        '-reachable'      => $step->isReachable(),
                        '-complete'       => $step->isComplete(),
                        'js-current-step' => $step->isCurrent()
                    ]|classnames}"
              data-index="{$index+1}"
              data-id-checkout-step="{$step->getIdentifier()}" 
              >
              <h1 class="step-title js-step-title">
                {$step->getTitle()}
              </h1>
            </div>
          {/foreach}
        </div>
      </div>
    </div>
  </nav>
{/block}

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...