Ejemplo n.º 1
0
 /**
  * @param Models\Tax\Tax $tax
  * @return Struct\Tax
  */
 public function convertTax(Models\Tax\Tax $tax)
 {
     $struct = new Struct\Tax();
     $struct->setId($tax->getId());
     $struct->setTax($tax->getTax());
     $struct->setName($tax->getName());
     return $struct;
 }
Ejemplo n.º 2
0
 /**
  * Prepares variant prices according to the price variation rules
  * Returns prices array
  *
  * @param array $detailData
  * @param array $priceVariations
  * @param array $optionIds
  * @param \Shopware\Models\Tax\Tax $tax
  * @return array
  */
 protected function prepareVariantPrice($detailData, $priceVariations, $optionIds, $tax)
 {
     $totalPriceVariationValue = 0;
     foreach ($priceVariations as $priceVariation) {
         $priceVariation['options'] = explode('|', trim($priceVariation['options'], '|'));
         $optionsDiff = array_diff($priceVariation['options'], $optionIds);
         if (!empty($optionsDiff)) {
             continue;
         }
         $priceVariationValue = $priceVariation['variation'];
         if ($priceVariation['isGross'] == 1) {
             $taxValue = (double) $tax->getTax();
             $priceVariationValue /= ($taxValue + 100) / 100;
         }
         $totalPriceVariationValue += $priceVariationValue;
     }
     foreach ($detailData['prices'] as $key => &$configuratorPrice) {
         $calculatedPrice = $configuratorPrice['price'] + $totalPriceVariationValue;
         $configuratorPrice['price'] = max($calculatedPrice, 0.01);
     }
     return $detailData['prices'];
 }
Ejemplo n.º 3
0
    /**
     * @param array $prices
     * @param \Shopware\Models\Article\Article $article
     * @param \Shopware\Models\Article\Detail $articleDetail
     * @param \Shopware\Models\Tax\Tax $tax
     * @throws \Shopware\Components\Api\Exception\CustomValidationException
     * @return array
     */
    protected function preparePricesAssociatedData($prices, ArticleModel $article, $articleDetail, \Shopware\Models\Tax\Tax $tax)
    {
        foreach ($prices as &$priceData) {

            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 \Shopware\Models\Customer\Group $customerGroup */
            if (!$customerGroup instanceof \Shopware\Models\Customer\Group) {
                throw new ApiException\CustomValidationException(sprintf('Customer Group by key %s not found', $priceData['customerGroupKey']));
            }

            if (!isset($priceData['from'])) {
                $priceData['from'] = 1;
            }

            $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['articleDetail'] = $articleDetail;
        }

        return $prices;
    }
Ejemplo n.º 4
0
 /**
  * Calculate the Price
  *
  * @param Tax $tax
  * @param $product
  * @return float
  */
 private function calculatePrice(Tax $tax, $product)
 {
     $price = empty($product->netPrice) ? 1.0E-8 : $product->netPrice;
     $price *= ($tax->getTax() + 100) / 100;
     return $price;
 }
Ejemplo n.º 5
0
 /**
  * @param array $data
  * @param \Shopware\Models\Tax\Tax $model
  */
 private function saveTaxRules(array $data, \Shopware\Models\Tax\Tax $model)
 {
     if (isset($data['rules'])) {
         $model->getRules()->clear();
         $rules = array();
         foreach ($data['rules'] as $ruleData) {
             $rule = new Shopware\Models\Tax\Rule();
             $rule->fromArray($ruleData);
             $rule->setGroup($model);
             $rules[] = $rule;
         }
         $data['rules'] = $rules;
         $model->fromArray($data);
         $this->getModelManager()->persist($model);
         $this->getModelManager()->flush();
     }
     $this->View()->assign(array('success' => true));
 }
Ejemplo n.º 6
0
 public function createTax($data = array())
 {
     $data = array_merge(array('tax' => 19.0, 'name' => 'PHP UNIT'), $data);
     $this->deleteTax($data['name']);
     $tax = new Models\Tax\Tax();
     $tax->fromArray($data);
     $this->entityManager->persist($tax);
     $this->entityManager->flush();
     $this->entityManager->clear();
     $this->createdTaxes[] = $data['name'];
     return $tax;
 }
Ejemplo n.º 7
0
 /**
  * @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 setManyToOne($data, $model, $property)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setManyToOne', array($data, $model, $property));
     return parent::setManyToOne($data, $model, $property);
 }