Update article price
This example changes data in Twinfield. It creates an article first and deletes it again, but only run it on a test administration.
Twinfield documentation: Articles.
Creates an example article, changes the price of its sub-article and adds a second sub-article.
An update sends the whole article. So start from $article->edit(): an ArticleInput with all current values and sub-articles, in which you only change what must change.
$subArticle->edit()gives aSubArticleInputwith the current values of a sub-article.subArticle()on the article input replaces the sub-article with the same code, or adds a new one.removeSubArticle($code)deletes a sub-article when the article is saved. Twinfield keeps a sub-article that is used in an invoice; adding it again withsubArticle()recovers it.unitPriceExcl()clears the price including VAT, and the other way round: Twinfield calculates the other price with the VAT code.
update() throws an ArticleNotFoundException when the code does not exist, and reads the article back after saving.
$twinfield = Example::twinfield();
$articles = $twinfield->articles();
$updated = $articles->update( $article->edit() ->subArticle($article->subArticles[0]->edit()->unitPriceExcl('799.00')) ->subArticle(SubArticleInput::create("Example man's bike", $account, $code . '-M')->unitPriceExcl('810.00')),);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/update-article-price/example.phpcomposer test:write also runs this example, after you confirm the company code.
Created EXAMPLE999: EXAMPLE999-L 750.00Updated EXAMPLE999-L: 799.00 excl., 966.79 incl.Updated EXAMPLE999-M: 810.00 excl., 980.10 incl.Deleted 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.
$article = $twinfield->articles()->get('BIKE');
$twinfield->articles()->update( $article->edit()->subArticle($article->subArticles[0]->edit()->unitPriceExcl('799.00')),);The SDK sends this XML as xmlRequest of ProcessXmlString to processxml.asmx:
<article> <header> <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> <allowchangeperformancetype>false</allowchangeperformancetype> <percentage>false</percentage> <allowdiscountorpremium>true</allowdiscountorpremium> <allowchangeunitsprice>false</allowchangeunitsprice> <allowdecimalquantity>false</allowdecimalquantity> </header> <lines> <line> <unitspriceexcl>799.00</unitspriceexcl> <unitspriceinc/> <units>1</units> <name>Lady's bike summer edition</name> <shortname>Lady summer</shortname> <subcode>BIKE.L</subcode> <freetext1>8050</freetext1> <freetext2/> <freetext3/> </line> <line> <unitspriceexcl>760.00</unitspriceexcl> <unitspriceinc>919.60</unitspriceinc> <units>1</units> <name>Man's bike summer edition</name> <shortname/> <subcode>BIKE.M</subcode> <freetext1>8051</freetext1> <freetext2>00001</freetext2> <freetext3>Summer</freetext3> </line> <line 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>8052</freetext1> <freetext2/> <freetext3/> </line> </lines></article>Twinfield answers with this XML in ProcessXmlStringResult:
<article result="1"> <header status="active"> <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>edit() sends all sub-articles back, also the deleted one (status="deleted"). The response follows the documentation; it is not recorded yet.
Source
Section titled “Source”View examples/articles/update-article-price/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.