Skip to content

Instantly share code, notes, and snippets.

@atticoos
Last active December 17, 2015 19:19
Show Gist options
  • Save atticoos/5659816 to your computer and use it in GitHub Desktop.
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.
<?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