Unterstützt die API einen PUT Batch mit ?useNumberAsId=true ?

Hallo liebe Leute,

Ich weiß, dass ich das nicht über die URL regeln kann, aber gibt es eine Möglichkeit, mehrere Artikel gleichzeitig anhand ihrer Artikelnummer upzudaten? In der Doku wird das nur über IDs gemacht.

Vielen Dank für die Unterstützung  Smile

Hallo Argee,

ja dass ist Möglich, aber Sie dürfen die nummer in mainDetail array

 $data['mainDetail']['number'] = ArtikelNummer.

VG,

Ahmad

1 „Gefällt mir“

Ah, perfekt, danke! :slight_smile:

Also sollte die Antwort tatsächlich stimmen, bin ich zu blöde^^ Ich bekomme eine Fehlermeldung, dass ein Artikel mit der Artikelnummer bereits existiert, obwohl ich eine put- und keine post-request sende…

folgendes versuche ich gerade:

$testUpdateArray = array(
	array(
		"taxId" => 4,
		"mainDetail" => array(
			"number" => 1)
		),
	array(
		"taxId" => 4,
		"mainDetail" => array(
			"number" => 3)
		)
	);

$putBatchResponse = $shopwareClient->put("articles", $testUpdateArray);
print_r($putBatchResponse);

ändere ich das $testUpdateArray zu

$testUpdateArray = array(
	array(
		"taxId" => 4,
		"id" => 10
		),
	array(
		"taxId" => 4,
		"id" => 11
		)
	);

läuft die Geschichte wieder…

Hallo,

du muss pass die aktulle mainDetail nummer.

ob du pass andere variant nummer , dann du hast dies Fehlermeldung.

VG,

Ahmad.

What do you mean with mainDetail nummer? The field number in mainDetail or the mainDetailId? Since I only have those two articles in my test-shop, I figure the api-call should work.

What would be a different variant number? I didn’t deal with variants at all in the test-shop… Undecided

Hallo,

can you call one article via the API , then post the return array hier.

VG,

Ahmad

and if you can the exact error message from the put call

post the return data will be better.

thank’s

Sure. Here is the data of an article by a get request:

{
  "data": {
    "id": 11,
    "mainDetailId": 4,
    "supplierId": 3,
    "taxId": 4,
    "priceGroupId": null,
    "filterGroupId": null,
    "configuratorSetId": null,
    "name": "Bohnen",
    "description": "Bohnen \u2714 45% vol. \u2714 700ml \u2714 7,00\u20ac \u2714 Perola-Shop - Premium Spirituosen g\u00fcnstig bestellen - Ab 29\u20ac versandkostenfrei \u2714",
    "descriptionLong": "Alkoholgehalt in % vol.:45Herkunftsland:(noch ausf\u00fcllen)Lebensmittelunternehmer:(noch ausf\u00fcllen)Bezeichnung des Lebensmittels:(noch ausf\u00fcllen)Farbstoffe:(noch ausf\u00fcllen)Allergenhinweise:enth\u00e4lt Sulfite",
    "added": "2017-03-03T00:00:00+0100",
    "active": false,
    "pseudoSales": 0,
    "highlight": false,
    "keywords": null,
    "metaTitle": "Bohnen, 45% vol., 700ml, 7,00\u20ac",
    "changed": "2017-03-03T10:10:03+0100",
    "priceGroupActive": false,
    "lastStock": true,
    "crossBundleLook": 0,
    "notification": false,
    "template": "",
    "mode": 0,
    "availableFrom": null,
    "availableTo": null,
    "mainDetail": {
      "id": 4,
      "articleId": 11,
      "unitId": 6,
      "number": "3",
      "supplierNumber": null,
      "kind": 1,
      "additionalText": null,
      "active": false,
      "inStock": 0,
      "stockMin": null,
      "weight": "100.000",
      "width": null,
      "len": null,
      "height": null,
      "ean": "7898221141755",
      "purchasePrice": "0",
      "position": 0,
      "minPurchase": 1,
      "purchaseSteps": null,
      "maxPurchase": null,
      "purchaseUnit": "0.7000",
      "referenceUnit": "1.000",
      "packUnit": "Flasche(n)",
      "shippingFree": false,
      "releaseDate": null,
      "shippingTime": null,
      "prices": [
        
      ],
      "attribute": {
        "id": 3,
        "articleId": 11,
        "articleDetailId": 4,
        "attr1": null,
        "attr2": null,
        "attr3": null,
        "attr4": null,
        "attr5": null,
        "attr6": null,
        "attr7": null,
        "attr8": null,
        "attr9": null,
        "attr10": null,
        "attr11": null,
        "attr12": null,
        "attr13": null,
        "attr14": null,
        "attr15": null,
        "attr16": null,
        "attr17": null,
        "attr18": null,
        "attr19": null,
        "attr20": null
      },
      "configuratorOptions": [
        
      ]
    },
    "tax": {
      "id": 4,
      "tax": "7.00",
      "name": "7 %"
    },
    "propertyValues": [
      
    ],
    "supplier": {
      "id": 3,
      "name": "Array",
      "image": "",
      "link": "",
      "description": null,
      "metaTitle": null,
      "metaDescription": null,
      "metaKeywords": null,
      "changed": "2017-03-03T10:10:03+0100"
    },
    "propertyGroup": null,
    "customerGroups": [
      
    ],
    "images": [
      
    ],
    "configuratorSet": null,
    "links": [
      
    ],
    "downloads": [
      
    ],
    "categories": [
      
    ],
    "similar": null,
    "related": null,
    "details": [
      
    ],
    "seoCategories": [
      
    ]
  },
  "success": true
}

And here is the error response:

Array
(
    [success] => 1
    [data] => Array
        (
            [0] => Array
                (
                    [success] => 
                    [message] => A variant with the given order number "1" already exists.
                    [trace] => #0 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Variant.php(427): Shopware\Components\Api\Resource\Variant->prepareData(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article), Object(Shopware\Models\Article\Detail))
#1 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Article.php(760): Shopware\Components\Api\Resource\Variant->prepareMainVariantData(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article), Object(Shopware\Models\Article\Detail))
#2 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Article.php(737): Shopware\Components\Api\Resource\Article->prepareMainDetail(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article))
#3 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Article.php(612): Shopware\Components\Api\Resource\Article->prepareAssociatedData(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article))
#4 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Resource.php(521): Shopware\Components\Api\Resource\Article->update(10, Array)
#5 C:\xampp\htdocs\shopware5\engine\Shopware\Controllers\Api\Rest.php(78): Shopware\Components\Api\Resource\Resource->batch(Array)
#6 C:\xampp\htdocs\shopware5\engine\Library\Enlight\Controller\Action.php(159): Shopware_Controllers_Api_Rest->batchAction()
#7 C:\xampp\htdocs\shopware5\engine\Library\Enlight\Controller\Dispatcher\Default.php(523): Enlight_Controller_Action->dispatch('batchAction')
#8 C:\xampp\htdocs\shopware5\engine\Library\Enlight\Controller\Front.php(223): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp))
#9 C:\xampp\htdocs\shopware5\engine\Shopware\Kernel.php(179): Enlight_Controller_Front->dispatch()
#10 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(487): Shopware\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#11 C:\xampp\htdocs\shopware5\engine\Shopware\Components\HttpCache\AppCache.php(255): Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL)
#12 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(258): Shopware\Components\HttpCache\AppCache->forward(Object(Symfony\Component\HttpFoundation\Request), true)
#13 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(275): Symfony\Component\HttpKernel\HttpCache\HttpCache->pass(Object(Symfony\Component\HttpFoundation\Request), true)
#14 C:\xampp\htdocs\shopware5\engine\Shopware\Components\HttpCache\AppCache.php(133): Symfony\Component\HttpKernel\HttpCache\HttpCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true)
#15 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(206): Shopware\Components\HttpCache\AppCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true)
#16 C:\xampp\htdocs\shopware5\engine\Shopware\Components\HttpCache\AppCache.php(114): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 C:\xampp\htdocs\shopware5\shopware.php(117): Shopware\Components\HttpCache\AppCache->handle(Object(Symfony\Component\HttpFoundation\Request))
#18 {main}
                )

            [1] => Array
                (
                    [success] => 
                    [message] => A variant with the given order number "3" already exists.
                    [trace] => #0 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Variant.php(427): Shopware\Components\Api\Resource\Variant->prepareData(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article), Object(Shopware\Models\Article\Detail))
#1 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Article.php(760): Shopware\Components\Api\Resource\Variant->prepareMainVariantData(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article), Object(Shopware\Models\Article\Detail))
#2 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Article.php(737): Shopware\Components\Api\Resource\Article->prepareMainDetail(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article))
#3 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Article.php(612): Shopware\Components\Api\Resource\Article->prepareAssociatedData(Array, Object(Shopware\Proxies\ __CG__ \Shopware\Models\Article\Article))
#4 C:\xampp\htdocs\shopware5\engine\Shopware\Components\Api\Resource\Resource.php(521): Shopware\Components\Api\Resource\Article->update(11, Array)
#5 C:\xampp\htdocs\shopware5\engine\Shopware\Controllers\Api\Rest.php(78): Shopware\Components\Api\Resource\Resource->batch(Array)
#6 C:\xampp\htdocs\shopware5\engine\Library\Enlight\Controller\Action.php(159): Shopware_Controllers_Api_Rest->batchAction()
#7 C:\xampp\htdocs\shopware5\engine\Library\Enlight\Controller\Dispatcher\Default.php(523): Enlight_Controller_Action->dispatch('batchAction')
#8 C:\xampp\htdocs\shopware5\engine\Library\Enlight\Controller\Front.php(223): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp))
#9 C:\xampp\htdocs\shopware5\engine\Shopware\Kernel.php(179): Enlight_Controller_Front->dispatch()
#10 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(487): Shopware\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#11 C:\xampp\htdocs\shopware5\engine\Shopware\Components\HttpCache\AppCache.php(255): Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL)
#12 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(258): Shopware\Components\HttpCache\AppCache->forward(Object(Symfony\Component\HttpFoundation\Request), true)
#13 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(275): Symfony\Component\HttpKernel\HttpCache\HttpCache->pass(Object(Symfony\Component\HttpFoundation\Request), true)
#14 C:\xampp\htdocs\shopware5\engine\Shopware\Components\HttpCache\AppCache.php(133): Symfony\Component\HttpKernel\HttpCache\HttpCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true)
#15 C:\xampp\htdocs\shopware5\vendor\symfony\http-kernel\HttpCache\HttpCache.php(206): Shopware\Components\HttpCache\AppCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true)
#16 C:\xampp\htdocs\shopware5\engine\Shopware\Components\HttpCache\AppCache.php(114): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 C:\xampp\htdocs\shopware5\shopware.php(117): Shopware\Components\HttpCache\AppCache->handle(Object(Symfony\Component\HttpFoundation\Request))
#18 {main}
                )

        )

)

 

Hallo,

dass ist nur lustig.

probier mal dieses Code und gib mir bescheid 

$testUpdateArray = array(
	array(
		"taxId" => 4,
		"mainDetail" => array(
			"number" => "1")
		),
	array(
		"taxId" => 4,
		"mainDetail" => array(
			"number" => "3")
		)
	);

$putBatchResponse = $shopwareClient->put("articles", $testUpdateArray);
print_r($putBatchResponse);

 

1 „Gefällt mir“

HAHAHAHAAAA! No way! Awesome Grin Works perfectly. Just because of the Quotes^^ really, that should almost be considered to be a bug. Thanks a lot!

ja lustig.

artikel nummer ist string und 1==‚1‘ => true  aber 1 === ‚1‘ => false

und sie benutzen ===

VG,

Ahmad

1 „Gefällt mir“

Wow, daran hätte ich noch Jahre gesessen. Danke dir!

Hallo,

tut mir leid das ich das Fass hier wieder aufmache, ich versteh zwar das Problem, aber ich weiß nicht wie ich es lösen soll!

Folgend baue ich meinen Array für die Call Funktion auf  

$updateArticle = array(
                array(
                    "mainDetail" => array(
                        "number" => $ergebnis[1],
                        "name" => "Artikel ".$ergebnis[1],
                    ),
                    'taxId' => 1,
                    'configuratorSet' => array(
                        'groups' => array(
                            array('name' => 'Seriennummer',
                                'options' => $options[$artikelnummer])
                        )
                    )
                )
            );

Der teil  “number” => $ergebnis[1]  erstellt ein “number” => 12345. Ich brauche aber ein  “number” => “12345”. 

 [message] =\> A variant with the given order number 12345 already exists.

Ich habe jetzt verschiedenste Wege ausprobiert den Wert umzuwandeln, aber dann krieg ich immer ein

[message] => A variant with the given order number “12345” already exists.

Weiß jemand rat?

Beste Grüße Magnum

 

Bei mir funktioniert ein Batch PUT ohne usenumberasid

Zu deinem Problem im Code:
Du solltest bei ’ oder " bleiben und diese nicht unbedingt mischen. Der Wert für „name“ ist auch nicht korrekt geschloßen.

$updateArticle = array(
                array(
                    "mainDetail" => array(
                        "number" => "' . $ergebnis[1] . '",
                        "name" => "Artikel '.$ergebnis[1].'",
                    ),
                    "taxId" => 1,
                    "configuratorSet" => array(
                        "groups" => array(
                            array("name" => "Seriennummer",
                                "options" => $options[$artikelnummer])
                        )
                    )
                )
            );

Funktioniert das PUT z.B. in Postman mit dem selben JSON-Payload?
Zu dem „A variant with the given order number…“ kann ich nur sagen das ein Hauptvarianten wechsel mit der API hier problematisch ist. Ich bin daher dazu über gegangen mir eine Dummy-Hauptvariante (immer inStock=0) zu halten die somit in den API-Calls immer konstant bleibt. Probier da mal rum mit Hauptvarianten oder nicht, bin mir sicher das es bei dir auf das selbe Problem raus läuft.

Hallo @Magnum‍,

du kannst einfach beim number die folgend code benutzen:

                        "number" => '' . $ergebnis[1],
oder:
                        "number" => (string)$ergebnis[1],

beim Name glaube ich du brauchst keine Ändernugne.

VG,

Tel.: +49 755 - 183 990 00 | Web: http://enbit.de/