Skip to content

Commit

Permalink
Fixing cloneIt method. It was loosing array nodes during cloning. Ins…
Browse files Browse the repository at this point in the history
…tead of multiple nodes with the same name, only one (last) was left in the cloned item
  • Loading branch information
Szymon Nowak committed Feb 19, 2019
1 parent 7e9d475 commit beb8b85
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 @@ -452,15 +452,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 beb8b85

Please sign in to comment.