Skip to content

Commit

Permalink
More improvements to models to that we can add logic later
Browse files Browse the repository at this point in the history
- Removed unused imports and commented-out code in Plugin.php
- Changed public properties to private
- Added getter and setter methods for encapsulated properties in models
- Updated Xml service to use new property accessors
  • Loading branch information
johnnynotsolucky committed Nov 5, 2024
1 parent 5b098d2 commit 7c499aa
Show file tree
Hide file tree
Showing 9 changed files with 487 additions and 107 deletions.
44 changes: 3 additions & 41 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use craft\events\RegisterUrlRulesEvent;
use craft\events\RegisterUserPermissionsEvent;
use craft\services\UserPermissions;
use craft\web\Application;
use craft\web\UrlManager;
use fostercommerce\shipstationconnect\models\Settings;
use fostercommerce\shipstationconnect\services\Xml;
Expand All @@ -26,44 +25,16 @@ class Plugin extends \craft\base\Plugin

public string $schemaVersion = '1.0.1';

/**
* init.
*
* @author Unknown
* @since v0.0.1
* @version v1.0.0 Monday, May 23rd, 2022.
* @access public
*/
public function init(): void
{
parent::init();

$this->setComponents([
'xml' => \fostercommerce\shipstationconnect\services\Xml::class,
'xml' => Xml::class,
]);

Craft::$app->view->registerTwigExtension(new IsFieldTypeFilter());

// Because Shipstation uses a querystring parameter of 'action' in their requests.
// This interferes with Craft's routing system.
// So we intercept the request and rename that parameter to ssaction IF the request is for one of this plugin's controllers
/*
Craft::$app->on(Application::EVENT_INIT, function() {
$request = Craft::$app->request;
if(!$request->isConsoleRequest){
if(in_array('actions', $request->getSegments()) && in_array('shipstationconnect', $request->getSegments())) {
if(array_key_exists('action', $request->getQueryParams())) {
// rename array key to match the action name
$params = $request->getQueryParams();
$params['ssaction'] = $params['action'];
unset($params['action']);
$request->setQueryParams($params);
}
};
}
});
*/

Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
Expand Down Expand Up @@ -141,25 +112,16 @@ protected function settingsHtml(): ?string

protected function beforeInstall(): void
{
if (! Craft::$app->plugins->isPluginInstalled('commerce')) {
Craft::error(Craft::t(
'shipstationconnect',
'Failed to install. Craft Commerce is required.'
));
// return false;
}

if (! Craft::$app->plugins->isPluginEnabled('commerce')) {
if (! Craft::$app->plugins->isPluginInstalled('commerce') || ! Craft::$app->plugins->isPluginEnabled('commerce')) {
Craft::error(Craft::t(
'shipstationconnect',
'Failed to install. Craft Commerce is required.'
));
// return false;
}
}

protected function createSettingsModel(): ?Model
{
return new \fostercommerce\shipstationconnect\models\Settings();
return new Settings();
}
}
2 changes: 1 addition & 1 deletion src/events/OrderEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class OrderEvent extends Event
/**
* The order that has been transformed into a format ready to be exported to ShipStation
*/
public Order $transformedOrder;
public Order $order;
}
120 changes: 110 additions & 10 deletions src/models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,143 @@ class Address extends Base
{
#[Groups(['export'])]
#[SerializedName('Company')]
public ?string $company = null;
private ?string $company = null;

#[Groups(['export'])]
#[SerializedName('Address1')]
public ?string $address1 = null;
private ?string $address1 = null;

#[Groups(['export'])]
#[SerializedName('Address2')]
public ?string $address2 = null;
private ?string $address2 = null;

#[Groups(['export'])]
#[SerializedName('City')]
public ?string $city = null;
private ?string $city = null;

#[Groups(['export'])]
#[SerializedName('State')]
public ?string $state = null;
private ?string $state = null;

#[Groups(['export'])]
#[SerializedName('PostalCode')]
public ?string $postalCode = null;
private ?string $postalCode = null;

#[Groups(['export'])]
#[SerializedName('Country')]
public string $country;
private string $country;

#[Groups(['export'])]
#[SerializedName('Name')]
public string $name;
private string $name;

#[Groups(['export'])]
#[SerializedName('Phone')]
public ?string $phone = null;
private ?string $phone = null;

#[Groups(['export'])]
#[SerializedName('Email')]
public string $email;
private string $email;

public function getCompany(): ?string
{
return $this->company;
}

public function setCompany(?string $company): void
{
$this->company = $company;
}

public function getAddress1(): ?string
{
return $this->address1;
}

public function setAddress1(?string $address1): void
{
$this->address1 = $address1;
}

public function getAddress2(): ?string
{
return $this->address2;
}

public function setAddress2(?string $address2): void
{
$this->address2 = $address2;
}

public function getCity(): ?string
{
return $this->city;
}

public function setCity(?string $city): void
{
$this->city = $city;
}

public function getState(): ?string
{
return $this->state;
}

public function setState(?string $state): void
{
$this->state = $state;
}

public function getPostalCode(): ?string
{
return $this->postalCode;
}

public function setPostalCode(?string $postalCode): void
{
$this->postalCode = $postalCode;
}

public function getCountry(): string
{
return $this->country;
}

public function setCountry(string $country): void
{
$this->country = $country;
}

public function getName(): string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = $name;
}

public function getPhone(): ?string
{
return $this->phone;
}

public function setPhone(?string $phone): void
{
$this->phone = $phone;
}

public function getEmail(): string
{
return $this->email;
}

public function setEmail(string $email): void
{
$this->email = $email;
}

public static function fromCommerceAddress(CommerceOrder $commerceOrder, ?CraftAddress $commerceAddress): ?self
{
Expand Down
36 changes: 33 additions & 3 deletions src/models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,45 @@ class Customer extends Base
{
#[Groups(['export'])]
#[SerializedName('CustomerCode')]
public string $customerCode;
private string $customerCode;

#[Groups(['export'])]
#[SerializedName('BillTo')]
public ?Address $billToAddress = null;
private ?Address $billToAddress = null;

#[Groups(['export'])]
#[SerializedName('ShipTo')]
public ?Address $shipToAddress = null;
private ?Address $shipToAddress = null;

public function getCustomerCode(): string
{
return $this->customerCode;
}

public function setCustomerCode(string $customerCode): void
{
$this->customerCode = $customerCode;
}

public function getBillToAddress(): ?Address
{
return $this->billToAddress;
}

public function setBillToAddress(?Address $billToAddress): void
{
$this->billToAddress = $billToAddress;
}

public function getShipToAddress(): ?Address
{
return $this->shipToAddress;
}

public function setShipToAddress(?Address $shipToAddress): void
{
$this->shipToAddress = $shipToAddress;
}

/**
* @return array<int, array<int, string>>
Expand Down
Loading

0 comments on commit 7c499aa

Please sign in to comment.