3

I am new in magento. I want to have terms and condition checkbox on cart page where proceed to checkout button is there. I have enabled terms and condition but it is on the last of the all process. So, can we have in starting or in cart page.

  • are you want this on checkout page or cart page? – Amit Bera Nov 25 '14 at 5:03
  • on cart page @AmitBera – Kishor Nov 25 '14 at 6:53
  • I am trying to do it on first step checkout page. Hopefully it will work for me @AmitBera – Kishor Nov 25 '14 at 6:57
16

If you're new to Magento, this answer likely will not make sense. So either get an experienced Magento developer on this or start brushing up. With that, here's what you can try.

Prerequisites

Ensure that you have defined terms in Magento under Sales > Terms and conditions Ensure that you have terms enabled in System Configuration > Sales > Checkout > Checkout Options > Enable Terms and Conditions

And please note, these instructions may vary greatly depending on your version of Magento/checkout extension in use, and where you actually want to display the agreements. This will show you how to work it out on a stock CE installation.

How Agreements are Rendered

See app/design/frontend/base/default/layout/checkout.xml:

...
<checkout_onepage_review translate="label">
    ...
    <block type="checkout/agreements" name="checkout.onepage.agreements" as="agreements" template="checkout/onepage/agreements.phtml"/>
    ...
</checkout_onepage_review>
...

The middle line tells Magento that the layout on the review step will contain a checkout/agreements block named checkout.onepage.agreements. It also sets up the template there.

So when the checkout reaches the review step, this file comes into play.

app/design/frontend/base/default/template/checkout/onepage/review/info.phtml:

...
<div id="checkout-review-submit">
    <?php echo $this->getChildHtml('agreements') ?>
    <div class="buttons-set" id="review-buttons-container">
...

And that 2nd line is asking to render the block we defined in the layout XML above.

How to Require Agreements at Checkout Step 1

If you've followed me so far, then you can infer to start by moving/copying the layout XML block node (checkout.onepage.agreements) into another area (called a 'layout handle') of the same file. Find the layout handle checkout_onepage_index, and get to its child block named checkout.onepage.billing or whatever block you want to display the agreements. Extend it by adding that agreements XML, so that it looks like this:

...
<checkout_onepage_index translate="label">
    ...
    <block type="checkout/onepage_billing" name="checkout.onepage.billing" as="billing" template="checkout/onepage/billing.phtml">
        <block type="checkout/agreements" name="checkout.onepage.agreements" as="agreements" template="checkout/onepage/agreements.phtml"/>
    </block>
    ...
</checkout_onepage_index>
...

Now we're ready to call and render that block from within the billing step's template. Open that up, get to the place where you want the agreements to appear, and add this line:

<?php echo $this->getChildHtml('agreements') ?>

If you clear your cache and get to the checkout, you should see the agreements appear. That handles rendering, now we have to tie that into validation.

How to Validate Agreements

Because this is normally done at the end of the checkout, we can figure out how it works by examing the checkout's main controller:

app/code/core/Mage/Checkout/controllers/OnepageController.php::saveOrderAction:

public function saveOrderAction()
{
    ...
    if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) {
        $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
        if ($diff = array_diff($requiredAgreements, $postedAgreements)) {
            $result['success'] = false;
            $result['error'] = true;
            $result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.');
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
            return;
        }
    }
    ...

You will essentially copy this condition into the top of the saveBillingAction method, like so:

...
public function saveBillingAction()
{
    ...
    if ($this->getRequest()->isPost()) {

        if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) {
            $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
            if ($diff = array_diff($requiredAgreements, $postedAgreements)) {
                $result['success'] = false;
                $result['error'] = true;
                $result['message'] = $this->__('Please agree to all the terms and conditions before placing the order.');
                $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
                return;
            }
        } 
    ...

Notice a key difference here. The $result['error_messages'] was changed to $result['message']. This is done because, unfortunately for the stock checkout, its JavaScript is inconsistent in implementation. So while the order review step will check for error_messages, the billing step looks for messages on the result.


Now that you've displayed your agreements, and wired them up to the controller, you should be able to test this step out. If you don't check the agreements, and continue to the next step, you would get an alert box that says, "Please agree to all the terms and conditions before placing the order."

A long-winded answer, but also very necessary if you have no idea where to begin. Hopefully this helps.

  • My question diff form this post, How can i set condition like selected zip code ares free shipping, currently i am using Webshop matrix as a shipping method option, free shipping working, how can i implement my specific condition like selected zipcode free shipping, in shopping cart pricing rule not working, so how can i write condition in checkout page. @Rick – zus Oct 1 '18 at 5:11
  • Post :: magento.stackexchange.com/q/224918/57334 – zus Oct 1 '18 at 5:13
5

To enable the terms and conditions check box at checkout, follow the below steps:

  1. In the admin panel, go to System > Configuration > Sales > Checkout > Checkout Options and set Enable Terms and Conditions to Yes. Then Save Config.

  2. Now (from the top menu), go to Sales > Terms and Conditions.

  3. Click Add New Condition and fill in the required fields.

Condition Name is only shown to the admin and can be whatever you’d like.

Status should be Enabled.

Show content as sets whether html can be displayed in the terms and conditions content box. Set this to yes if you want to style the content or add links.

Checkbox text is shown next to the check-box, for example “I agree to the terms and conditions of this website.”

Content is the content that will be shown under the checkbox. You can place the entire text of your terms and conditions here or include a link to it.

  1. Click Save Condition and you are all set. Remember to test your checkout to see how everything looks and make sure it is working correctly.

now change the layout using xml or phtml...

  • I think that will show on last of the process. I don't want to go on to onepage process instead on checkout page. – Kishor Aug 10 '15 at 3:50
1

If want this first step checkout for then i am suggesting to you add this billing step because it customer is already logged in magento customer is must goto billing step and billing.phtml you need to call billing agreement and validate it on saveBillingAction.

Step1: Call this code <block type="checkout/agreements" name="checkout.onepage.agreements" as="agreements" template="checkout/onepage/agreements.phtml"/> at billing step;

Step2: Need to override OnepageController.php and saveBillingAction add this code:

   $requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds();
        if ($requiredAgreements) {
            $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
            $diff = array_diff($requiredAgreements, $postedAgreements);
            if ($diff) {
                $result['success'] = false;
                $result['error'] = true;
                $result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.');
                $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
                return;
            }
        }

Which validate billing agreement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.