Skip to content

Commit

Permalink
Merge pull request #38 from 5zymon/master
Browse files Browse the repository at this point in the history
Fixing cloneIt method. It was loosing array nodes during cloning. Ins…
  • Loading branch information
lukesnowden authored Feb 19, 2019
2 parents 9792555 + beb8b85 commit 8a14e8e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/LukeSnowden/GoogleShoppingFeed/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,19 @@ public function cloneIt()
if (is_array($node)) {
// multiple accepted values..
$name = $node[0]->get('name');
$multipleNodes = array();
foreach ($node as $_node) {
if ($name == 'shipping') {
// Shipping has another layer so we are going to have to do a little hack
$xml = simplexml_load_string('<foo>' . trim(str_replace('g:', '', $_node->get('value'))) . '</foo>');
$item->{$_node->get('name')}($xml->country, $xml->service, $xml->price);
} else {
$item->{$name}($_node->get('value'));
$multipleNodes[$name][] = $_node->get('value');
}
}
if (count($multipleNodes)) {
$item->{$name}($multipleNodes[$name]);
}
} elseif ($node->get('name') !== 'shipping') {
if (method_exists($item, $node->get('name'))) {
$item->{$node->get('name')}($node->get('value'));
Expand Down

0 comments on commit 8a14e8e

Please sign in to comment.