Ejemplo n.º 1
0
Archivo: Rate.php Proyecto: kingsj/core
 public function testGetTotalRate()
 {
     $tax = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VAT\\Model\\Tax')->getTax();
     foreach ($tax->getRates() as $rate) {
         \XLite\Core\Database::getEM()->remove($rate);
     }
     $tax->getRates()->clear();
     $tax->setEnabled(true);
     $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
     $rate->setValue(10);
     $rate->setPosition(1);
     \XLite\Core\Database::getEM()->persist($rate);
     $tax->addRates($rate);
     $rate->setTax($tax);
     $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
     $rate->setValue(20);
     $rate->setPosition(0);
     \XLite\Core\Database::getEM()->persist($rate);
     $tax->addRates($rate);
     $rate->setTax($tax);
     $memberships = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->findAll();
     $membership = array_shift($memberships);
     $rate->setMembership($membership);
     $tax->setVATMembership($membership);
     \XLite\Core\Database::getEM()->flush();
     $method = new \XLite\Model\Shipping\Method();
     $method->setEnabled(true);
     $rate = new \XLite\Model\Shipping\Rate();
     $rate->setBaseRate(10);
     $rate->setMarkupRate(10);
     $rate->setMethod($method);
     $this->assertEquals(16.67, \XLite::getInstance()->getCurrency()->formatValue($rate->getTotalRate()), 'check cost');
 }
Ejemplo n.º 2
0
 public function testSearchByPrice()
 {
     $tax = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VAT\\Model\\Tax')->getTax();
     foreach ($tax->getRates() as $rate) {
         \XLite\Core\Database::getEM()->remove($rate);
     }
     $tax->getRates()->clear();
     $tax->setEnabled(true);
     $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
     $rate->setValue(10);
     $rate->setPosition(1);
     \XLite\Core\Database::getEM()->persist($rate);
     $tax->addRates($rate);
     $rate->setTax($tax);
     \XLite\Core\Database::getEM()->flush();
     $memberships = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->findAll();
     $membership = array_shift($memberships);
     $rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
     $rate->setValue(20);
     $rate->setPosition(0);
     $rate->setMembership($membership);
     $rate->setTax($tax);
     $tax->setVATMembership($membership);
     $tax->addRates($rate);
     \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VAT\\Model\\Tax\\Rate')->insert($rate);
     \XLite\Module\CDev\VAT\Logic\Product\Tax::resetInstance();
     $cnd = new \XLite\Core\CommonCell(array(\XLite\Model\Repo\Product::P_PRICE => array(1, 2)));
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(2, count($result), 'check count');
     $result[0]->setPrice(1.01);
     \XLite\Core\Database::getEM()->flush();
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(1, count($result), 'check count #2');
     $rate->setPosition(2);
     \XLite\Core\Database::getEM()->flush();
     \XLite\Module\CDev\VAT\Logic\Product\Tax::resetInstance();
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(3, count($result), 'check count #3');
     $result[0]->setPrice(1);
     \XLite\Core\Database::getEM()->flush();
     $result = \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->search($cnd);
     $this->assertEquals(2, count($result), 'check count #4');
 }