7.3.2: Adding the archived field

Adding the archived field

Technical Blueprint: Filter on only orders where “archived” is 0.

The "Order Export" grid in its current form shows all existing records, but our requirements dictate that only exports more recent than 30 days should be displayed, and our technical blueprint prescribes an archived field on export records to control this.

Our sales_order_export table doesn't have such a field yet, so let's add it. Revisit the etc/db_schema.xml file in SwiftOtter_OrderExport and add a field called archived.

  • The field should be a smallint, since it only needs to store a value of 0 or 1.
  • The default value should be 0, which will also be applied to the records that already exist when the new field is added.

Run Magento's upgrade process to install the new field. Don't forget to run the command to update the "whitelist" file as well!

bin/magento setup:upgrade --keep-generated
bin/magento setup:db-declaration:generate-whitelist --module-name=SwiftOtter_OrderExport

Updating the entity API

With a new field available on export records, don't neglect the entity interface and its corresponding model.

Add getArchived and setArchived accessor methods to SwiftOtter\OrderExport\Api\Data\OrderExportDetailsInterface and SwiftOtter\OrderExport\Model\OrderExportDetails.

Tips:

  • In application code, we want to deal with this value as a boolean, but it's stored as 0 or 1 in the database, so don't forget appropriate type casting.

SEE THE CODE

Complete and Continue