Example #1
0
 /**
  * Returns tax rates for all basket positions
  *
  * @param unknown_type $basket array returned from this->getBasket
  * @return array
  */
 public function getTaxRates($basket)
 {
     $result = array();
     if (!empty($basket['sShippingcostsTax'])) {
         $basket['sShippingcostsTax'] = number_format(floatval($basket['sShippingcostsTax']), 2);
         $result[$basket['sShippingcostsTax']] = $basket['sShippingcostsWithTax'] - $basket['sShippingcostsNet'];
         if (empty($result[$basket['sShippingcostsTax']])) {
             unset($result[$basket['sShippingcostsTax']]);
         }
     } elseif ($basket['sShippingcostsWithTax']) {
         $result[number_format(floatval(Shopware()->Config()->get('sTAXSHIPPING')), 2)] = $basket['sShippingcostsWithTax'] - $basket['sShippingcostsNet'];
         if (empty($result[number_format(floatval(Shopware()->Config()->get('sTAXSHIPPING')), 2)])) {
             unset($result[number_format(floatval(Shopware()->Config()->get('sTAXSHIPPING')), 2)]);
         }
     }
     if (empty($basket['content'])) {
         ksort($result, SORT_NUMERIC);
         return $result;
     }
     foreach ($basket['content'] as $item) {
         if (!empty($item["tax_rate"])) {
         } elseif (!empty($item['taxPercent'])) {
             $item['tax_rate'] = $item["taxPercent"];
         } elseif ($item['modus'] == 2) {
             // Ticket 4842 - dynamic tax-rates
             $resultVoucherTaxMode = Shopware()->Db()->fetchOne("SELECT taxconfig FROM s_emarketing_vouchers WHERE ordercode=?\n                ", array($item["ordernumber"]));
             // Old behaviour
             if (empty($resultVoucherTaxMode) || $resultVoucherTaxMode == "default") {
                 $tax = Shopware()->Config()->get('sVOUCHERTAX');
             } elseif ($resultVoucherTaxMode == "auto") {
                 // Automatically determinate tax
                 $tax = $this->basket->getMaxTax();
             } elseif ($resultVoucherTaxMode == "none") {
                 // No tax
                 $tax = "0";
             } elseif (intval($resultVoucherTaxMode)) {
                 // Fix defined tax
                 $tax = Shopware()->Db()->fetchOne("\n                    SELECT tax FROM s_core_tax WHERE id = ?\n                    ", array($resultVoucherTaxMode));
             }
             $item['tax_rate'] = $tax;
         } else {
             // Ticket 4842 - dynamic tax-rates
             $taxAutoMode = Shopware()->Config()->get('sTAXAUTOMODE');
             if (!empty($taxAutoMode)) {
                 $tax = $this->basket->getMaxTax();
             } else {
                 $tax = Shopware()->Config()->get('sDISCOUNTTAX');
             }
             $item['tax_rate'] = $tax;
         }
         if (empty($item['tax_rate']) || empty($item["tax"])) {
             continue;
         }
         // Ignore 0 % tax
         $taxKey = number_format(floatval($item['tax_rate']), 2);
         $result[$taxKey] += str_replace(',', '.', $item['tax']);
     }
     ksort($result, SORT_NUMERIC);
     return $result;
 }
Example #2
0
 /**
  * @covers sBasket::getMaxTax
  */
 public function testGetMaxTax()
 {
     // Test with empty session, expect false
     $this->assertFalse($this->module->getMaxTax());
     // Create session id
     $this->module->sSYSTEM->sSESSION_ID = uniqid();
     $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID);
     // Test with session and empty basket, expect false
     $this->assertFalse($this->module->getMaxTax());
     $randomArticle = $this->db->fetchRow('SELECT * FROM s_articles_details detail
         INNER JOIN s_articles article
           ON article.id = detail.articleID
         WHERE detail.active = 1
         ORDER BY RAND() LIMIT 1');
     $randOne = rand(1, 100);
     $randTwo = rand(1, 100);
     // Add one article, check that he is the new maximum
     $this->db->insert('s_order_basket', array('price' => 100, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticle['ordernumber'], 'articleID' => $randomArticle['articleID'], 'tax_rate' => $randOne));
     $this->assertEquals($randOne, $this->module->getMaxTax());
     // Add another article, check that we get the max of the two
     $this->db->insert('s_order_basket', array('price' => 100, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticle['ordernumber'], 'articleID' => $randomArticle['articleID'], 'tax_rate' => $randTwo));
     $this->assertEquals(max($randOne, $randTwo), $this->module->getMaxTax());
     // Housekeeping
     $this->db->delete('s_order_basket', array('sessionID = ?' => $this->session->get('sessionId')));
 }