. */ /* */ /*************************************************************************************/ namespace LocalPickup\Loop; use Symfony\Component\Config\Definition\Exception\Exception; use Thelia\Core\Template\Element\ArraySearchLoopInterface; use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Model\AddressQuery; use Thelia\Model\ConfigQuery; /** * Class LocalAddress * @package LocalPickup\Loop * @author Thelia * @method int getId() */ class LocalAddress extends BaseLoop implements ArraySearchLoopInterface { /** * @inheritdoc */ public function buildArray() { $id = $this->getId(); /** @var \Thelia\Core\HttpFoundation\Session\Session $session */ $session = $this->requestStack->getCurrentRequest()->getSession(); $address = AddressQuery::create() ->filterByCustomerId($session->getCustomerUser()->getId()) ->findPk($id); if ($address === null) { throw new Exception("The requested address doesn't exist"); } /** @var \Thelia\Model\Customer $customer */ $customer = $session->getCustomerUser(); return [ 'Id' => 0, 'Label' => $address->getLabel(), 'CustomerId' => $address->getCustomerId(), 'TitleId' => $address->getTitleId(), 'Company' => ConfigQuery::read('store_name'), 'Firstname' => $customer->getFirstname(), 'Lastname' => $customer->getLastname(), 'Address1' => ConfigQuery::read('store_address1'), 'Address2' => ConfigQuery::read('store_address2'), 'Address3' => ConfigQuery::read('store_address3'), 'Zipcode' => ConfigQuery::read('store_zipcode'), 'City' => ConfigQuery::read('store_city'), 'CountryId' => ConfigQuery::read('store_country'), 'Phone' => $address->getPhone(), 'Cellphone' => $address->getCellphone(), 'IsDefault' => 0 ]; } /** * @inheritdoc */ public function parseResults(LoopResult $loopResult) { $address = $loopResult->getResultDataCollection(); $loopResultRow = new LoopResultRow($address); $loopResultRow ->set("ID", $address['Id']) ->set("LABEL", $address['Label']) ->set("CUSTOMER", $address['CustomerId']) ->set("TITLE", $address['TitleId']) ->set("COMPANY", $address['Company']) ->set("FIRSTNAME", $address['Firstname']) ->set("LASTNAME", $address['Lastname']) ->set("ADDRESS1", $address['Address1']) ->set("ADDRESS2", $address['Address2']) ->set("ADDRESS3", $address['Address3']) ->set("ZIPCODE", $address['Zipcode']) ->set("CITY", $address['City']) ->set("COUNTRY", $address['CountryId']) ->set("PHONE", $address['Phone']) ->set("CELLPHONE", $address['Cellphone']) ->set("DEFAULT", $address['IsDefault']) ; $loopResult->addRow($loopResultRow); return $loopResult; } /** * @inheritdoc */ protected function getArgDefinitions() { return new ArgumentCollection( Argument::createIntTypeArgument('id', null, true) ); } }