/** * @param Struct\Customer\Group $customerGroup * @param Struct\Country\Area $area * @param Struct\Country $country * @param Struct\Country\State $state * @return \Doctrine\DBAL\Query\QueryBuilder */ private function getAreaQuery(Struct\Customer\Group $customerGroup = null, Struct\Country\Area $area = null, Struct\Country $country = null, Struct\Country\State $state = null) { $query = $this->connection->createQueryBuilder(); $query->select($this->fieldHelper->getTaxRuleFields()); $query->from('s_core_tax_rules', 'taxRule'); $areaId = $area ? $area->getId() : null; $countryId = $country ? $country->getId() : null; $stateId = $state ? $state->getId() : null; $query->andWhere('(taxRule.areaID = :area OR taxRule.areaID IS NULL)')->setParameter(':area', $areaId); $query->andWhere('(taxRule.countryID = :country OR taxRule.countryID IS NULL)')->setParameter(':country', $countryId); $query->andWhere('(taxRule.stateID = :state OR taxRule.stateID IS NULL)')->setParameter(':state', $stateId); $query->andWhere('(taxRule.customer_groupID = :customerGroup OR taxRule.customer_groupID IS NULL)')->setParameter(':customerGroup', $customerGroup->getId()); $query->andWhere('taxRule.groupID = :taxId')->andWhere('taxRule.active = 1'); $query->orderBy('taxRule.customer_groupID', 'DESC')->addOrderBy('taxRule.areaID', 'DESC')->addOrderBy('taxRule.countryID', 'DESC')->addOrderBy('taxRule.stateID', 'DESC'); $query->setFirstResult(0)->setMaxResults(1); return $query; }
/** * @param array $data * @return \Shopware\Bundle\StoreFrontBundle\Struct\Country\State */ public function hydrateState(array $data) { $state = new Struct\Country\State(); $translation = $this->getTranslation($data, '__countryState_translation', '__countryState_translation_fallback', $data['__countryState_id'], $this->translationStateFields); $data = array_merge($data, $translation); $state->setId((int) $data['__countryState_id']); if (isset($data['__countryState_name'])) { $state->setName($data['__countryState_name']); } if (isset($data['__countryState_shortcode'])) { $state->setCode($data['__countryState_shortcode']); } if ($data['__countryStateAttribute_id'] !== null) { $attribute = $this->attributeHydrator->hydrate($this->extractFields('__countryStateAttribute_', $data)); $state->addAttribute('core', $attribute); } return $state; }