cancel
Showing results for 
Search instead for 
Did you mean: 

create cron for report shipment

create cron for report shipment

hello,

 

i use Magento 1.9.2.4 (community edition).

 

We have installed a module of our shipping company
Before a shipment is effectively accepted by the shipping company, we first have to report this shipment. This is provided in the module itself.
However, this must be done manually each time.

Now I would like to run a cron every 15 minutes to do this reporting automatically.

Can anyone give us a start how we can make the code for this cron?

thank you in advance

8 REPLIES 8

Re: create cron for report shipment

Hi @vmwebdesign,

 

I guess that you'll create a new module that will extended the original one (is the best idea).

 

I'll assume that you have currently a blank module created. Next step is to define the cronjob on config.xml:

 

<config>
    ...
    <crontab>
        <jobs>
            <your_module_cron_job>
                <run>
                    <model>modulename/modelname::method_name</model>
                    <!-- I.e.: shipmentmodule/cron::runShipmentConfirmation -->
                </run>
                <schedule>
                    <cron_expr>* */15 * * *</cron_expr>
</schedule> </your_module_cron_job> </jobs> </crontab> </config>

Now you'll need to create your model class (inside Model directory, of course):

 

class Vendor_Shipmentmodule_Model_Cron
{
 
    public function runShipmentConfirmation()
    {
         //Do things
     }
 
}

And, basically that's all.

You can improve the module with configuration options but this should work.

Re: create cron for report shipment

hello,

thank you very much for your answer.

it is an existing module, but with your answer, i've found a file config.xml with this code in the crontab:

 

    <crontab>
        <jobs>
            <!-- remove old temporary label files (by default files older than 5 min will be deleted) -->
            <postnl_clean_temp_labels>
                <schedule>
                    <cron_expr>30 * * * *</cron_expr> <!-- every hour at 30 minutes minutes -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::cleanTempLabels</model>
                </run>
            </postnl_clean_temp_labels>
            <!-- remove old lock files (by default files older than 1 hour will be deleted) -->
            <postnl_clean_old_locks>
                <schedule>
                    <cron_expr>0 * * * *</cron_expr> <!-- every hour on the hour -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::cleanOldLocks</model>
                </run>
            </postnl_clean_old_locks>
            <!-- get missing barcodes for postnl shipments -->
            <postnl_get_missing_barcodes>
                <schedule>
                    <cron_expr>*/30 * * * *</cron_expr> <!-- every 30 minutes -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::getBarcodes</model>
                </run>
            </postnl_get_missing_barcodes>
            <!-- Update the shipping status for all undelivered PostNL shipments -->
            <postnl_update_shipping_status>
                <schedule>
                    <cron_expr>30 3,11,15 * * *</cron_expr> <!-- This schedule will be overwritten by a semi-random cron expression that is generated when the extension is first installed. It's stored in the core_config_data table. -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::updateShippingStatus</model>
                </run>
            </postnl_update_shipping_status>
            <!-- Update the return status for all undelivered PostNL shipments -->
            <postnl_update_return_status>
                <schedule>
                    <cron_expr>30 2,10,18 * * *</cron_expr> <!-- This schedule will be overwritten by a semi-random cron expression that is generated when the extension is first installed. It's stored in the core_config_data table. -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::updateReturnStatus</model>
                </run>
            </postnl_update_return_status>
            <!-- Expire confirmations of shipments that have been confirmed, but have not been shipped within the maximum number of days -->
            <postnl_expire_confirmation>
                <schedule>
                    <cron_expr>0 1,13 * * *</cron_expr> <!-- at 01:00 (1 A.M.) and 13:00 (1 P.M.) each day -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::expireConfirmation</model>
                </run>
            </postnl_expire_confirmation>
            <!-- Sends track and trace emails for all shipments that have been confirmed -->
            <postnl_send_track_and_trace_email>
                <schedule>
                    <cron_expr>*/15 * * * *</cron_expr> <!-- every 15 minutes -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::sendTrackAndTraceEmail</model>
                </run>
            </postnl_send_track_and_trace_email>
            <!-- Update the shop's statistics with the extension control system -->
            <postnl_update_statistics>
                <schedule>
                    <cron_expr>30 6,18 * * *</cron_expr> <!-- This schedule will be overwritten by a semi-random cron expression that is generated when the extension is first installed. It's stored in the core_config_data table. -->
                </schedule>
                <run>
                    <model>postnl_extensioncontrol/observer_cron::updateStatistics</model>
                </run>
            </postnl_update_statistics>
            <!-- Update the shop's statistics with the extension control system -->
            <postnl_update_notification_feed>
                <schedule>
                    <cron_expr>15 * * * *</cron_expr> <!-- every hour at 15 minutes on the hour -->
                </schedule>
                <run>
                    <model>postnl_extensioncontrol/observer_cron::checkFeedUpdate</model>
                </run>
            </postnl_update_notification_feed>
            <!-- Remove labels of shipments that have been delivered to prevent the database from getting too large -->
            <postnl_remove_old_labels>
                <schedule>
                    <cron_expr>0 1,13 * * *</cron_expr> <!-- at 01:00 (1 A.M.) and 13:00 (1 P.M.) each day -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::removeOldLabels</model>
                </run>
            </postnl_remove_old_labels>
            <!-- Update product attributes data. This needs to be performed for certain update scripts, however it can be very taxing on the server when there are a lot of products. Therefore we'll process it using a cronjob. -->
            <postnl_update_product_attribute>
                <!-- No cron expression. The cron expression is generated when the extension is updated and will be removed once the update has finished. -->
                <run>
                    <model>postnl_core/observer_cron::updateProductAttribute</model>
                </run>
            </postnl_update_product_attribute>
            <!-- Update PostNl shipment and order dates to the correct (UTC) time zone. This needs to be performed for certain update scripts, however it can be very taxing on the server when there are a lot of products. Therefore we'll process it using a cronjob. -->
            <postnl_update_date_time_zone>
                <!-- No cron expression. The cron expression is generated when the extension is updated and will be removed once the update has finished. -->
                <run>
                    <model>postnl_core/observer_cron::updateDateTimeZone</model>
                </run>
            </postnl_update_date_time_zone>
            <!-- Update PostNl config settings. Currently this is used for the Google Maps API key, and the Cendris username and password. -->
            <postnl_update_config_settings>
                <schedule>
                    <cron_expr>0 0 * * 0</cron_expr> <!-- every sunday at midnight. -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::updateDateTimeZone</model>
                </run>
            </postnl_update_config_settings>
            <!-- Verify PostNL's data integrity. -->
            <postnl_data_integrity_check>
                <schedule>
                    <cron_expr>0 5 * * *</cron_expr> <!-- every night at 5 AM. -->
                </schedule>
                <run>
                    <model>postnl_core/observer_cron::integrityCheck</model>
                </run>
            </postnl_data_integrity_check>
        </jobs>
    </crontab>

after that i've found this, i've found a file cron.php in the model-directory with a very large class-function.

 

but the function that i need, is not mentioned in this cron, because this is a manual transaction that we have to do in the backend of magento.

how can i import this manual transaction in an automatically transaction in this cron. Or is this not the correct way to do this?

 

thanks

tom

Re: create cron for report shipment

@vmwebdesign,

 

I guess you don't need to add your new code to that module. Is a better idea to create a new module (because updates of the original module).

I still believe that creating a new module (using the example or maybe your code) is the best approach.

 

Re: create cron for report shipment

okay, that is very clear for me

 

i will create a new module, just for this cronjob.

making a module is another question. maybe i can use the extension 'Ultimate Module Creator' for this

 

but now is my biggest question: making this function to automatically send confirmation (reporting) the orders that are not confirmed yet to the shipping company

 

is it an option than anyone can help me with this?

 

thanks

tom

Re: create cron for report shipment

@vmwebdesign

 

Could you give few information of your order processing flow?

 

1. what is the order status when customers place orders successfully?

2. when you prepare orders using your existing module, which is ran manually, what status do orders have at that point?

 

 

Re: create cron for report shipment

Hey,

it is a possibility that I can give you a login to the backend of Magento and we see this along so on?

 

afterwards i will put the necessary info in this ticket again, so other people can use this information as well

 

thank you

tom

Re: create cron for report shipment

Hi,

 

@vmwebdesign

 

Not a problem, can take a look for you. But please PM me directly, I am sure you will not do this, but as a suggestion do not post credentials here.

Re: create cron for report shipment

oke,

 

i will send you a PM

 

hope we can find a solution