예제 #1
0
 /**
  * Creates a new tax struct and assigns the passed
  * data array.
  *
  * @param array $data
  * @return \Shopware\Bundle\StoreFrontBundle\Struct\Tax
  */
 public function hydrateRule(array $data)
 {
     $tax = new Struct\Tax();
     $tax->setId((int) $data['__taxRule_groupID']);
     $tax->setName($data['__taxRule_name']);
     $tax->setTax((double) $data['__taxRule_tax']);
     return $tax;
 }
예제 #2
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;
 }
 /**
  * Helper function which calculates a single price value.
  * The function subtracts the percentage customer group discount if
  * it should be considered and decides over the global state if the
  * price should be calculated gross or net.
  * The function is used for the original price value of a price struct
  * and the pseudo price of a price struct.
  *
  * @param $price
  * @param Struct\Tax $tax
  * @param Struct\ProductContextInterface $context
  * @return float
  */
 private function calculatePrice($price, Struct\Tax $tax, Struct\ProductContextInterface $context)
 {
     /**
      * Important:
      * We have to use the current customer group of the current user
      * and not the customer group of the price.
      *
      * The price could be a price of the fallback customer group
      * but the discounts and gross calculation should be used from
      * the current customer group!
      */
     $customerGroup = $context->getCurrentCustomerGroup();
     /**
      * Basket discount calculation:
      *
      * Check if a global basket discount is configured and reduce the price
      * by the percentage discount value of the current customer group.
      */
     if ($customerGroup->useDiscount() && $customerGroup->getPercentageDiscount()) {
         if ($customerGroup->getPercentageDiscount() != 0) {
             $price = $price - $price / 100 * $customerGroup->getPercentageDiscount();
         } else {
             $price = 0;
         }
     }
     /**
      * Currency calculation:
      * If the customer is currently in a sub shop with another currency, like dollar,
      * we have to calculate the the price for the other currency.
      */
     $price = $price * $context->getCurrency()->getFactor();
     /**
      * check if the customer group should see gross prices.
      */
     if (!$customerGroup->displayGrossPrices()) {
         return round($price, 3);
     }
     /**
      * Gross calculation:
      *
      * This line contains the gross price calculation within the store front.
      *
      * The passed $context object contains a calculated Struct\Tax object which
      * defines which tax rules should be used for the tax calculation.
      *
      * The tax rules can be defined individual for each customer group and
      * individual for each area, country and state.
      *
      * For example:
      *  - The EK customer group has different configured HIGH-TAX rules.
      *  - In area Europe, in country Germany the global tax value are set to 19%
      *  - But in area Europe, in country Germany, in state Bayern, the tax value are set to 20%
      *  - But in area Europe, in country Germany, in state Berlin, the tax value are set to 18%
      */
     $price = $price * (100 + $tax->getTax()) / 100;
     return round($price, 3);
 }