Skip to content

Commit

Permalink
Merge pull request lukesnowden#31 from vinimtex/master
Browse files Browse the repository at this point in the history
Allow multiple images and custom fields with namespace
  • Loading branch information
lukesnowden authored Apr 6, 2018
2 parents d61569b + 73ac7e9 commit 51437c1
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/LukeSnowden/GoogleShoppingFeed/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ public function custom($name, $value)
$this->nodes[$name] = $node->value($value);
}

/**
* Adds a custom attribute to the shopping feed with namespace.
*
* @param string $name
* @param string $value
*/
public function customWithNamespace($name, $value)
{
$node = new Node($name);
$this->nodes[$name] = $node->value($value)->_namespace($this->namespace);
}

/**
* Returns item nodes
* @return array
Expand Down Expand Up @@ -503,12 +515,23 @@ public function pattern($pattern)
}

/**
* @param $imageLink
* Add one additional image (string) or multiple images (array).
*
* @param $imagesLink
*/
public function additional_image_link($imageLink)
public function additional_image_link($imagesLink)
{
$node = new Node('additional_image_link');
$imageLink = $this->safeCharEncodeURL(urldecode($imageLink));
$this->nodes['additional_image_link'] = $node->value($imageLink)->_namespace($this->namespace)->addCdata();
$this->nodes['additional_image_link'] = [];
if (is_array($imagesLink)) {
foreach ($imagesLink as $imageLink) {
$node = new Node('additional_image_link');
$imageLink = $this->safeCharEncodeURL(urldecode($imageLink));
array_push($this->nodes['additional_image_link'], $node->value($imageLink)->_namespace($this->namespace)->addCdata());
}
} else {
$node = new Node('additional_image_link');
$imageLink = $this->safeCharEncodeURL(urldecode($imagesLink));
array_push($this->nodes['additional_image_link'], $node->value($imagesLink)->_namespace($this->namespace)->addCdata());
}
}
}

0 comments on commit 51437c1

Please sign in to comment.