Skip to content

Commit

Permalink
Merge pull request #47 from czettnersandor/feature/billing-address
Browse files Browse the repository at this point in the history
Ability to send billing address with API calls
  • Loading branch information
garthbrantley authored Aug 25, 2023
2 parents 091ded2 + 12723d9 commit f90f01b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/SubscribePro/Service/Subscription/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Subscription extends DataObject implements SubscriptionInterface
self::PAYMENT_METHOD_CODE => false,
self::SHIPPING_ADDRESS_ID => false,
self::SHIPPING_ADDRESS => false,
self::BILLING_ADDRESS_ID => false,
self::BILLING_ADDRESS => false,
self::PRODUCT_SKU => true,
self::REQUIRES_SHIPPING => true,
self::QTY => true,
Expand Down Expand Up @@ -49,6 +51,8 @@ class Subscription extends DataObject implements SubscriptionInterface
self::PAYMENT_METHOD_CODE => false,
self::SHIPPING_ADDRESS_ID => false,
self::SHIPPING_ADDRESS => false,
self::BILLING_ADDRESS_ID => false,
self::BILLING_ADDRESS => false,
self::PRODUCT_SKU => true,
self::REQUIRES_SHIPPING => true,
self::QTY => true,
Expand Down Expand Up @@ -135,6 +139,12 @@ public function getFormData()
unset($formData[self::SHIPPING_ADDRESS_ID]);
}

if (!empty($formData[self::BILLING_ADDRESS_ID])) {
unset($formData[self::BILLING_ADDRESS]);
} else {
unset($formData[self::BILLING_ADDRESS_ID]);
}

return $formData;
}

Expand Down Expand Up @@ -388,6 +398,36 @@ public function getCreditcardLastDigits()
return $this->getData(self::CREDITCARD_LAST_DIGITS);
}

/**
* @return int|null
*/
public function getBillingAddressId()
{
return $this->getData(self::BILLING_ADDRESS_ID);
}

public function setBillingAddressId($shippingAddressId)
{
return $this->setData(self::BILLING_ADDRESS_ID, $shippingAddressId);
}

/**
* @return \SubscribePro\Service\Address\AddressInterface|null
*/
public function getBillingAddress()
{
return $this->getData(self::BILLING_ADDRESS);
}

/**
* @param \SubscribePro\Service\Address\AddressInterface|null $billingAddress
* @return $this
*/
public function setBillingAddress($billingAddress)
{
return $this->setData(self::BILLING_ADDRESS, $billingAddress);
}

/**
* @return int|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ interface SubscriptionInterface extends DataInterface
public const MAGENTO_BILLING_ADDRESS_ID = 'magento_billing_address_id';
public const SHIPPING_ADDRESS_ID = 'shipping_address_id';
public const SHIPPING_ADDRESS = 'shipping_address';
public const BILLING_ADDRESS_ID = 'billing_address_id';
public const BILLING_ADDRESS = 'billing_address';

public const MAGENTO_SHIPPING_ADDRESS_ID = 'magento_shipping_address_id';
public const MAGENTO_SHIPPING_METHOD_CODE = 'magento_shipping_method_code';
public const SHIPPING_METHOD_CODE = 'shipping_method_code';
Expand Down
3 changes: 3 additions & 0 deletions src/SubscribePro/Utils/SubscriptionUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ protected static function compareSubscriptions(SubscriptionInterface $a, Subscri
return $dateResult;
}

if(!$a->getShippingAddressId()) {
return 0;
}
// Compare by shipping address
$shippingAddressResult = strcmp($a->getShippingAddressId(), $b->getShippingAddressId());
if (0 != $shippingAddressResult) {
Expand Down

0 comments on commit f90f01b

Please sign in to comment.