Skip to content

Commit

Permalink
fixed error when creating variants for using new ISO currency codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Snowden authored and Luke Snowden committed Jan 16, 2018
1 parent 16e0353 commit 8dabb03
Showing 1 changed file with 42 additions and 80 deletions.
122 changes: 42 additions & 80 deletions src/LukeSnowden/GoogleShoppingFeed/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Item

/**
* Stores all of the product nodes
* @var Node[]
* @var Node
*/
private $nodes = array();

Expand All @@ -68,16 +68,7 @@ class Item
protected $namespace = 'http://base.google.com/ns/1.0';

/**
* [__construct]
*/
public function __construct()
{
}

/**
* [id - Set the ID of the product]
* @param [type] $id [description]
* @return [type] [description]
* @param $id
*/
public function id($id)
{
Expand All @@ -86,9 +77,7 @@ public function id($id)
}

/**
* [title - Set the title of the product]
* @param [type] $title [description]
* @return [type] [description]
* @param $title
*/
public function title($title)
{
Expand All @@ -98,9 +87,7 @@ public function title($title)
}

/**
* [link - Set the link/URL of the product]
* @param [type] $link [description]
* @return [type] [description]
* @param $link
*/
public function link($link)
{
Expand All @@ -110,33 +97,33 @@ public function link($link)
}

/**
* price - Set the price of the product, do not format before passing
* @param $price
*/
public function price($price)
{
/** @var $price - Added hack in for when the variants are being created it passes over the new ISO currency code which breaks number_format */
$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();
$this->nodes['price'] = $node->value( $price . " {$code}" )->_namespace($this->namespace);
}

/**
* [sale_price - set the sale price, do not format before passing]
* @param [type] $salePrice [description]
* @param $salePrice
*/
public function sale_price($salePrice)
{
/** @var $salePrice - Added hack in for when the variants are being created it passes over the new ISO currency code which breaks number_format */
$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();
$this->nodes['sale_price'] = $node->value( $salePrice . " {$code}" )->_namespace($this->namespace);
}

/**
* [description - Set the description of the product]
* @param [type] $description [description]
* @return [type] [description]
* @param $description
*/
public function description($description)
{
Expand All @@ -147,9 +134,7 @@ public function description($description)
}

/**
* [condition - Set the condition of the product (pass in the constants above to standardise the values)]
* @param [type] $condition [description]
* @return [type] [description]
* @param $condition
*/
public function condition($condition)
{
Expand All @@ -158,9 +143,7 @@ public function condition($condition)
}

/**
* [expiration_date description]
* @param [type] $expirationDate [description]
* @return [type] [description]
* @param $expirationDate
*/
public function expiration_date($expirationDate)
{
Expand All @@ -169,9 +152,7 @@ public function expiration_date($expirationDate)
}

/**
* [image_link description]
* @param [type] $imageLink [description]
* @return [type] [description]
* @param $imageLink
*/
public function image_link($imageLink)
{
Expand All @@ -181,9 +162,7 @@ public function image_link($imageLink)
}

/**
* [brand description]
* @param [type] $brand [description]
* @return [type] [description]
* @param $brand
*/
public function brand($brand)
{
Expand All @@ -193,9 +172,7 @@ public function brand($brand)
}

/**
* [mpn description]
* @param [type] $mnp [description]
* @return [type] [description]
* @param $mpn
*/
public function mpn($mpn)
{
Expand All @@ -204,9 +181,7 @@ public function mpn($mpn)
}

/**
* [gtin description]
* @param [type] $gtin [description]
* @return [type] [description]
* @param $gtin
*/
public function gtin($gtin)
{
Expand All @@ -219,20 +194,23 @@ public function gtin($gtin)
* @param [type] $bundle [description]
* @return boolean [description]
*/
public function is_bundle($bundle) {
public function is_bundle($bundle)
{
$node = new Node('is_bundle');
$this->nodes['is_bundle'] = $node->value($bundle)->_namespace($this->namespace);
}

public function identifier_exists($identifier) {
/**
* @param $identifier
*/
public function identifier_exists($identifier)
{
$node = new Node('identifier_exists');
$this->nodes['identifier_exists'] = $node->value($identifier)->_namespace($this->namespace);
}

/**
* [product_type description]
* @param [type] $productType [description]
* @return [type] [description]
* @param $productType
*/
public function product_type($productType)
{
Expand All @@ -242,9 +220,7 @@ public function product_type($productType)
}

/**
* [google_product_category description]
* @param [type] $googleProductCategory [description]
* @return [type] [description]
* @param $googleProductCategory
*/
public function google_product_category($googleProductCategory)
{
Expand All @@ -253,9 +229,7 @@ public function google_product_category($googleProductCategory)
}

/**
* [availability description]
* @param [type] $availability [description]
* @return [type] [description]
* @param $availability
*/
public function availability($availability)
{
Expand All @@ -264,9 +238,7 @@ public function availability($availability)
}

/**
* [availability_date description]
*
* @param [type] $availability [description]
* @param $availabilityDate
*/
public function availability_date($availabilityDate)
{
Expand All @@ -275,12 +247,10 @@ public function availability_date($availabilityDate)
}

/**
* [shipping description]
* @param [type] $code [description]
* @param [type] $service [description]
* @param [type] $cost [description]
* @param [type] $region [description]
* @return [type] [description]
* @param $code
* @param $service
* @param $cost
* @param null $region
*/
public function shipping($code, $service, $cost, $region = null)
{
Expand All @@ -298,9 +268,7 @@ public function shipping($code, $service, $cost, $region = null)
}

/**
* [size description]
* @param [type] $size [description]
* @return [type] [description]
* @param $size
*/
public function size($size)
{
Expand All @@ -309,9 +277,7 @@ public function size($size)
}

/**
* [gender description]
* @param [type] $gender [description]
* @return [type] [description]
* @param $gender
*/
public function gender($gender)
{
Expand All @@ -320,9 +286,7 @@ public function gender($gender)
}

/**
* [age_group description]
* @param [type] $ageGroup [description]
* @return [type] [description]
* @param $ageGroup
*/
public function age_group($ageGroup)
{
Expand All @@ -331,9 +295,7 @@ public function age_group($ageGroup)
}

/**
* [color description]
* @param [type] $color [description]
* @return [type] [description]
* @param $color
*/
public function color($color)
{
Expand All @@ -342,9 +304,7 @@ public function color($color)
}

/**
* [item_group_id description]
* @param [type] $id [description]
* @return [type] [description]
* @param $id
*/
public function item_group_id($id)
{
Expand Down Expand Up @@ -436,8 +396,8 @@ public function delete()
}

/**
* [checkForIdentificationProperties description]
* @return [type] [description]
* @return string
* @throws MissingIdentifierException
*/
protected function getGroupIdentifier()
{
Expand Down Expand Up @@ -517,15 +477,17 @@ private function safeCharEncodeText($string)
/**
* @param $material
*/
public function material($material) {
public function material($material)
{
$node = new Node('material');
$this->nodes['material'] = $node->value($material)->_namespace($this->namespace);
}

/**
* @param $pattern
*/
public function pattern($pattern) {
public function pattern($pattern)
{
$node = new Node('pattern');
$this->nodes['pattern'] = $node->value($pattern)->_namespace($this->namespace);
}
Expand Down

0 comments on commit 8dabb03

Please sign in to comment.