From 0c6839893744c60dd9cd7626807f1d6780c0954b Mon Sep 17 00:00:00 2001 From: Johan Lerche Schulz Date: Thu, 5 Apr 2018 16:32:28 +0200 Subject: [PATCH] removed static calls from Item class allowing for non-static usage of Feed --- src/LukeSnowden/GoogleShoppingFeed/Feed.php | 2 +- src/LukeSnowden/GoogleShoppingFeed/Item.php | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/LukeSnowden/GoogleShoppingFeed/Feed.php b/src/LukeSnowden/GoogleShoppingFeed/Feed.php index 111b735..68ea9b5 100644 --- a/src/LukeSnowden/GoogleShoppingFeed/Feed.php +++ b/src/LukeSnowden/GoogleShoppingFeed/Feed.php @@ -130,7 +130,7 @@ private function channel() public function createItem() { $this->channel(); - $item = new Item; + $item = new Item($this); $index = 'index_' . md5(microtime()); $this->items[$index] = $item; $item->setIndex($index); diff --git a/src/LukeSnowden/GoogleShoppingFeed/Item.php b/src/LukeSnowden/GoogleShoppingFeed/Item.php index 89e6db6..e41f03b 100644 --- a/src/LukeSnowden/GoogleShoppingFeed/Item.php +++ b/src/LukeSnowden/GoogleShoppingFeed/Item.php @@ -61,12 +61,22 @@ class Item */ private $index = null; + /** + * @var Feed + */ + private $googleShoppingFeed = null; + /** * [$namespace - (g:) namespace definition] * @var string */ protected $namespace = 'http://base.google.com/ns/1.0'; + public function __construct($googleShoppingFeed) + { + $this->googleShoppingFeed = $googleShoppingFeed; + } + /** * @param $id */ @@ -105,7 +115,7 @@ public function price($price) $price = (float) preg_replace( "/^([0-9]+\.?[0-9]*)(\s[A-Z]{3})$/", "$1", $price ); $node = new Node('price'); $price = number_format($price, 2, '.', ''); - $code = GoogleShopping::getIso4217CountryCode(); + $code = $this->googleShoppingFeed->getIso4217CountryCode(); $this->nodes['price'] = $node->value( $price . " {$code}" )->_namespace($this->namespace); } @@ -118,7 +128,7 @@ public function sale_price($salePrice) $salePrice = (float) preg_replace( "/^([0-9]+\.?[0-9]*)(\s[A-Z]{3})$/", "$1", $salePrice ); $node = new Node('sale_price'); $salePrice = number_format($salePrice, 2, '.', ''); - $code = GoogleShopping::getIso4217CountryCode(); + $code = $this->googleShoppingFeed->getIso4217CountryCode(); $this->nodes['sale_price'] = $node->value( $salePrice . " {$code}" )->_namespace($this->namespace); } @@ -402,7 +412,7 @@ public function setIndex($index) */ public function delete() { - GoogleShopping::removeItemByIndex($this->index); + $this->googleShoppingFeed->removeItemByIndex($this->index); } /** @@ -426,7 +436,7 @@ public function cloneIt() { $groupIdentifiers = $this->getGroupIdentifier(); /** @var Item $item */ - $item = GoogleShopping::createItem(); + $item = $this->googleShoppingFeed->createItem(); $this->item_group_id( $groupIdentifiers ); foreach ($this->nodes as $node) { if (is_array($node)) {