Last active
December 17, 2015 19:19
-
-
Save atticoos/5659816 to your computer and use it in GitHub Desktop.
Solution for matching "Input name" and "Input value" fields for Shopp's Promotion component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Updated match function */ | |
function match ($rule) { | |
extract($rule); | |
switch($property) { | |
case 'Any item name': $subject = $this->name; break; | |
case 'Any item quantity': $subject = (int)$this->quantity; break; | |
case 'Any item amount': $subject = $this->total; break; | |
case 'Name': $subject = $this->name; break; | |
case 'Category': $subject = $this->categories; break; | |
case 'Tag name': $subject = $this->tags; break; | |
case 'Variation': $subject = $this->option->label; break; | |
// iterate over the keys for the Promotion::match_rule | |
case 'Input name': | |
foreach($this->data as $inputName=>$inputValue){ | |
if (Promotion::match_rule($inputName, $logic, $value, $property)){ | |
return true; | |
} | |
} | |
return false; | |
// iterate over the values for Promotion::match_rule | |
case 'Input value': | |
foreach($this->data as $inputName=>$inputValue){ | |
if (Promotion::match_rule($inputValue, $logic, $value, $property)){ | |
return true; | |
} | |
} | |
return false; | |
case 'Quantity': $subject = $this->quantity; break; | |
case 'Unit price': $subject = $this->unitprice; break; | |
case 'Total price': $subject = $this->total; break; | |
case 'Discount amount': $subject = $this->discount; break; | |
} | |
return Promotion::match_rule($subject,$logic,$value,$property); | |
} | |
/* Existing match function */ | |
public function match ($rule) { | |
extract($rule); | |
switch($property) { | |
case 'Any item name': $subject = $this->name; break; | |
case 'Any item quantity': $subject = (int)$this->quantity; break; | |
case 'Any item amount': $subject = $this->total; break; | |
case 'Name': $subject = $this->name; break; | |
case 'Category': $subject = $this->categories; break; | |
case 'Tag name': $subject = $this->tags; break; | |
case 'Variation': $subject = $this->option->label; break; | |
// case 'Input name': $subject = $Item->option->label; break; | |
// case 'Input value': $subject = $Item->option->label; break; | |
case 'Quantity': $subject = $this->quantity; break; | |
case 'Unit price': $subject = $this->unitprice; break; | |
case 'Total price': $subject = $this->total; break; | |
case 'Discount amount': $subject = $this->discount; break; | |
} | |
return Promotion::match_rule($subject,$logic,$value,$property); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment