Skip to content

Commit

Permalink
Fixed bug when applied to ProductVariation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Guinn committed Jun 24, 2014
1 parent 3bd40e1 commit 29b0d8e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions code/Downloadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,28 @@ public function getDownloads($blacklist=array()) {
$files->merge( $this->owner->DownloadableFiles() );

if ($this->owner->IncludeParentDownloads) {
$p = $this->owner instanceof ProductVariation ? $this->owner->Product() : $this->owner->Parent();
if ($this->owner instanceof ProductVariation) {
$p = $this->owner->Product();
} elseif ($this->owner->hasMethod('Parent')) {
$p = $this->owner->Parent();
} else {
$p = null;
}

if ($p && $p->exists() && $p->hasExtension('Downloadable') && !isset($blacklist[$p->ID])) {
$files->merge( $p->getDownloads($blacklist) );
}
}

if ($this->owner->IncludeChildDownloads) {
$kids = $this->owner->hasMethod('ChildProducts') ? $this->owner->ChildProducts() : $this->owner->Children();
if ($this->owner->hasMethod('ChildProducts')) {
$kids = $this->owner->ChildProducts();
} elseif ($this->owner->hasMethod('Children')) {
$kids = $this->owner->Children();
} else {
$kids = array();
}

foreach ($kids as $kid) {
if ($kid->hasExtension('Downloadable') && !isset($blacklist[$kid->ID])) {
$files->merge( $kid->getDownloads($blacklist) );
Expand Down

0 comments on commit 29b0d8e

Please sign in to comment.