예제 #1
0
파일: Country.php 프로젝트: kingsj/core
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     $c = new \XLite\Model\Country();
     foreach ($this->entityData as $field => $testValue) {
         $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $c->{$setterMethod}($testValue);
         $value = $c->{$getterMethod}();
         $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')');
     }
     $s = new \XLite\Model\State();
     $s->setState('test state');
     $s->setCode('ttt');
     $c->addStates($s);
     $em = \XLite\Core\Database::getEM();
     $em->persist($c);
     $em->flush();
     $em->clear();
     $c = \XLite\Core\Database::getEM()->merge($c);
     foreach ($this->entityData as $field => $testValue) {
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $this->assertEquals($testValue, $c->{$getterMethod}(), 'Creation checking (' . $field . ') #2');
     }
     $this->assertEquals($s->getStateId(), $c->getStates()->get(0)->getStateId(), 'check state');
     $em->remove($c);
     $em->flush();
 }
예제 #2
0
 /**
  * Get field value
  *
  * @param string  $fieldName    Field name
  * @param boolean $processValue Process value flag OPTIONAL
  *
  * @return string
  */
 public function getFieldValue($fieldName, $processValue = false)
 {
     $result = '';
     $address = $this->getAddressInfo();
     if ($this->getCart() && $this->getCart()->getProfile() && 'email' == $fieldName) {
         $result = $this->getCart()->getProfile()->getLogin();
     } elseif ($this->getCart() && $this->getCart()->getProfile() && 'password' == $fieldName) {
         $result = \XLite\Core\Session::getInstance()->createProfilePassword;
     } elseif (isset($address)) {
         $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($fieldName);
         // $methodName assembled from 'get' + camelized $fieldName
         $result = $address->{$methodName}();
         if ($result && false !== $processValue) {
             switch ($fieldName) {
                 case 'state_id':
                     $result = $address->getCountry()->hasStates() ? $address->getState()->getState() : null;
                     break;
                 case 'custom_state':
                     $result = $address->getCountry()->hasStates() ? null : $result;
                     break;
                 case 'country_code':
                     $result = $address->getCountry()->getCountry();
                     break;
                 case 'type':
                     $result = $address->getTypeName();
                     break;
                 default:
             }
         }
     } elseif (in_array($fieldName, array('country_code', 'state_id', 'custom_state', 'zipcode'))) {
         $result = \XLite\Model\Address::getDefaultFieldPlainValue($fieldName);
     }
     return $result;
 }
예제 #3
0
파일: Category.php 프로젝트: kingsj/core
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     $c = new \XLite\Model\Category();
     foreach ($this->categoryData as $field => $testValue) {
         $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $c->{$setterMethod}($testValue);
         $value = $c->{$getterMethod}();
         $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')');
     }
     $qf = new \XLite\Model\Category\QuickFlags();
     $qf->setCategory($c);
     $c->setQuickFlags($qf);
     $this->assertEquals($qf, $c->getQuickFlags(), 'test quick flags');
     $m = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->findAll();
     $c->setMembership($m[0]);
     $this->assertEquals($m[0], $c->getMembership(), 'check membership');
     $i = new \XLite\Model\Image\Category\Image();
     $c->setImage($i);
     $this->assertEquals($i, $c->getImage(), 'check image');
     $cp = new \XLite\Model\CategoryProducts();
     $c->addCategoryProducts($cp);
     $this->assertEquals($cp, $c->getCategoryProducts()->get(0), 'check category products');
     $this->assertEquals(1, count($c->getCategoryProducts()), 'check category products length');
     $child = new \XLite\Model\Category();
     $c->addChildren($child);
     $child->setParent($c);
     $this->assertEquals($child, $c->getChildren()->get(0), 'check childs');
     $this->assertEquals(1, count($c->getChildren()), 'check childs length');
     $this->assertEquals($c, $child->getParent(), 'check parent');
 }
예제 #4
0
파일: Order.php 프로젝트: kirkbauer2/kirkxc
 /**
  * Return the current page title (for the content area)
  *
  * @return string
  */
 public function getTitle()
 {
     if ($this->checkAccess()) {
         $title = static::t('Order #X, Y', array('id' => $this->getOrderNumber(), 'date' => \XLite\Core\Converter::getInstance()->formatTime($this->getOrder()->getDate())));
     } else {
         $title = static::t('Order not found');
     }
     return $title;
 }
예제 #5
0
파일: Membership.php 프로젝트: kingsj/core
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     $c = new \XLite\Model\Membership();
     foreach ($this->entityData as $field => $testValue) {
         $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $c->{$setterMethod}($testValue);
         $value = $c->{$getterMethod}();
         $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')');
     }
 }
예제 #6
0
파일: ViewList.php 프로젝트: kingsj/core
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     $c = new \XLite\Model\ViewList();
     foreach ($this->entityData as $field => $testValue) {
         $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $c->{$setterMethod}($testValue);
         $value = $c->{$getterMethod}();
         $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')');
     }
     \XLite\Core\Database::getEM()->persist($c);
     \XLite\Core\Database::getEM()->flush();
     $this->assertTrue(0 < $c->getListId(), 'check list id');
     \XLite\Core\Database::getEM()->remove($c);
     \XLite\Core\Database::getEM()->flush();
 }
예제 #7
0
파일: Parameter.php 프로젝트: kingsj/core
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.17
  */
 public function testCreate()
 {
     $p = new \XLite\Model\DataSource\Parameter();
     foreach ($this->entityData as $field => $testValue) {
         $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $p->{$setterMethod}($testValue);
         $value = $p->{$getterMethod}();
         $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')');
     }
     $em = \XLite\Core\Database::getEM();
     $em->persist($p);
     $em->flush();
     $this->assertTrue(0 < $p->getId(), 'check parameter id');
     $em->remove($p);
     $em->flush();
 }
예제 #8
0
파일: Address.php 프로젝트: kingsj/core
 /**
  * getFieldValue
  *
  * @param string  $fieldName    Field name
  * @param boolean $processValue Process value flag OPTIONAL
  *
  * @return string
  */
 public function getFieldValue($fieldName, $processValue = false)
 {
     $result = '';
     $address = $this->getParam(self::PARAM_ADDRESS);
     $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($fieldName);
     if (method_exists($address, $methodName)) {
         // $methodName assembled from 'get' + camelized $fieldName
         $result = $address->{$methodName}();
         if (false !== $processValue) {
             switch ($fieldName) {
                 case 'state_id':
                     $result = $address->getState()->getState();
                     break;
                 case 'country_code':
                     $result = $address->getCountry()->getCountry();
                     break;
                 default:
             }
         }
     }
     return $result;
 }
예제 #9
0
파일: Address.php 프로젝트: kingsj/core
 public function testCheckAddress()
 {
     // Prepare address and save it in database
     $origAddress = new \XLite\Model\Address();
     $origAddress->map($this->addressFields);
     $origAddress->setState(\XLite\Core\Database::getRepo('XLite\\Model\\State')->findOneByCountryAndCode('US', 'NY'));
     $origAddress->setCountry(\XLite\Core\Database::getRepo('XLite\\Model\\Country')->find('US'));
     $origAddress->setProfile(\XLite\Core\Database::getRepo('XLite\\Model\\Profile')->find(1));
     $address = $origAddress->cloneEntity();
     $origAddress->create();
     // Test: new address should not be created as it is identical
     $this->assertFalse($address->create(), "Check that address is not created (all fields are identical)");
     foreach (\XLite\Model\Address::getAddressFields() as $field) {
         $address = $origAddress->cloneEntity();
         if ('state_id' == $field) {
             $address->setState(\XLite\Core\Database::getRepo('XLite\\Model\\State')->findOneByCountryAndCode('US', 'CA'));
         } elseif ('country_code' == $field) {
             $address->setCountry(\XLite\Core\Database::getRepo('XLite\\Model\\Country')->find('GB'));
         } elseif ('custom_state' != $field) {
             $address->map($this->addressFields);
             $methodName = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
             $this->assertTrue(method_exists($address, $methodName), "Check if method exists ({$methodName})");
             $modifiedField = $this->addressFields[$field] . '2';
             $address->{$methodName}($modifiedField);
         }
         // Test: new address must be created as one of fields is modified
         $this->assertTrue($address->create(), "Check if address is created ({$field})");
     }
 }
예제 #10
0
파일: Invoice.php 프로젝트: kingsj/core
 /**
  * Return the current page title (for the content area)
  *
  * @return string
  */
 public function getTitle()
 {
     return static::t('Invoice #{{orderId}}, {{time}}', array('orderId' => $this->getOrderId(), 'time' => \XLite\Core\Converter::getInstance()->formatTime($this->getOrder()->getDate())));
 }
예제 #11
0
 /**
  * Preprocess "date" field
  *
  * @param integer                                          $date   Date
  * @param array                                            $column Column data
  * @param \XLite\Module\XC\CanadaPost\Model\ProductsReturn $entity Canada Post return model
  *
  * @return string
  */
 protected function preprocessDate($date, array $column, \XLite\Module\XC\CanadaPost\Model\ProductsReturn $entity)
 {
     return $date ? \XLite\Core\Converter::getInstance()->formatTime($date) : static::t('Unknown');
 }
예제 #12
0
파일: Address.php 프로젝트: kingsj/core
 /**
  * defineFindSameAddressQuery
  *
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function defineFindSameAddressQuery($address)
 {
     $params = array();
     $qb = $this->createQueryBuilder();
     $qb->innerJoin('a.profile', 'p')->andWhere('p.profile_id = :profile_id');
     $params['profile_id'] = $address->getProfile()->getProfileId();
     if ($address->getAddressId()) {
         $qb->andWhere($qb->expr()->not('a.address_id = :address_id'));
         $params['address_id'] = $address->getAddressId();
     }
     $fields = $address->getAddressFields();
     foreach ($fields as $field) {
         if ('state_id' == $field) {
             if ($address->getStateId()) {
                 $qb->innerJoin('a.state', 's')->andWhere('s.state_id = :state_id');
                 $params[$field] = $address->getStateId();
             } else {
                 $qb->leftJoin('a.state', 's')->andWhere('s.state_id IS NULL');
             }
         } elseif ('country_code' == $field) {
             $qb->innerJoin('a.country', 'c')->andWhere('c.code = :country_code');
             $params[$field] = $address->getCountryCode();
         } else {
             $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
             if (method_exists($address, $methodName)) {
                 $qb->andWhere(sprintf('a.%s = :%s', $field, $field));
                 // Assign value from address
                 $params[$field] = $address->{$methodName}();
             }
         }
     }
     $qb->setParameters($params);
     return $qb;
 }
예제 #13
0
파일: Profile.php 프로젝트: kingsj/core
 /**
  * testUpdate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testUpdate()
 {
     // Test #1
     $profile1 = $this->getTestProfile(1, 0);
     $profile1->map($this->testProfileData[2]);
     $profile1->setMembership(null);
     $profile1->setPendingMembership(null);
     $result = $profile1->update();
     // Update result must be true
     $this->assertTrue($result, 'update() must return true');
     // Get updated profile from the database
     $profile2 = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->find($profile1->getProfileId());
     // Check if profile properties are correctly updated
     foreach ($this->testProfileData[2] as $key => $value) {
         $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($key);
         // membership_id must be null after updating if it has a zero value initially
         if (in_array($key, array('membership_id', 'pending_membership_id')) && 0 === $value) {
             $this->assertNull($profile2->{$methodName}(), 'Wrong property (' . $key . ')');
         } else {
             $this->assertEquals($value, $profile2->{$methodName}(), 'Wrong property (' . $key . ')');
         }
     }
     $this->assertTrue(is_null($profile2->getMembership()), 'Membership is expected to be null');
     // Test #2: update user with login that is used by other user, check for duplicate login
     $profile3 = $this->getTestProfile(0, 0);
     $profile4 = $this->getTestProfile(1, 0);
     $origLogin = $profile4->getLogin();
     $origProfileId = $profile4->getProfileId();
     $profile4->setLogin($profile3->getLogin());
     $result = $profile4->update();
     $this->assertFalse($result, 'update() must return false');
     $profile5 = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->find($origProfileId);
     // TODO: check why this test failed
     //$this->assertEquals($origLogin, $profile5->getLogin(), 'Checking for duplicate login');
 }
예제 #14
0
 /**
  * Get field value
  *
  * @param string               $fieldName    Field name
  * @param \XLite\Model\Address $address      Field name
  *
  * @return string
  */
 protected function getFieldValue($fieldName, \XLite\Model\Address $address)
 {
     $result = '';
     if (isset($address)) {
         $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($fieldName);
         // $methodName assembled from 'get' + camelized $fieldName
         $result = $address->{$methodName}();
         if ($result) {
             switch ($fieldName) {
                 case 'state_id':
                     $result = $address->getCountry()->hasStates() ? $address->getState()->getState() : null;
                     break;
                 case 'custom_state':
                     $result = $address->getCountry()->hasStates() ? null : $result;
                     break;
                 case 'country_code':
                     $result = $address->getCountry()->getCountry();
                     break;
                 default:
             }
         }
     }
     return $result;
 }
예제 #15
0
파일: AModel.php 프로젝트: kingsj/core
 /**
  * Retrieve property from the model object
  *
  * @param mixed $name Field/property name
  *
  * @return mixed
  */
 protected function getModelObjectValue($name)
 {
     $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($name);
     $value = null;
     if (method_exists($this->getModelObject(), $methodName)) {
         // Call the corresponded method
         $value = $this->getModelObject()->{$methodName}();
     }
     return $value;
 }
예제 #16
0
파일: Address.php 프로젝트: kingsj/core
 /**
  * Get required and empty fields
  *
  * @param string $atype Address type code
  *
  * @return array
  */
 public function getRequiredEmptyFields($atype)
 {
     $result = array();
     foreach ($this->getRequiredFieldsByType($atype) as $name) {
         $method = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($name);
         // $method assebled from 'get' + \XLite\Core\Converter::getInstance()->convertToCamelCase() method
         if (!$this->{$method}()) {
             $result[] = $name;
         }
     }
     return $result;
 }
예제 #17
0
 public function getTime($time)
 {
     return \XLite\Core\Converter::getInstance()->formatTime($time);
 }
예제 #18
0
 /**
  * Get fields hash
  *
  * @return array
  */
 public function getFieldsHash()
 {
     $result = array();
     foreach (\XLite\Core\Database::getRepo('XLite\\Model\\AddressField')->findAllEnabled() as $field) {
         $name = $field->getServiceName();
         $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($name);
         $result[$name] = $this->{$methodName}();
     }
     return $result;
 }
예제 #19
0
 /**
  * Preprocess addition date
  *
  * @param integer                               $date   Date
  * @param array                                 $column Column data
  * @param \XLite\Module\XC\Reviews\Model\Review $entity Review
  *
  * @return string
  */
 protected function preprocessAdditionDate($date, array $column, \XLite\Module\XC\Reviews\Model\Review $entity)
 {
     return $date ? \XLite\Core\Converter::getInstance()->formatTime($date) : static::t('Unknown');
 }
예제 #20
0
 /**
  * Preprocess last login
  *
  * @param integer              $date   Date
  * @param array                $column Column data
  * @param \XLite\Model\Profile $entity Profile
  *
  * @return string
  */
 protected function preprocessLastLogin($date, array $column, \XLite\Model\Profile $entity)
 {
     return $date ? \XLite\Core\Converter::getInstance()->formatTime($date) : static::t('Never');
 }
예제 #21
0
 /**
  * Get field value
  *
  * @param string  $fieldName    Field name
  * @param boolean $processValue Process value flag OPTIONAL
  *
  * @return string
  */
 public function getFieldValue($fieldName, $processValue = false)
 {
     $address = $this->getParam(self::PARAM_ADDRESS);
     $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($fieldName);
     // $methodName assembled from 'get' + camelized $fieldName
     $result = $address->{$methodName}();
     if ($result && false !== $processValue) {
         switch ($fieldName) {
             case 'state_id':
                 $result = $address->getCountry()->hasStates() ? $address->getState()->getState() : null;
                 break;
             case 'custom_state':
                 $result = $address->getCountry()->hasStates() ? null : $result;
                 break;
             case 'country_code':
                 $result = $address->getCountry()->getCountry();
                 break;
             case 'type':
                 $result = $address->getTypeName();
                 break;
             default:
         }
     }
     return $result;
 }
예제 #22
0
 /**
  * Check reponse content for action and target
  *
  * @param string $target Request target
  * @param string $action Request action
  * @param array  $reponse Decrypted and converted data from X-Payments
  *
  * @return bool 
  */
 protected function checkResponseContent($target, $action, $response)
 {
     $method = 'check' . \XLite\Core\Converter::getInstance()->convertToCamelCase($target) . \XLite\Core\Converter::getInstance()->convertToCamelCase($action) . 'ResponseValid';
     return is_array($response) && (method_exists($this, $method) ? $this->{$method}($response) : true);
 }
예제 #23
0
 /**
  * Check if billing and shipping addresses are equal or not
  * TODO: review method after implementing at one-step-checkout
  *
  * @return boolean
  */
 public function isSameAddress()
 {
     $result = false;
     $billingAddress = $this->getBillingAddress();
     $shippingAddress = $this->getShippingAddress();
     if (null !== $billingAddress && null !== $shippingAddress) {
         $result = true;
         if ($billingAddress->getAddressId() != $shippingAddress->getAddressId()) {
             $addressFields = $billingAddress->getAvailableAddressFields();
             foreach ($addressFields as $name) {
                 $methodName = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($name);
                 // Compare field values of billing and shipping addresses
                 if ($billingAddress->{$methodName}() != $shippingAddress->{$methodName}()) {
                     $result = false;
                     break;
                 }
             }
         }
     }
     return $result;
 }
예제 #24
0
 /**
  * Call corresponded method to handle a search condition
  *
  * @param mixed                      $value        Condition data
  * @param string                     $key          Condition name
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare
  *
  * @return void
  */
 protected function callSearchConditionHandler($value, $key, \Doctrine\ORM\QueryBuilder $queryBuilder)
 {
     if ($this->isSearchParamHasHandler($key)) {
         $methodName = 'prepareCnd' . \XLite\Core\Converter::getInstance()->convertToCamelCase($key);
         // Call method for preparing param condition
         $this->{$methodName}($queryBuilder, $value);
     } else {
         // TODO - add logging here
     }
 }