Skip to content

Commit

Permalink
Fix delivery module validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Perriere committed Apr 21, 2016
1 parent 0716532 commit d52b1ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.2</version>
<version>1.2.1</version>
<authors>
<author>
<name>Etienne Perriere</name>
Expand Down
35 changes: 19 additions & 16 deletions DeliveryRound.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ public function postActivation(ConnectionInterface $con = null)
*/
public function isValidDelivery(Country $country)
{
// Get current customer & addressId
$customer = $this->getRequest()->getSession()->getCustomerUser();
$currentAddressId = $this->getCurrentlySelectedAddress($this->getRequest(), $customer);
// Get current addressId
$currentAddressId = $this->getRequest()->request->get('address_id');

if (empty($currentAddressId)) {
if (null !== $customer = $this->getRequest()->getSession()->getCustomerUser()) {
$currentAddressId = AddressQuery::create()
->filterByCustomer($customer)
->filterByIsDefault(1)
->select('ID')
->findOne();
} else {
return false;
}
}

// Get delivered zipcodes
$deliveryRounds = DeliveryRoundQuery::create()->find();
Expand All @@ -66,7 +77,7 @@ public function isValidDelivery(Country $country)
$deliveryRoundZipcode[] = $deliveryRound->getZipCode();
}

// Check if the customer's current address is deliverable
// Check if the customer's current address is in delivered zipcodes
if (null !== AddressQuery::create()->filterByZipcode($deliveryRoundZipcode)->findOneById($currentAddressId)) {
return true;
} else {
Expand All @@ -75,22 +86,14 @@ public function isValidDelivery(Country $country)
}

/**
* @param \Thelia\Core\HttpFoundation\Request $request
* @param \Thelia\Model\Customer $customer
* @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
* @param $request
* @return mixed
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function getCurrentlySelectedAddress($request, $customer)
protected function getCurrentlySelectedAddress($request)
{
$currentAddressId = $request->request->get('address_id');

if (empty($currentAddressId)) {
$currentAddressId = AddressQuery::create()
->filterByCustomer($customer)
->filterByIsDefault(1)
->select('ID')
->findOne();
}


return $currentAddressId;
}
Expand Down

0 comments on commit d52b1ce

Please sign in to comment.