ShopwareAG/shopware-4 — pull request #172 by FiveDigital (2014-08-15 09:07:13+00:00)
Title: Update Resource.php

Changed type hinting from concrete class Doctrine\Common\Collections\ArrayCollection to interface Doctrine\Common\Collections\Collection because of problems when using API locally.

I ran into the following error when using the API locally to update prices:

`Catchable fatal error: Argument 1 passed to Shopware\Components\Api\Resource\Resource::checkDataReplacement() must be an instance of Doctrine\Common\Collections\ArrayCollection, instance of Doctrine\ORM\PersistentCollection given, called in /var/www/htdocs/engine/Shopware/Components/Api/Resource/Variant.php on line 592 and defined in /var/www/htdocs/engine/Shopware/Components/Api/Resource/Resource.php on line 276`

An update without prices was no problem at all. After some googleing I found out that this is a common doctrine error and the solution always was to change type hinting to the interface. After changing the type hinting the product got updated with correct prices.

The code causing this error is the following (`$data` come from a CSV file provided by our customer):

```php
$number = $data['ReferenzNr'];
$price = doubleval($data['VK']);
$specialPrice = doubleval($data['VKShop']);

$params = array(
'name' => $data['Beschreibung'],
'description' => $data['Bemerkungen'],
'active' => true,
'supplier' => $data['Hersteller'],
'mainDetail' => array(
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => $specialPrice > 0 ? $specialPrice : $price,
'pseudoPrice' => $specialPrice > 0 ? $price : '',
'from' => 1,
)
)
)
);

try {
$article = $this->articleResource->updateByNumber($number, $params);
} catch(\Exception $e) {
$this->output(sprintf("Cannot update article %s: %s", $number, $e->getMessage()));
}
```