Skip to content

Commit

Permalink
feat: save check stattus to orders attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
chartechlabs committed Oct 27, 2020
1 parent f0e4b8b commit d2530fe
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
39 changes: 39 additions & 0 deletions EnderecoShopware5Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ public function uninstall(UninstallContext $uninstallContext)
if ($service->get('s_user_addresses_attributes', 'enderecoamsapredictions')) {
$service->delete('s_user_addresses_attributes', 'enderecoamsapredictions');
}

// Attribute sin the order.
if ($service->get('s_order_attributes', 'endereco_order_billingamsts')) {
$service->delete('s_order_attributes', 'endereco_order_billingamsts');
}
if ($service->get('s_order_attributes', 'endereco_order_shippingamsts')) {
$service->delete('s_order_attributes', 'endereco_order_shippingamsts');
}
if ($service->get('s_order_attributes', 'endereco_order_billingamsstatus')) {
$service->delete('s_order_attributes', 'endereco_order_billingamsstatus');
}
if ($service->get('s_order_attributes', 'endereco_order_shippingamsstatus')) {
$service->delete('s_order_attributes', 'endereco_order_shippingamsstatus');
}

$metaDataCache = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl();
$metaDataCache->deleteAll();
Shopware()->Models()->generateAttributeModels(['s_user_addresses_attributes']);
Expand Down Expand Up @@ -127,6 +142,30 @@ private function _addAttributes()
'custom' => true
]);
}
if (!$service->get('s_order_attributes', 'endereco_order_billingamsts')) {
$service->update('s_order_attributes', 'endereco_order_billingamsts', \Shopware\Bundle\AttributeBundle\Service\TypeMapping::TYPE_STRING, [
'displayInBackend' => false,
'custom' => true
]);
}
if (!$service->get('s_order_attributes', 'endereco_order_shippingamsts')) {
$service->update('s_order_attributes', 'endereco_order_shippingamsts', \Shopware\Bundle\AttributeBundle\Service\TypeMapping::TYPE_STRING, [
'displayInBackend' => false,
'custom' => true
]);
}
if (!$service->get('s_order_attributes', 'endereco_order_billingamsstatus')) {
$service->update('s_order_attributes', 'endereco_order_billingamsstatus', \Shopware\Bundle\AttributeBundle\Service\TypeMapping::TYPE_STRING, [
'displayInBackend' => false,
'custom' => true
]);
}
if (!$service->get('s_order_attributes', 'endereco_order_shippingamsstatus')) {
$service->update('s_order_attributes', 'endereco_order_shippingamsstatus', \Shopware\Bundle\AttributeBundle\Service\TypeMapping::TYPE_STRING, [
'displayInBackend' => false,
'custom' => true
]);
}

// If current plugin is EnderecoAMS, the GitHub version is not installed, try to remove old attributes.
$temp = explode('\\', get_class($this));
Expand Down
4 changes: 2 additions & 2 deletions Resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@

<element type="boolean" scope="shop">
<name>checkOnBlur</name>
<label lang="de">Adressprüfung sofort nach verlassen des Hausnummern Feldes auslösen</label>
<label lang="en">Trigger address check immediately after leaving the house number field</label>
<label lang="de">Adressprüfung sofort nach Verlassen der Adressfelder ausführen</label>
<label lang="en">Trigger address check immediately after leaving the address fields</label>
<value>true</value>
<description lang="de">Ist die Funktion aktiv, wird die Adressprüfung sofort nach Eingabe der Adresse angestoßen. Ist die deaktiviert, erfolg die Prüfung beim Klick auf den "Speichern" Button.</description>
<description lang="en">If the function is active, the address check is triggered immediately after the address is entered. If the function is deactivated, the check is performed by clicking the "Save" button.</description>
Expand Down
25 changes: 25 additions & 0 deletions Subscriber/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,34 @@ public static function getSubscribedEvents()

'Enlight_Controller_Action_PostDispatchSecure_Frontend_Account' => 'checkExistingCustomerAddresses',
'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => 'checkAdressesOrOpenModals',

'Shopware_Modules_Order_SaveOrder_FilterAttributes' => 'onAfterOrderSaveOrder',
];
}

public function onAfterOrderSaveOrder($args) {
$sOrder = $args->get('subject');
$returnValue = $args->getReturn();

if ($sOrder->sUserData['billingaddress']['attributes']['enderecoamsstatus']) {
$returnValue['endereco_order_billingamsstatus'] = $sOrder->sUserData['billingaddress']['attributes']['enderecoamsstatus'];
}

if ($sOrder->sUserData['shippingaddress']['attributes']['enderecoamsstatus']) {
$returnValue['endereco_order_shippingamsstatus'] = $sOrder->sUserData['shippingaddress']['attributes']['enderecoamsstatus'];
}

if ($sOrder->sUserData['billingaddress']['attributes']['enderecoamsts']) {
$returnValue['endereco_order_billingamsts'] = $sOrder->sUserData['billingaddress']['attributes']['enderecoamsts'];
}

if ($sOrder->sUserData['shippingaddress']['attributes']['enderecoamsts']) {
$returnValue['endereco_order_shippingamsts'] = $sOrder->sUserData['shippingaddress']['attributes']['enderecoamsts'];
}

return $returnValue;
}

public function checkAdressesOrOpenModals($args) {
$request = $args->getRequest();
$controller = $args->get('subject');
Expand Down
19 changes: 18 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<label lang="en">Endereco Address-Services for Shopware (Download)</label>
<label lang="de">Endereco Adress-Services für Shopware (Download)</label>

<version>3.2.3</version>
<version>3.3.0</version>

<link>https://www.endereco.de/shopware</link>

Expand All @@ -31,6 +31,23 @@

<logo>/custom/plugins/EnderecoShopware5Client/logo.png</logo>

<changelog version="3.3.0">
<changes lang="de">
<![CDATA[
<ul>
<li>Status der Adressenprüfung wird bei Bestellungen als Attribut gespeichert</li>
</ul>
]]>
</changes>
<changes lang="en">
<![CDATA[
<ul>
<li>Saving addres check status in orders attribute.</li>
</ul>
]]>
</changes>
</changelog>

<changelog version="3.2.3">
<changes lang="de">
<![CDATA[
Expand Down

0 comments on commit d2530fe

Please sign in to comment.