Vince P
Vince P

Reputation: 1791

PHP if statement dependent on value

We currently have the following code which displays a link if a quotation is viewable:

        <td><?php echo $this->__($_quotation->getstatus()); ?></td>
        <td class="a-center">
            <?php if ($_quotation->isViewableByCustomer()): ?>
                    <a href="<?php echo $this->getViewUrl($_quotation) ?>"><?php echo $this->__('View Quotation') ?></a>
                <?php endif; ?>
        </td>

We're looking to show the link if the quotation status value equals Active or Expired but not Pending.

How should I change this code around to reflect this?

Upvotes: 0

Views: 148

Answers (2)

Michael Berkowski
Michael Berkowski

Reputation: 270677

I'm assuming you intend to show the status cell in any condition, and only link to it if Active or Expired. at least that's how I read your question.

Assuming the function $_quotation->getstatus() returns the strings "Active" or "Expired" before internationalization, just add something like this to the condition that displays the link:

 <td><?php echo $this->__($_quotation->getstatus()); ?></td>
 <td class="a-center">
     <?php if ($_quotation->isViewableByCustomer() && ($_quotation->getstatus() == "Active" || $_quotation->getstatus() == "Expired")): ?>
          <a href="<?php echo $this->getViewUrl($_quotation) ?>"><?php echo $this->__('View Quotation') ?></a>
     <?php endif; ?>
 </td>

EDIT According to comment below, isViewableByCustomer() is not relevant here, so try:

 <td><?php echo $this->__($_quotation->getstatus()); ?></td>
 <td class="a-center">
     <?php if ($_quotation->getstatus() == "Active" || $_quotation->getstatus() == "Expired"): ?>
          <a href="<?php echo $this->getViewUrl($_quotation) ?>"><?php echo $this->__('View Quotation') ?></a>
     <?php endif; ?>
 </td>

Upvotes: 2

Mild Fuzz
Mild Fuzz

Reputation: 30731

   <?php if ($this->__($_quotation->getstatus() == "Active" || $this->__($_quotation->getstatus() == "Expired"){?><td><?php echo $this->__($_quotation->getstatus()); ?></td>
        <td class="a-center">
            <?php if ($_quotation->isViewableByCustomer()): ?>
                    <a href="<?php echo $this->getViewUrl($_quotation) ?>"><?php echo $this->__('View Quotation') ?></a>
                <?php endif; ?>
        </td>

Upvotes: 0

Related Questions