Example #1
0
File: Rate.php Project: 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');
 }
Example #2
0
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     $newMethod = new \XLite\Model\Shipping\Method();
     $newMethod->setName('Test');
     $newMethod->setProcessor('offline');
     $newMethod->setCarrier('ups');
     $newMethod->setEnabled(1);
     $newMethod->setPosition(888);
     \XLite\Core\Database::getEM()->persist($newMethod);
     \XLite\Core\Database::getEM()->flush();
     $methodId = $newMethod->getMethodId();
     $this->assertTrue(isset($methodId), 'Object could not be created');
     if (isset($methodId)) {
         $method = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->find($methodId);
         $this->assertEquals('Test', $method->getName(), 'Wrong method name');
         $this->assertEquals('offline', $method->getProcessor(), 'Wrong processor');
         $this->assertEquals('ups', $method->getCarrier(), 'Wrong carrier');
         $this->assertEquals(1, $method->getEnabled(), 'Wrong status');
         $this->assertEquals(888, $method->getPosition(), 'Wrong position');
     }
 }
Example #3
0
 /**
  * Create shipping method
  *
  * @param array $data Shipping method data
  *
  * @return \XLite\Model\Shipping\Method
  */
 public function createShippingMethod($data)
 {
     // Array of allowed fields and flag required/optional
     $fields = $this->getAllowedFields();
     $errorFields = array();
     foreach ($fields as $field => $required) {
         if (isset($data[$field])) {
             $fields[$field] = $data[$field];
         } elseif ($required) {
             $errorFields[] = $field;
         }
     }
     if (!empty($errorFields)) {
         throw new \Exception('createShippingMethod() failed: The following required fields are missed: ' . implode(', ', $errorFields));
     }
     $method = $this->findMethodToUpdate($fields);
     if ($method) {
         $this->update($method, $fields);
     } else {
         $method = new \XLite\Model\Shipping\Method();
         $method->map($fields);
         $method = $this->insert($method);
     }
     return $method;
 }
Example #4
0
 /**
  * Create shipping method
  *
  * @param array $data Shipping method data
  *
  * @return \XLite\Model\Shipping\Method
  */
 public function createShippingMethod($data)
 {
     // Array of allowed fields and flag required/optional
     $fields = array('processor' => 1, 'carrier' => 1, 'code' => 1, 'enabled' => 0, 'position' => 0, 'name' => 1);
     $errorFields = array();
     foreach ($fields as $field => $required) {
         if (isset($data[$field])) {
             $fields[$field] = $data[$field];
         } elseif ($required) {
             $errorFields[] = $field;
         }
     }
     if (!empty($errorFields)) {
         throw new \Exception('createShippingMethod() failed: The following required fields are missed: ' . implode(', ', $errorFields));
     }
     $method = $this->findOneBy(array('processor' => $fields['processor'], 'code' => $fields['code']));
     if ($method) {
         $this->update($method, $fields);
     } else {
         $method = new \XLite\Model\Shipping\Method();
         $method->map($fields);
         $method = $this->insert($method);
     }
     return $method;
 }
Example #5
0
 /**
  * Add shipping method to the database
  *
  * @param array $postage Array of data for shipping method
  *
  * @return void
  */
 protected function addShippingMethod($postage)
 {
     $method = null;
     // Check if method has alreaby been added in current session to prevent duplicates
     if (!in_array($postage['CLASSID'], $this->newMethods)) {
         $lastMethod = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->findOneMaxPositionByProcessor($this->getProcessorId());
         $method = new \XLite\Model\Shipping\Method();
         $method->setProcessor($this->getProcessorId());
         $method->setCarrier($this->getProcessorId());
         $method->setCode($postage['CLASSID']);
         $method->setEnabled(\XLite\Core\Config::getInstance()->CDev->USPS->autoenable_new_methods);
         $method->setName($postage['MailService']);
         if ($lastMethod) {
             $method->setPosition($lastMethod->getPosition() + 1);
         }
         \XLite\Core\Database::getEM()->persist($method);
         \XLite\Core\Database::getEM()->flush();
         $this->newMethods[] = $postage['CLASSID'];
     }
     return $method;
 }
Example #6
0
 /**
  * add new shipping method to DB
  * 
  * @param array method attributes
  *
  * @return void
  */
 protected function addShippingMethod($service)
 {
     // Check if method has already been added in current session to prevent duplicates
     if (!in_array($service['service_code'], $this->newMethods)) {
         $method = new \XLite\Model\Shipping\Method();
         $method->setProcessor($this->getProcessorId());
         $method->setCarrier($this->getProcessorId());
         $method->setCode($service['service_code']);
         $method->setEnabled(false);
         $method->setName($service['service_name']);
         \XLite\Core\Database::getEM()->persist($method);
         \XLite\Core\Database::getEM()->flush();
         $this->newMethods[] = $service['service_code'];
     }
 }