megloffmegloff MitgliedKommentare: 46 Danke erhalten: 5 Mitglied seit: Mai 2015 bearbeitet August 2015
Hallo zusammen

Ich möchte ein Artikel den ich eingelesen, aktualisieren. Nun wenn ich den 1:1 mit dem Rest-API via "put" Operation (Update) zurückschreibe dann erhalte ich folgende Fehlermeldung:

{"success":false,"message":"\\Shopware\\Models\\Article\\Price by id 894 not found"}

In der DB ist aber in der Tabelle "s_articles_prices" der Eintrag 894 vorhanden und stimmt mit der Artikel ID und Artikel Detail ID überein.
- Price ID: 894
- article ID: 185
- articledetails ID: 775

Was mache ich falsch? So eine 1:1 Operation (Lesen & Update) sollte doch eigentlich gehen?

Danke für Ratschläge und Hints.

Hier noch der Price Array wie ich ihn zurückschicke:
"prices":[{"id":894,
"articleId":185,
"articleDetailsId":775,
"customerGroupKey":"EK",
"from":1,
"to":"beliebig",
"price":36.111111111111,
"pseudoPrice":0,
"basePrice":0,
"percent":0,
"customerGroup":{"id":1,
"key":"EK",
"name":"Shopkunden",
"tax":true,
"taxInput":true,
"mode":false,
"discount":0,
"minimumOrder":10,
"minimumOrderSurcharge":5}}]
Hier noch der gesamte serialisierte JSON Request:

{"id":185,"name":"Burnt T-Shirt","mainDetailId":775, "mainDetail":{"id":775,"articleId":185,"number":"SKT-AFG-2-3","kind":1,"active":true,"position":0,"minPurchase":1,"shippingFree":false, "prices":[[{"id":894,"articleId":185,"articleDetailsId":775,"customerGroupKey":"EK","from":1,"to":"beliebig","price":36.111111111111,"pseudoPrice":0,"basePrice":0,"percent":0,"customerGroup":{"id":1,"key":"EK","name":"Shopkunden","tax":true,"taxInput":true,"mode":false,"discount":0,"minimumOrder":10,"minimumOrderSurcharge":5}}], "configuratorOptions":[{"id":125,"groupId":19,"name":"Black","position":0,"option":"Black"}, {"id":127,"groupId":20,"name":"S","position":0,"option":"S"}]}, "active":true,"taxId":5, "tax":{"id":5,"tax":8.0,"name":"Standard"}, "lastStock":false, "categories":{"41":{"id":41,"name":"T-Shirts","active":true,"position":21,"parentId":40,"childrenCount":0,"articleCount":0}}, "supplierId":14, "supplier":{"id":14,"name":"Thrasher","image":"","link":"","changed":"2015-08-16T19:29:21+0200"},"filterGroupId":12,"configuratorSetId":127, "configuratorSet":{"name":"Set-SKT-AFG-2-3", "groups":[{"name":"Design","options":[{"name":"Black","group":"Design","option":"Black"}, {"name":"Charcoal","group":"Design","option":"Charcoal"}]},{"name":"Size", "options": [{"name":"S","group":"Size","option":"S"},{"name":"M","group":"Size","option":"M"}, {"name":"L","group":"Size","option":"L"}, {"name":"XL","group":"Size","option":"XL"}]}]},"propertyValues":[{"id":325,"value":"Black","position":0,"optionId":27,"valueNumeric":"0.00"}, {"id":326,"value":"S","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":327,"value":"M","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":328,"value":"L","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":329,"value":"XL","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":330,"value":"Charcoal","position":0,"optionId":27,"valueNumeric":"0.00"}], "propertyGroup":{"id":12,"name":"Standard","position":0,"comparable":false,"sortMode":0}, "descriptionLong":"<style type=\"text/css\"> <!-- span.st1 { font-family: Microsoft Sans Serif; font-size: 8pt; color: #000000; } --> </style> <p align=\"left\"><span class=\"st1\">In the original charcoal colorway, this \"throwback\" T-shirt design is a tribute to those skaters among us with a slightly more DIY approach to rolling through life. Heavyweight 100% pre-shrunk cotton T-shirt.</span></p>"}" [/code] und hier noch der Stack Trace aus dem Log file: [code] [2015-08-17 19:37:09] core.ERROR: exception 'Shopware\Components\Api\Exception\CustomValidationException' with message '\Shopware\Models\Article\Price by id 894 not found' in D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Resource.php:396 Stack trace: #0 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Variant.php(615): Shopware\Components\Api\Resource\Resource->getOneToManySubElement(Object(Doctrine\ORM\PersistentCollection), Array, '\\Shopware\\Model...') #1 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Variant.php(396): Shopware\Components\Api\Resource\Variant->preparePriceAssociation(Array, Object(Shopware\Models\Article\Article), Object(Shopware\Proxies\__CG__\Shopware\Models\Article\Detail), Object(Shopware\Models\Tax\Tax)) #2 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Variant.php(374): Shopware\Components\Api\Resource\Variant->prepareData(Array, Object(Shopware\Models\Article\Article), Object(Shopware\Proxies\__CG__\Shopware\Models\Article\Detail)) #3 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Article.php(761): Shopware\Components\Api\Resource\Variant->prepareMainVariantData(Array, Object(Shopware\Models\Article\Article), Object(Shopware\Proxies\__CG__\Shopware\Models\Article\Detail)) #4 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Article.php(738): Shopware\Components\Api\Resource\Article->prepareMainDetail(Array, Object(Shopware\Models\Article\Article)) #5 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Article.php(611): Shopware\Components\Api\Resource\Article->prepareAssociatedData(Array, Object(Shopware\Models\Article\Article)) #6 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Controllers\Api\Articles.php(116): Shopware\Components\Api\Resource\Article->update('185', Array) #7 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Library\Enlight\Controller\Action.php(159): Shopware_Controllers_Api_Articles->putAction() #8 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Library\Enlight\Controller\Dispatcher\Default.php(524): Enlight_Controller_Action->dispatch('putAction') #9 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Library\Enlight\Controller\Front.php(227): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp)) #10 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Kernel.php(143): Enlight_Controller_Front->dispatch() #11 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(490): Shopware\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #12 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\HttpCache\AppCache.php(255): Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL) #13 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(261): Shopware\Components\HttpCache\AppCache->forward(Object(Symfony\Component\HttpFoundation\Request), true) #14 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(278): Symfony\Component\HttpKernel\HttpCache\HttpCache->pass(Object(Symfony\Component\HttpFoundation\Request), true) #15 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\HttpCache\AppCache.php(133): Symfony\Component\HttpKernel\HttpCache\HttpCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true) #16 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(207): Shopware\Components\HttpCache\AppCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true) #17 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\HttpCache\AppCache.php(114): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 D:\Documents\Projects\BigPicture\Skateshop\shop\shopware.php(101): Shopware\Components\HttpCache\AppCache->handle(Object(Symfony\Component\HttpFoundation\Request)) #19 {main} [] {"uid":"0133a51"} [/code][code]{"id":185,"name":"Burnt T-Shirt","mainDetailId":775,
"mainDetail":{"id":775,"articleId":185,"number":"SKT-AFG-2-3","kind":1,"active":true,"position":0,"minPurchase":1,"shippingFree":false,
"prices":[[{"id":894,"articleId":185,"articleDetailsId":775,"customerGroupKey":"EK","from":1,"to":"beliebig","price":36.111111111111,"pseudoPrice":0,"basePrice":0,"percent":0,"customerGroup":{"id":1,"key":"EK","name":"Shopkunden","tax":true,"taxInput":true,"mode":false,"discount":0,"minimumOrder":10,"minimumOrderSurcharge":5}}],
"configuratorOptions":[{"id":125,"groupId":19,"name":"Black","position":0,"option":"Black"},
{"id":127,"groupId":20,"name":"S","position":0,"option":"S"}]},
"active":true,"taxId":5,
"tax":{"id":5,"tax":8.0,"name":"Standard"},
"lastStock":false,
"categories":{"41":{"id":41,"name":"T-Shirts","active":true,"position":21,"parentId":40,"childrenCount":0,"articleCount":0}},
"supplierId":14,
"supplier":{"id":14,"name":"Thrasher","image":"","link":"","changed":"2015-08-16T19:29:21+0200"},"filterGroupId":12,"configuratorSetId":127,
"configuratorSet":{"name":"Set-SKT-AFG-2-3",
"groups":[{"name":"Design","options":[{"name":"Black","group":"Design","option":"Black"},
{"name":"Charcoal","group":"Design","option":"Charcoal"}]},{"name":"Size",
"options":
[{"name":"S","group":"Size","option":"S"},{"name":"M","group":"Size","option":"M"}, {"name":"L","group":"Size","option":"L"}, {"name":"XL","group":"Size","option":"XL"}]}]},"propertyValues":[{"id":325,"value":"Black","position":0,"optionId":27,"valueNumeric":"0.00"}, {"id":326,"value":"S","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":327,"value":"M","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":328,"value":"L","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":329,"value":"XL","position":0,"optionId":28,"valueNumeric":"0.00"}, {"id":330,"value":"Charcoal","position":0,"optionId":27,"valueNumeric":"0.00"}], "propertyGroup":{"id":12,"name":"Standard","position":0,"comparable":false,"sortMode":0}, "descriptionLong":"<style type=\"text/css\"> <!-- span.st1 { font-family: Microsoft Sans Serif; font-size: 8pt; color: #000000; } --> </style> <p align=\"left\"><span class=\"st1\">In the original charcoal colorway, this \"throwback\" T-shirt design is a tribute to those skaters among us with a slightly more DIY approach to rolling through life. Heavyweight 100% pre-shrunk cotton T-shirt.</span></p>"}" [/code] und hier noch der Stack Trace aus dem Log file: [code] [2015-08-17 19:37:09] core.ERROR: exception 'Shopware\Components\Api\Exception\CustomValidationException' with message '\Shopware\Models\Article\Price by id 894 not found' in D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Resource.php:396 Stack trace: #0 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Variant.php(615): Shopware\Components\Api\Resource\Resource->getOneToManySubElement(Object(Doctrine\ORM\PersistentCollection), Array, '\\Shopware\\Model...') #1 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Variant.php(396): Shopware\Components\Api\Resource\Variant->preparePriceAssociation(Array, Object(Shopware\Models\Article\Article), Object(Shopware\Proxies\__CG__\Shopware\Models\Article\Detail), Object(Shopware\Models\Tax\Tax)) #2 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Variant.php(374): Shopware\Components\Api\Resource\Variant->prepareData(Array, Object(Shopware\Models\Article\Article), Object(Shopware\Proxies\__CG__\Shopware\Models\Article\Detail)) #3 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Article.php(761): Shopware\Components\Api\Resource\Variant->prepareMainVariantData(Array, Object(Shopware\Models\Article\Article), Object(Shopware\Proxies\__CG__\Shopware\Models\Article\Detail)) #4 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Article.php(738): Shopware\Components\Api\Resource\Article->prepareMainDetail(Array, Object(Shopware\Models\Article\Article)) #5 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\Api\Resource\Article.php(611): Shopware\Components\Api\Resource\Article->prepareAssociatedData(Array, Object(Shopware\Models\Article\Article)) #6 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Controllers\Api\Articles.php(116): Shopware\Components\Api\Resource\Article->update('185', Array) #7 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Library\Enlight\Controller\Action.php(159): Shopware_Controllers_Api_Articles->putAction() #8 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Library\Enlight\Controller\Dispatcher\Default.php(524): Enlight_Controller_Action->dispatch('putAction') #9 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Library\Enlight\Controller\Front.php(227): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp)) #10 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Kernel.php(143): Enlight_Controller_Front->dispatch() #11 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(490): Shopware\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #12 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\HttpCache\AppCache.php(255): Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL) #13 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(261): Shopware\Components\HttpCache\AppCache->forward(Object(Symfony\Component\HttpFoundation\Request), true) #14 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(278): Symfony\Component\HttpKernel\HttpCache\HttpCache->pass(Object(Symfony\Component\HttpFoundation\Request), true) #15 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\HttpCache\AppCache.php(133): Symfony\Component\HttpKernel\HttpCache\HttpCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true) #16 D:\Documents\Projects\BigPicture\Skateshop\shop\vendor\symfony\http-kernel\Symfony\Component\HttpKernel\HttpCache\HttpCache.php(207): Shopware\Components\HttpCache\AppCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true) #17 D:\Documents\Projects\BigPicture\Skateshop\shop\engine\Shopware\Components\HttpCache\AppCache.php(114): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 D:\Documents\Projects\BigPicture\Skateshop\shop\shopware.php(101): Shopware\Components\HttpCache\AppCache->handle(Object(Symfony\Component\HttpFoundation\Request)) #19 {main} [] {"uid":"0133a51"} [/code]

Kommentare

  • megloffmegloff MitgliedKommentare: 46 Danke erhalten: 5 Mitglied seit: Mai 2015
    Hier ein Update: Nach längerer Zeit PHP Debuggen bin ich auf eine Zeile gestossen die den "Prices" Array des Artikels löscht bevor die übermittelten Preise darin gesucht werden. Funktion "checkDataReplacement"

    Warum dies gemacht wird weiss ich nicht, hier die Original Zeile. Meine erste Behauptung es muss sich um einen Bug handeln.

    Shopware\Components\Api\Resource\Variant.preparePriceAssociation() - Zeile 605
    /**
         * @param $data
         * @param \Shopware\Models\Article\Article $article
         * @param \Shopware\Models\Article\Detail $variant
         * @param \Shopware\Models\Tax\Tax $tax
         * @throws \Shopware\Components\Api\Exception\CustomValidationException
         * @return array
         */
        protected function preparePriceAssociation($data, ArticleModel $article, Detail $variant, Tax $tax)
        {
            $prices = $this->checkDataReplacement($variant->getPrices(), $data, 'prices', true);
      
    
            foreach ($data['prices'] as &$priceData) {
                /**@var $price Price*/
                $price = $this->getOneToManySubElement(
                    $prices,
                    $priceData,
                    '\Shopware\Models\Article\Price'
                );
    ...
    
    checkDataReplacement: Helper function which checks the option configuration for the passed collection. If the data property contains the "__options_$optionName" value and this value contains the "replace" parameter the collection will be cleared.

    Wie meldet Ihr Bugs an das Shopware Team eigentlich? Gibt es irgendow eine Art Bugzilla oder JIRA page um diese zu submitten?

    Ich habe mal provisorisch die Zeile bei mir ersetzt mit :
            //$prices = $this->checkDataReplacement($variant->getPrices(), $data, 'prices', true)
    
            $prices = $variant->getPrices();
    
    
    Danach hat das Update funktioniert. Natürlich ohne Gewähr ob das so richtig ist. Aber vielleicht kann hier einer der erfahrener Programmierer Auskunft geben wie es angedacht ist Preise bei einem Update zu übermitteln.
  • Heiner LohausHeiner Lohaus MitgliedKommentare: 933 Danke erhalten: 266 Mitglied seit: Juni 2010
    Hi,

    das ist kein Bug. Du übergibst die Preise mit einer ID:
    "prices":[[{"id":894,
    
    Wäre es aber ein Bug, könntest du hier ein Ticket anlegen:

    http://jira.shopware.de

    Gruß Heiner
  • megloffmegloff MitgliedKommentare: 46 Danke erhalten: 5 Mitglied seit: Mai 2015
    Danke Heiner.

    Mit anderen Worten man darf bei den Preisen keine Id bei einem update (put) übergeben. Das fuktioniert, habe ich nun getestet.

    Trotzdem würde ich allgemein erwarten, dass was ich mit lese (get) auch wieder 1:1 wieder schreiben kann ( put). Auch wird hier bei der Beschreibung der Struktur zumindest beim post die Id aufgeführt ;). Ist natürlich Ansichtssache, ob es nun ein "Bug" ist oder nicht. Hauptsache es funktoniert nun für mich.

    http://community.shopware.com/REST-API- ... ml#Price_2

    Danke trotzdem

    Gruss
    Mark
Anmelden oder Registrieren, um zu kommentieren.