Skip to content

Commit b6037f9

Browse files
committed
Add ability to generate Index (product catalog)
1 parent a261c40 commit b6037f9

28 files changed

+752
-49
lines changed

src/CXml/Builder/OrderRequestBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function fromPunchOutOrderMessage(
134134
$orb->addItem(
135135
$item->quantity,
136136
$item->itemId,
137-
$item->itemDetail->description->value ?? '',
137+
$item->itemDetail->descriptions[0]->value ?? '',
138138
$item->itemDetail->unitOfMeasure,
139139
$item->itemDetail->unitPrice->money->getValueCent(),
140140
[

src/CXml/Jms/CXmlExclusionStrategy.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ public function shouldSkipProperty(PropertyMetadata $property, Context $context)
2424
return false;
2525
}
2626

27-
if (Comment::class === $property->class) {
28-
if ('attachment' === $property->name) {
29-
/** @var Comment $object */
30-
/** @phpstan-ignore-next-line */
31-
$object = $context->getObject();
32-
33-
// if comment has a textual value, we dont serialize the <Attachment> element anymore. See DTD:
34-
// <!ELEMENT Comments ( #PCDATA | Attachment )* >
35-
if (isset($object->value)) {
36-
return true;
37-
}
27+
if (Comment::class === $property->class && 'attachment' === $property->name) {
28+
/** @var Comment $object */
29+
/** @phpstan-ignore-next-line */
30+
$object = $context->getObject();
31+
// if comment has a textual value, we dont serialize the <Attachment> element anymore. See DTD:
32+
// <!ELEMENT Comments ( #PCDATA | Attachment )* >
33+
if (isset($object->value)) {
34+
return true;
3835
}
3936
}
4037

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CXml\Model;
6+
7+
use JMS\Serializer\Annotation as Serializer;
8+
9+
class AttachmentReference
10+
{
11+
public function __construct(
12+
#[Serializer\SerializedName('Name')]
13+
#[Serializer\XmlElement(cdata: false)]
14+
public MultilanguageString $name,
15+
#[Serializer\SerializedName('Description')]
16+
#[Serializer\XmlElement(cdata: false)]
17+
public MultilanguageString $description,
18+
#[Serializer\SerializedName('InternalID')]
19+
#[Serializer\XmlElement(cdata: false)]
20+
public string $internalId,
21+
#[Serializer\SerializedName('URL')]
22+
#[Serializer\XmlElement(cdata: false)]
23+
public ?string $url = null,
24+
) {
25+
}
26+
}

src/CXml/Model/Characteristic.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CXml\Model;
6+
7+
use JMS\Serializer\Annotation as Serializer;
8+
9+
readonly class Characteristic
10+
{
11+
public function __construct(
12+
#[Serializer\XmlAttribute]
13+
public string $domain,
14+
#[Serializer\XmlAttribute]
15+
public string $value,
16+
#[Serializer\XmlAttribute]
17+
public ?string $code = null,
18+
) {
19+
}
20+
}

src/CXml/Model/Classification.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public function __construct(
1313
#[Serializer\XmlAttribute]
1414
public string $domain,
1515
#[Serializer\XmlValue(cdata: false)]
16-
public string $value,
16+
public ?string $value = null,
17+
#[Serializer\XmlAttribute]
18+
public ?string $code = null,
1719
) {
1820
}
1921
}

src/CXml/Model/Index.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CXml\Model;
6+
7+
use Assert\Assertion;
8+
use CXml\Model\Trait\CommentsTrait;
9+
use JMS\Serializer\Annotation as Serializer;
10+
use ReflectionClass;
11+
use Stringable;
12+
13+
#[Serializer\XmlRoot('Index')]
14+
#[Serializer\AccessorOrder(order: 'custom', custom: ['supplierId', 'comments', 'indexItems'])]
15+
class Index implements Stringable
16+
{
17+
use CommentsTrait;
18+
19+
public function __construct(
20+
#[Serializer\XmlAttribute]
21+
#[Serializer\SerializedName('loadmode')]
22+
public readonly string $loadmode,
23+
#[Serializer\SerializedName('SupplierID')]
24+
public readonly SupplierId $supplierId,
25+
/**
26+
* @var IndexItemWrapper[]
27+
*/
28+
#[Serializer\XmlList(entry: 'IndexItem', inline: true)]
29+
#[Serializer\Type('array<CXml\Model\IndexItemWrapper>')]
30+
private array $indexItems = [],
31+
#[Serializer\Exclude]
32+
public string $dtdUri = 'http://xml.cxml.org/schemas/cXML/1.2.063/cXML.dtd',
33+
) {
34+
Assertion::inArray($this->loadmode, ['Full', 'Incremental']);
35+
}
36+
37+
public static function create(string $loadmode, SupplierId $supplierId): self
38+
{
39+
return new self($loadmode, $supplierId);
40+
}
41+
42+
public function addIndexItem(IndexItemInterface $indexItem): self
43+
{
44+
$shortClsName = (new ReflectionClass($indexItem))->getShortName();
45+
46+
if (!isset($this->indexItems[$shortClsName])) {
47+
$this->indexItems[$shortClsName] = new IndexItemWrapper();
48+
}
49+
50+
$this->indexItems[$shortClsName]->addIndexItem($indexItem);
51+
52+
return $this;
53+
}
54+
55+
public function __toString(): string
56+
{
57+
return 'Index';
58+
}
59+
}

src/CXml/Model/IndexItemAdd.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CXml\Model;
6+
7+
use JMS\Serializer\Annotation as Serializer;
8+
9+
class IndexItemAdd implements IndexItemInterface
10+
{
11+
public function __construct(
12+
#[Serializer\SerializedName('ItemID')]
13+
public ItemId $itemId,
14+
#[Serializer\SerializedName('ItemDetail')]
15+
public ItemDetail $itemDetail,
16+
#[Serializer\SerializedName('IndexItemDetail')]
17+
public IndexItemDetail $indexItemDetail,
18+
) {
19+
}
20+
21+
public static function create(ItemId $itemId, ItemDetail $itemDetail, IndexItemDetail $indexItemDetail): self
22+
{
23+
return new self($itemId, $itemDetail, $indexItemDetail);
24+
}
25+
}

src/CXml/Model/IndexItemDelete.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CXml\Model;
6+
7+
use JMS\Serializer\Annotation as Serializer;
8+
9+
class IndexItemDelete implements IndexItemInterface
10+
{
11+
public function __construct(
12+
#[Serializer\SerializedName('ItemID')]
13+
public ItemId $itemId,
14+
#[Serializer\SerializedName('ItemDetail')]
15+
public ItemDetail $itemDetail,
16+
#[Serializer\SerializedName('IndexItemDetail')]
17+
public IndexItemDetail $indexItemDetail,
18+
) {
19+
}
20+
21+
public static function create(ItemId $itemId, ItemDetail $itemDetail, IndexItemDetail $indexItemDetail): self
22+
{
23+
return new self($itemId, $itemDetail, $indexItemDetail);
24+
}
25+
}

src/CXml/Model/IndexItemDetail.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CXml\Model;
6+
7+
use DateTimeInterface;
8+
use JMS\Serializer\Annotation as Serializer;
9+
10+
#[Serializer\AccessorOrder(order: 'custom', custom: ['leadtime', 'expirationDate', 'territoryAvailables'])]
11+
class IndexItemDetail
12+
{
13+
/**
14+
* @var TerritoryAvailable[]
15+
*/
16+
#[Serializer\XmlList(entry: 'TerritoryAvailable', inline: true)]
17+
#[Serializer\Type('array<CXml\Model\TerritoryAvailable>')]
18+
private array $territoryAvailables = [];
19+
20+
/**
21+
* @param string[] $territoryAvailables
22+
*/
23+
public function __construct(
24+
#[Serializer\SerializedName('LeadTime')]
25+
#[Serializer\XmlElement(cdata: false)]
26+
public int $leadtime,
27+
#[Serializer\SerializedName('ExpirationDate')]
28+
#[Serializer\XmlElement(cdata: false)]
29+
public ?DateTimeInterface $expirationDate = null,
30+
array $territoryAvailables = [],
31+
) {
32+
$this->territoryAvailables = array_map(fn (string $territory): TerritoryAvailable => new TerritoryAvailable($territory), $territoryAvailables);
33+
}
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CXml\Model;
6+
7+
interface IndexItemInterface
8+
{
9+
}

0 commit comments

Comments
 (0)