-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added availability to provide shipping info, fixed usage for PHP 5.6
- Loading branch information
1 parent
eeb1355
commit 80c8a51
Showing
10 changed files
with
353 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
language: php | ||
|
||
php: | ||
- "5.6" | ||
- "7.0" | ||
- "7.1" | ||
- "7.2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Vitalybaev\GoogleMerchant; | ||
|
||
use Sabre\Xml\Element\Cdata; | ||
|
||
trait HasProperties | ||
{ | ||
/** | ||
* Attributes | ||
* | ||
* @var ProductProperty[] | ||
*/ | ||
private $attributes = []; | ||
|
||
/** | ||
* Sets attribute. If attribute is already exist, it would be overwritten. | ||
* | ||
* @param string $name | ||
* @param string $value | ||
* @param bool $isCData | ||
* | ||
* @return self | ||
*/ | ||
public function setAttribute($name, $value, $isCData = false) | ||
{ | ||
$productProperty = new ProductProperty($name, $value, $isCData); | ||
$this->attributes[strtolower($name)] = $productProperty; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Adds attribute. Doesn't overwrite previous attributes. | ||
* | ||
* @param $name | ||
* @param $value | ||
* @param bool $isCData | ||
* | ||
* @return self | ||
*/ | ||
public function addAttribute($name, $value, $isCData = false) | ||
{ | ||
$productProperty = new ProductProperty($name, $value, $isCData); | ||
$attributeName = strtolower($name); | ||
if (!isset($this->attributes[$attributeName])) { | ||
$this->attributes[$attributeName] = [$productProperty]; | ||
return $this; | ||
} | ||
|
||
if (!is_array($this->attributes[$attributeName])) { | ||
$this->attributes[$attributeName] = [$this->attributes[$attributeName], $productProperty]; | ||
return $this; | ||
} | ||
|
||
$this->attributes[$attributeName][] = $productProperty; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Returns structure of properties | ||
* | ||
* @param $namespace | ||
* | ||
* @return array | ||
*/ | ||
public function getPropertiesXmlStructure($namespace) | ||
{ | ||
$result = []; | ||
|
||
foreach ($this->attributes as $attributeItem) { | ||
if (is_object($attributeItem) && $attributeItem->getValue() instanceof PropertyBag) { | ||
$result[] = [ | ||
'name' => $namespace . $attributeItem->getName(), | ||
'value' => $attributeItem->getValue()->getPropertiesXmlStructure($namespace), | ||
]; | ||
|
||
continue; | ||
} | ||
|
||
$attributes = is_array($attributeItem) ? $attributeItem : [$attributeItem]; | ||
/** @var ProductProperty $attribute */ | ||
foreach ($attributes as $attribute) { | ||
$result[] = $attribute->getXmlStructure($namespace); | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return PropertyBag | ||
*/ | ||
public function getPropertyBag() | ||
{ | ||
$propertyBag = new PropertyBag(); | ||
foreach ($this->attributes as $attributeItem) { | ||
$attributes = is_array($attributeItem) ? $attributeItem : [$attributeItem]; | ||
foreach ($attributes as $attribute) { | ||
$value = $attribute->isCData() ? new Cdata($attribute->getValue()) : $attribute->getValue(); | ||
$propertyBag->addAttribute($attribute->getName(), $value, $attribute->isCData()); | ||
} | ||
} | ||
|
||
return $propertyBag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
class Condition | ||
{ | ||
const NEW = 'new'; | ||
const NEW_PRODUCT = 'new'; | ||
|
||
const REFURBISHED = 'refurbished'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace Vitalybaev\GoogleMerchant\Product; | ||
|
||
use Vitalybaev\GoogleMerchant\HasProperties; | ||
|
||
/** | ||
* Describes product's specific shipping rules | ||
* | ||
* @see https://support.google.com/merchants/answer/6324484 | ||
*/ | ||
class Shipping | ||
{ | ||
use HasProperties; | ||
|
||
/** | ||
* Sets shipping country. | ||
* | ||
* @param string $countryCode ISO 3166-1 country code | ||
* | ||
* @return $this | ||
*/ | ||
public function setCountry($countryCode) | ||
{ | ||
$this->setAttribute('country', $countryCode, false); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets shipping country. | ||
* | ||
* @param string $region | ||
* | ||
* @return $this | ||
*/ | ||
public function setRegion($region) | ||
{ | ||
$this->setAttribute('region', $region, false); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets shipping postal code. | ||
* | ||
* @param string $postalCode | ||
* | ||
* @return $this | ||
*/ | ||
public function setPostalCode($postalCode) | ||
{ | ||
$this->setAttribute('postal_code', $postalCode, false); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets shipping location id. | ||
* | ||
* @param string $locationId | ||
* | ||
* @return $this | ||
*/ | ||
public function setLocationId($locationId) | ||
{ | ||
$this->setAttribute('location_id', $locationId, false); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets shipping location group name. | ||
* | ||
* @param string $locationGroupName | ||
* | ||
* @return $this | ||
*/ | ||
public function setLocationGroupName($locationGroupName) | ||
{ | ||
$this->setAttribute('location_group_name', $locationGroupName, false); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets shipping service. | ||
* | ||
* @param string $service | ||
* | ||
* @return $this | ||
*/ | ||
public function setService($service) | ||
{ | ||
$this->setAttribute('service', $service, false); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets shipping price. | ||
* | ||
* @param string $price | ||
* | ||
* @return $this | ||
*/ | ||
public function setPrice($price) | ||
{ | ||
$this->setAttribute('price', $price, false); | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.