Skip to content

Commit a1dca4f

Browse files
committed
Merge pull request #1 from fusionspim/feature/exports
Helper classes to export Demandware XML files
2 parents 3aa43e8 + 4fde3e0 commit a1dca4f

23 files changed

+2292
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*.sublime-*
2+
/.idea
3+
.DS_Store
4+
out
5+
vendor

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 Fusions PIM Limited
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
1-
# php-demandware-xml
21
PHP library for working with Demandware XML files
2+
===
3+
4+
Helpers for working with Demandware XML files.
5+
6+
- Exporting: supports category/product/variant/assignment files, and allows elements to be added in the order that makes sense for your code - they'll be exported in the sequence specified by the XSD automatically, and custom attribute elements are ordered by attribute ids for consistency between exports
7+
- Validating: against included XSD schemas (done automatically when exporting)
8+
- Parsing: *to-do*
9+
- Comparing: *in-progress* reports on different ids/elements/attributes, regardless of how they're ordered in the files (i.e. higher-level than diff) which is useful when different systems/processes have exported the files
10+
11+
12+
Install
13+
---
14+
15+
Via Composer:
16+
17+
``` bash
18+
$ composer require fusionspim/php-demandware-xml
19+
```
20+
21+
Usage
22+
---
23+
24+
See `test.php` for usage, and `/examples` for output examples.
25+
26+
27+
Future plans
28+
---
29+
30+
- Export all root elements sorted by their first attribute value (similar to custom attributes) to ease manual comparison/diffs
31+
- Test a large export to better understand how scales and memory usage
32+
- Convert nested elements currently implemented with string concatenation/loops to nodes (they work, but would be nice for consistency/robustness) & deal with the `setClassification()`/`catalog-id` hack ;-)

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "fusionspim/php-demandware-xml",
3+
"type": "library",
4+
"description": "PHP library for working with Demandware XML files",
5+
"keywords": ["demandware", "xml", "export", "php"],
6+
"homepage": "https://github.com/fusionspim/php-demandware-xml",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Wes Hooper",
11+
"email": "wes@fusionspim.com"
12+
}
13+
],
14+
"require": {
15+
"php": ">=5.6"
16+
},
17+
"autoload": {
18+
"psr-4": {"DemandwareXml\\": "src"}
19+
}
20+
}

composer.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/assignments.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<catalog xmlns="http://www.demandware.com/xml/impex/catalog/2006-10-31" catalog-id="TestCatalog">
3+
<category-assignment product-id="PROD1" category-id="CAT2">
4+
<primary-flag>true</primary-flag>
5+
</category-assignment>
6+
<category-assignment product-id="PROD1" category-id="CAT42"/>
7+
<category-assignment product-id="PROD2" category-id="CAT1" mode="delete"/>
8+
<category-assignment product-id="PROD3" category-id="CAT3">
9+
<primary-flag>false</primary-flag>
10+
</category-assignment>
11+
</catalog>

examples/categories.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<catalog xmlns="http://www.demandware.com/xml/impex/catalog/2006-10-31" catalog-id="TestCatalog">
3+
<category category-id="CAT0">
4+
<display-name xml:lang="x-default">Socks</display-name>
5+
<online-flag>true</online-flag>
6+
<parent>CAT0</parent>
7+
<template>cat-listings.html</template>
8+
<sitemap-included-flag>true</sitemap-included-flag>
9+
<sitemap-changefrequency>weekly</sitemap-changefrequency>
10+
<sitemap-priority>0.2</sitemap-priority>
11+
<page-attributes>
12+
<page-title xml:lang="x-default">Socks</page-title>
13+
<page-description xml:lang="x-default">Buy Socks</page-description>
14+
<page-keywords xml:lang="x-default">socks</page-keywords>
15+
<page-url xml:lang="x-default">/Socks</page-url>
16+
</page-attributes>
17+
<custom-attributes>
18+
<custom-attribute attribute-id="hasOffers">true</custom-attribute>
19+
<custom-attribute attribute-id="itemsPerPage">30</custom-attribute>
20+
<custom-attribute attribute-id="promoMast">cat0-banner.png</custom-attribute>
21+
</custom-attributes>
22+
</category>
23+
<category category-id="CAT1">
24+
<display-name xml:lang="x-default">Death Stars</display-name>
25+
<online-flag>true</online-flag>
26+
<parent>CAT0</parent>
27+
<template>cat-listings.html</template>
28+
<sitemap-included-flag>true</sitemap-included-flag>
29+
<sitemap-changefrequency>weekly</sitemap-changefrequency>
30+
<sitemap-priority>0.2</sitemap-priority>
31+
<page-attributes>
32+
<page-title xml:lang="x-default">Death Stars</page-title>
33+
<page-description xml:lang="x-default">Buy Death Stars</page-description>
34+
<page-keywords xml:lang="x-default">death stars</page-keywords>
35+
<page-url xml:lang="x-default">/Death Stars</page-url>
36+
</page-attributes>
37+
<custom-attributes>
38+
<custom-attribute attribute-id="hasOffers">true</custom-attribute>
39+
<custom-attribute attribute-id="itemsPerPage">30</custom-attribute>
40+
<custom-attribute attribute-id="promoMast">cat1-banner.png</custom-attribute>
41+
</custom-attributes>
42+
</category>
43+
<category category-id="CAT2">
44+
<display-name xml:lang="x-default">Donuts</display-name>
45+
<online-flag>true</online-flag>
46+
<parent>CAT0</parent>
47+
<template>cat-listings.html</template>
48+
<sitemap-included-flag>true</sitemap-included-flag>
49+
<sitemap-changefrequency>weekly</sitemap-changefrequency>
50+
<sitemap-priority>0.2</sitemap-priority>
51+
<page-attributes>
52+
<page-title xml:lang="x-default">Donuts</page-title>
53+
<page-description xml:lang="x-default">Buy Donuts</page-description>
54+
<page-keywords xml:lang="x-default">donuts</page-keywords>
55+
<page-url xml:lang="x-default">/Donuts</page-url>
56+
</page-attributes>
57+
<custom-attributes>
58+
<custom-attribute attribute-id="hasOffers">true</custom-attribute>
59+
<custom-attribute attribute-id="itemsPerPage">30</custom-attribute>
60+
<custom-attribute attribute-id="promoMast">cat2-banner.png</custom-attribute>
61+
</custom-attributes>
62+
</category>
63+
</catalog>

examples/products.xml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<catalog xmlns="http://www.demandware.com/xml/impex/catalog/2006-10-31" catalog-id="TestCatalog">
3+
<product product-id="PRODUCT123">
4+
<upc>500000000000</upc>
5+
<min-order-quantity>1</min-order-quantity>
6+
<step-quantity>1</step-quantity>
7+
<display-name xml:lang="x-default">Product number 123</display-name>
8+
<long-description xml:lang="x-default">The description for an example product!</long-description>
9+
<online-flag>true</online-flag>
10+
<online-from>2015-01-23T01:23:45</online-from>
11+
<online-to>2025-01-23T01:23:45</online-to>
12+
<searchable-flag>false</searchable-flag>
13+
<brand>SampleBrand™</brand>
14+
<search-rank>1</search-rank>
15+
<sitemap-included-flag>true</sitemap-included-flag>
16+
<sitemap-changefrequency>weekly</sitemap-changefrequency>
17+
<sitemap-priority>0.5</sitemap-priority>
18+
<page-attributes>
19+
<page-title xml:lang="x-default">Amazing Product</page-title>
20+
<page-description xml:lang="x-default">Buy our Product today!</page-description>
21+
<page-keywords xml:lang="x-default">Product, test, example</page-keywords>
22+
<page-url xml:lang="x-default">http://example.com/product/123</page-url>
23+
</page-attributes>
24+
<custom-attributes>
25+
<custom-attribute attribute-id="boolTest">true</custom-attribute>
26+
<custom-attribute attribute-id="multiWow">
27+
<value>so</value>
28+
<value>such</value>
29+
<value>many</value>
30+
<value>much</value>
31+
<value>very</value>
32+
</custom-attribute>
33+
<custom-attribute attribute-id="primaryImage">product-123.png</custom-attribute>
34+
<custom-attribute attribute-id="type">Examples</custom-attribute>
35+
<custom-attribute attribute-id="zzz">Should be exported last within custom-attributes</custom-attribute>
36+
</custom-attributes>
37+
<variations>
38+
<attributes>
39+
<shared-variation-attribute variation-attribute-id="AT001" attribute-id="AT001"/>
40+
<shared-variation-attribute variation-attribute-id="AT002" attribute-id="AT002"/>
41+
</attributes>
42+
<variants>
43+
<variant product-id="SKU0000001"/>
44+
<variant product-id="SKU0000002"/>
45+
<variant product-id="SKU0000003" default="true"/>
46+
</variants>
47+
</variations>
48+
<classification-category catalog-id="TestCatalog">CAT123</classification-category>
49+
</product>
50+
<product product-id="SET123">
51+
<upc>500000000001</upc>
52+
<min-order-quantity>1</min-order-quantity>
53+
<step-quantity>1</step-quantity>
54+
<display-name xml:lang="x-default">Set number 123</display-name>
55+
<long-description xml:lang="x-default">The description for an example set!</long-description>
56+
<online-flag>true</online-flag>
57+
<online-from>2015-01-23T01:23:45</online-from>
58+
<online-to>2025-01-23T01:23:45</online-to>
59+
<searchable-flag>false</searchable-flag>
60+
<brand>SampleBrand™</brand>
61+
<search-rank>1</search-rank>
62+
<sitemap-included-flag>true</sitemap-included-flag>
63+
<sitemap-changefrequency>weekly</sitemap-changefrequency>
64+
<sitemap-priority>0.5</sitemap-priority>
65+
<page-attributes>
66+
<page-title xml:lang="x-default">Amazing Set</page-title>
67+
<page-description xml:lang="x-default">Buy our Set today!</page-description>
68+
<page-keywords xml:lang="x-default">Set, test, example</page-keywords>
69+
<page-url xml:lang="x-default">http://example.com/set/123</page-url>
70+
</page-attributes>
71+
<custom-attributes>
72+
<custom-attribute attribute-id="boolTest">true</custom-attribute>
73+
<custom-attribute attribute-id="multiWow">
74+
<value>so</value>
75+
<value>such</value>
76+
<value>many</value>
77+
<value>much</value>
78+
<value>very</value>
79+
</custom-attribute>
80+
<custom-attribute attribute-id="primaryImage">set-123.png</custom-attribute>
81+
<custom-attribute attribute-id="type">Examples</custom-attribute>
82+
<custom-attribute attribute-id="zzz">Should be exported last within custom-attributes</custom-attribute>
83+
</custom-attributes>
84+
<product-set-products>
85+
<product-set-product product-id="PRODUCT123"/>
86+
<product-set-product product-id="PRODUCT456"/>
87+
</product-set-products>
88+
<classification-category catalog-id="TestCatalog">CAT123</classification-category>
89+
</product>
90+
<product product-id="BUNDLE123">
91+
<upc>500000000002</upc>
92+
<min-order-quantity>1</min-order-quantity>
93+
<step-quantity>1</step-quantity>
94+
<display-name xml:lang="x-default">Bundle number 123</display-name>
95+
<long-description xml:lang="x-default">The description for an example bundle!</long-description>
96+
<online-flag>true</online-flag>
97+
<online-from>2015-01-23T01:23:45</online-from>
98+
<online-to>2025-01-23T01:23:45</online-to>
99+
<searchable-flag>false</searchable-flag>
100+
<tax-class-id>TAX_20_00</tax-class-id>
101+
<brand>SampleBrand™</brand>
102+
<search-rank>1</search-rank>
103+
<sitemap-included-flag>true</sitemap-included-flag>
104+
<sitemap-changefrequency>weekly</sitemap-changefrequency>
105+
<sitemap-priority>0.5</sitemap-priority>
106+
<page-attributes>
107+
<page-title xml:lang="x-default">Amazing Bundle</page-title>
108+
<page-description xml:lang="x-default">Buy our Bundle today!</page-description>
109+
<page-keywords xml:lang="x-default">Bundle, test, example</page-keywords>
110+
<page-url xml:lang="x-default">http://example.com/bundle/123</page-url>
111+
</page-attributes>
112+
<custom-attributes>
113+
<custom-attribute attribute-id="boolTest">true</custom-attribute>
114+
<custom-attribute attribute-id="multiWow">
115+
<value>so</value>
116+
<value>such</value>
117+
<value>many</value>
118+
<value>much</value>
119+
<value>very</value>
120+
</custom-attribute>
121+
<custom-attribute attribute-id="primaryImage">bundle-123.png</custom-attribute>
122+
<custom-attribute attribute-id="type">Examples</custom-attribute>
123+
<custom-attribute attribute-id="zzz">Should be exported last within custom-attributes</custom-attribute>
124+
</custom-attributes>
125+
<bundled-products>
126+
<bundled-product product-id="SKU0000001">
127+
<quantity>10</quantity>
128+
</bundled-product>
129+
<bundled-product product-id="SKU0000002">
130+
<quantity>20</quantity>
131+
</bundled-product>
132+
</bundled-products>
133+
<classification-category catalog-id="TestCatalog">CAT123</classification-category>
134+
</product>
135+
</catalog>

examples/variants.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<catalog xmlns="http://www.demandware.com/xml/impex/catalog/2006-10-31" catalog-id="TestCatalog">
3+
<variation-attribute variation-attribute-id="colour" attribute-id="colour">
4+
<variation-attribute-values>
5+
<variation-attribute-value value="red">
6+
<display-value xml:lang="x-default">Red</display-value>
7+
</variation-attribute-value>
8+
<variation-attribute-value value="blue">
9+
<display-value xml:lang="x-default">Blue</display-value>
10+
</variation-attribute-value>
11+
</variation-attribute-values>
12+
</variation-attribute>
13+
<variation-attribute variation-attribute-id="height" attribute-id="height">
14+
<variation-attribute-values>
15+
<variation-attribute-value value="H1">
16+
<display-value xml:lang="x-default">Grande</display-value>
17+
</variation-attribute-value>
18+
<variation-attribute-value value="H2">
19+
<display-value xml:lang="x-default">Tall</display-value>
20+
</variation-attribute-value>
21+
</variation-attribute-values>
22+
</variation-attribute>
23+
</catalog>

src/Assignment.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace DemandwareXml;
3+
4+
class Assignment extends Base
5+
{
6+
protected $element = 'category-assignment';
7+
8+
/**
9+
* Create a new <category-assignment> element, for the product/category ids
10+
*
11+
* @param null $objectId
12+
* @param null $categoryId
13+
*/
14+
public function __construct($objectId = null, $categoryId = null)
15+
{
16+
// although passed as `product-id`, can actually represent a product/variation/set/bundle
17+
$this->attributes = ['product-id' => $objectId, 'category-id' => $categoryId];
18+
}
19+
20+
/**
21+
* Sets the `mode` attribute to "delete"
22+
*/
23+
public function setDeleted()
24+
{
25+
$this->attributes['mode'] = 'delete';
26+
}
27+
28+
/**
29+
* Adds a <primary-flag> element with true/false value
30+
*
31+
* @param $primary
32+
*/
33+
public function setPrimary($primary)
34+
{
35+
$this->elements['primary-flag'] = $primary;
36+
}
37+
}

0 commit comments

Comments
 (0)