Delete article
This example changes data in Twinfield. It creates an article first, but only run it on a test administration.
Twinfield documentation: Articles.
Creates an example article, deletes it, activates it and deletes it again.
delete() returns a DeleteResult:
DeleteResult::Deleted: the article is deleted.DeleteResult::Hidden: an invoice uses the article, so Twinfield hid it instead.
activate() makes a deleted or hidden article active again. Both read the article first and throw an ArticleNotFoundException when the code does not exist: an <article> request for an unknown code would create it.
$twinfield = Example::twinfield();
$articles = $twinfield->articles();
$result = $articles->delete($code);
echo $result === DeleteResult::Deleted ? 'Deleted ' : 'Hidden ', $code, ': status ';echo $articles->get($code)->status->value, PHP_EOL;
// A deleted or hidden article can be activated again.$articles->activate($code);The write guard of the examples blocks changes unless you allow them for a company in TWINFIELD_WRITE_COMPANIES:
TWINFIELD_COMPANY=1002_3 TWINFIELD_ALLOW_WRITES=1002_3 php examples/articles/delete-article/example.phpcomposer test:write also runs this example, after you confirm the company code.
Created EXAMPLE999Deleted EXAMPLE999: status deletedActivated EXAMPLE999: status activeDeleted EXAMPLE999What the SDK sends to Twinfield and what Twinfield sends back, for a call like the one in this example. The responses come from the tests, with example data.
Create/Update/Delete
Section titled “Create/Update/Delete”Twinfield documentation: Articles: Create/Update/Delete.
$twinfield->articles()->delete('BIKE');The SDK sends this XML as xmlRequest of ProcessXmlString to processxml.asmx:
<article> <header status="deleted"> <office>1000</office> <code>BIKE</code> </header></article>Twinfield answers with this XML in ProcessXmlStringResult:
<article result="1"> <header status="deleted"> <office>1000</office> <code>BIKE</code> <type>normal</type> <name>Bike summer edition</name> <shortname>Bike summer</shortname> <unitnamesingular>Piece</unitnamesingular> <unitnameplural>Pieces</unitnameplural> <vatcode>VH</vatcode> <allowchangevatcode>false</allowchangevatcode> <performancetype/> <allowchangeperformancetype>false</allowchangeperformancetype> <percentage>false</percentage> <allowdiscountorpremium>true</allowdiscountorpremium> <allowchangeunitsprice>false</allowchangeunitsprice> <allowdecimalquantity>false</allowdecimalquantity> </header> <lines> <line inuse="true" status="active"> <unitspriceexcl>750.00</unitspriceexcl> <unitspriceinc>907.50</unitspriceinc> <units>1</units> <name>Lady's bike summer edition</name> <shortname>Lady summer</shortname> <subcode>BIKE.L</subcode> <freetext1 name="Bike lady" shortname="" dimensiontype="PNL">8050</freetext1> <freetext2 name="" shortname="" dimensiontype=""/> <freetext3/> <freetext4/> <freetext5/> <freetext6/> </line> <line inuse="false" status="active"> <unitspriceexcl>760.00</unitspriceexcl> <unitspriceinc>919.60</unitspriceinc> <units>1</units> <name>Man's bike summer edition</name> <shortname/> <subcode>BIKE.M</subcode> <freetext1 name="Bike man" shortname="" dimensiontype="PNL">8051</freetext1> <freetext2 name="Sales" shortname="" dimensiontype="KPL">00001</freetext2> <freetext3>Summer</freetext3> <freetext4/> <freetext5/> <freetext6/> </line> <line inuse="false" status="deleted"> <unitspriceexcl>350.00</unitspriceexcl> <unitspriceinc>423.50</unitspriceinc> <units>1</units> <name>Kid's bike summer edition</name> <shortname>Kid summer</shortname> <subcode>BIKE.K</subcode> <freetext1 name="" shortname="" dimensiontype="PNL">8052</freetext1> <freetext2 name="" shortname="" dimensiontype=""/> <freetext3/> <freetext4/> <freetext5/> <freetext6/> </line> </lines></article>delete() first reads the article, to check that it exists. The response follows the documentation; it is not recorded yet.
Source
Section titled “Source”View examples/articles/delete-article/example.php on GitHub.
Twinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.