public function verifyTaxList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Tax list is not valid JSON"));
     }
     $taxList = json_decode($value, true);
     /* check we have 2 level max */
     foreach ($taxList as $taxLevel1) {
         if (is_array($taxLevel1)) {
             foreach ($taxLevel1 as $taxLevel2) {
                 if (is_array($taxLevel2)) {
                     $context->addViolation(Translator::getInstance()->trans("Bad tax list JSON"));
                 } else {
                     $taxModel = TaxQuery::create()->findPk($taxLevel2);
                     if (null === $taxModel) {
                         $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
                     }
                 }
             }
         } else {
             $taxModel = TaxQuery::create()->findPk($taxLevel1);
             if (null === $taxModel) {
                 $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
             }
         }
     }
 }
 public function verifyCountryList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Country list is not valid JSON"));
     }
     $countryList = json_decode($value, true);
     foreach ($countryList as $countryItem) {
         if (is_array($countryItem)) {
             $country = CountryQuery::create()->findPk($countryItem[0]);
             if (null === $country) {
                 $context->addViolation(Translator::getInstance()->trans("Country ID %id not found", ['%id' => $countryItem[0]]));
             }
             if ($countryItem[1] == "0") {
                 continue;
             }
             $state = StateQuery::create()->findPk($countryItem[1]);
             if (null === $state) {
                 $context->addViolation(Translator::getInstance()->trans("State ID %id not found", ['%id' => $countryItem[1]]));
             }
         } else {
             $context->addViolation(Translator::getInstance()->trans("Wrong country definition"));
         }
     }
 }
示例#3
0
 public function testFormatJsonType()
 {
     $jsonType = new JsonType();
     $this->assertTrue(is_array($jsonType->getFormattedValue('{"k0":"v0","k1":"v1","k2":"v2"}')));
     $this->assertNull($jsonType->getFormattedValue('foo'));
 }