Skip to content

Commit

Permalink
Serialize line item options which are array values to JSON; Resolves #12
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnynotsolucky committed Nov 25, 2019
1 parent 67e0b6c commit 2887d1a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.2.5 - 2019-11-25

### Updated

- Line Item options which are an array or object are serialized to a JSON string.
- Order Line Item options are now limited to a maximum of 10 per line item. Limit set by ShipStation.

## 1.2.4 - 2019-10-28

### Updated
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A Craft CMS plugin for integrating Craft Commerce with ShipStation",
"homepage": "https://github.com/fostercommerce/shipstation-connect",
"type": "craft-plugin",
"version": "1.2.4",
"version": "1.2.5",
"keywords": ["craft","plugin","shipstation"],
"license": "proprietary",
"support": {
Expand Down
16 changes: 15 additions & 1 deletion src/services/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class Xml extends Component
{
const LINEITEM_OPTION_LIMIT = 10;
const ORDER_FIELD_EVENT = 'orderFieldEvent';

public function shouldInclude($order)
Expand Down Expand Up @@ -293,10 +294,23 @@ public function options(\SimpleXMLElement $xml, $options, $name='Options')
{
$options_xml = $xml->getName() == $name ? $xml : $xml->addChild($name);


$index = 0;
foreach ($options as $key => $value) {
$option_xml = $options_xml->addChild('Option');
$this->addChildWithCDATA($option_xml, 'Name', $key);
$option_xml->addChild('Name', $key);

if (is_array($value) || !is_object($value)) {
$value = json_encode($value);
}

$this->addChildWithCDATA($option_xml, 'Value', $value);

// ShipStation limits the number of options on any line item
$index++;
if ($index === self::LINEITEM_OPTION_LIMIT) {
break;
}
}

return $xml;
Expand Down

0 comments on commit 2887d1a

Please sign in to comment.