/** * @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'); if (empty($priceData['customerGroupKey'])) { $priceData['customerGroupKey'] = 'EK'; } // load the customer group of the price definition $customerGroup = $this->getManager()->getRepository('Shopware\\Models\\Customer\\Group')->findOneBy(array('key' => $priceData['customerGroupKey'])); /** @var CustomerGroup $customerGroup */ if (!$customerGroup instanceof CustomerGroup) { throw new ApiException\CustomValidationException(sprintf('Customer Group by key %s not found', $priceData['customerGroupKey'])); } // setup default values $priceData += array('price' => 0, 'basePrice' => 0, 'pseudoPrice' => 0, 'percent' => 0, 'from' => '1', 'to' => 'beliebig'); $priceData['from'] = intval($priceData['from']); $priceData['to'] = intval($priceData['to']); if ($priceData['from'] <= 0) { throw new ApiException\CustomValidationException(sprintf('Invalid Price "from" value')); } // if the "to" value isn't numeric, set the place holder "beliebig" if ($priceData['to'] <= 0) { $priceData['to'] = 'beliebig'; } $priceData['price'] = floatval(str_replace(",", ".", $priceData['price'])); $priceData['basePrice'] = floatval(str_replace(",", ".", $priceData['basePrice'])); $priceData['pseudoPrice'] = floatval(str_replace(",", ".", $priceData['pseudoPrice'])); $priceData['percent'] = floatval(str_replace(",", ".", $priceData['percent'])); if ($customerGroup->getTaxInput()) { $priceData['price'] = $priceData['price'] / (100 + $tax->getTax()) * 100; $priceData['pseudoPrice'] = $priceData['pseudoPrice'] / (100 + $tax->getTax()) * 100; } $priceData['customerGroup'] = $customerGroup; $priceData['article'] = $article; $priceData['detail'] = $variant; $price->fromArray($priceData); } return $prices; }
/** * {@inheritDoc} */ public function getPrices() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getPrices', array()); return parent::getPrices(); }
/** * @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'); if (empty($priceData['customerGroupKey'])) { $priceData['customerGroupKey'] = 'EK'; } if (empty($priceData['from']) && $price->getFrom() == 0) { $priceData['from'] = 1; } // load the customer group of the price definition $customerGroup = $this->getManager()->getRepository('Shopware\\Models\\Customer\\Group')->findOneBy(array('key' => $priceData['customerGroupKey'])); /** @var CustomerGroup $customerGroup */ if (!$customerGroup instanceof CustomerGroup) { throw new ApiException\CustomValidationException(sprintf('Customer Group by key %s not found', $priceData['customerGroupKey'])); } $priceData['customerGroup'] = $customerGroup; $priceData['article'] = $article; $priceData['detail'] = $variant; $priceData = $this->mergePriceData($priceData, $tax); $price->fromArray($priceData); } return $prices; }