Skip to content

Commit

Permalink
Merge pull request #30 from johanlerche/remove-static-calls-from-item
Browse files Browse the repository at this point in the history
removed static calls from Item class allowing for non-static usage of…
  • Loading branch information
lukesnowden authored Apr 6, 2018
2 parents 51437c1 + 0c68398 commit 2313d42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/LukeSnowden/GoogleShoppingFeed/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions src/LukeSnowden/GoogleShoppingFeed/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -414,7 +424,7 @@ public function setIndex($index)
*/
public function delete()
{
GoogleShopping::removeItemByIndex($this->index);
$this->googleShoppingFeed->removeItemByIndex($this->index);
}

/**
Expand All @@ -438,7 +448,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)) {
Expand Down

0 comments on commit 2313d42

Please sign in to comment.