Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1166555
shipping_quote_engine_event_handler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Sep 23, 12:04 AM
Size
3 KB
Mime Type
text/x-php
Expires
Thu, Sep 25, 12:04 AM (1 h, 3 m)
Engine
blob
Format
Raw Data
Handle
755512
Attached To
rMINC Modules.In-Commerce
shipping_quote_engine_event_handler.php
View Options
<?php
/**
* @version $Id: shipping_quote_engine_event_handler.php 16522 2017-01-20 20:28:16Z alex $
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
ShippingQuoteEngineEventHandler
extends
kDBEventHandler
{
/**
* Occurs before updating item
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
OnBeforeItemUpdate
(
kEvent
$event
)
{
parent
::
OnBeforeItemUpdate
(
$event
);
/** @var kDBItem $object */
$object
=
$event
->
getObject
();
/** @var ShippingQuoteEngine $engine */
$engine
=
$this
->
Application
->
recallObject
(
$object
->
GetDBField
(
'ClassName'
));
$engine_fields
=
$engine
->
GetEngineFields
();
$properties
=
$object
->
GetDBField
(
'Properties'
);
$properties
=
$properties
?
unserialize
(
$properties
)
:
Array
();
// common fields for all shipping quote engines
if
(
$object
->
GetDBField
(
'AccountPassword'
)
!=
''
)
{
// don't erase password by accident
$engine_fields
[]
=
'AccountPassword'
;
}
// save shipping quote specific fields
foreach
(
$engine_fields
as
$engine_field
)
{
$properties
[
$engine_field
]
=
$object
->
GetDBField
(
$engine_field
);
}
$object
->
SetDBField
(
'Properties'
,
serialize
(
$properties
));
/** @var kCountryStatesHelper $cs_helper */
$cs_helper
=
$this
->
Application
->
recallObject
(
'CountryStatesHelper'
);
$from_country
=
$this
->
Application
->
ConfigValue
(
'Comm_Shipping_Country'
);
$has_states
=
strlen
(
$from_country
)
==
3
?
$cs_helper
->
CountryHasStates
(
$from_country
)
:
false
;
$valid_address
=
$from_country
&&
(
$has_states
&&
$this
->
Application
->
ConfigValue
(
'Comm_Shipping_State'
)
||
!
$has_states
)
&&
$this
->
Application
->
ConfigValue
(
'Comm_Shipping_City'
)
&&
$this
->
Application
->
ConfigValue
(
'Comm_Shipping_ZIP'
);
if
(
!
function_exists
(
'curl_init'
)
)
{
$object
->
SetError
(
'Status'
,
'curl_not_present'
);
}
elseif
(
(
$object
->
GetDBField
(
'Status'
)
==
STATUS_ACTIVE
)
&&
!
$valid_address
)
{
$object
->
SetError
(
'Status'
,
'from_info_not_filled_in'
);
}
}
/**
* Sets virtual fields from serialized properties array
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
OnAfterItemLoad
(
kEvent
$event
)
{
parent
::
OnAfterItemLoad
(
$event
);
/** @var kDBItem $object */
$object
=
$event
->
getObject
();
$properties
=
$object
->
GetDBField
(
'Properties'
);
if
(
$properties
)
{
$object
->
SetDBFieldsFromHash
(
unserialize
(
$properties
));
}
}
/**
* Deletes cached shipping quotes on any setting change
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
OnAfterItemCreate
(
kEvent
$event
)
{
parent
::
OnAfterItemCreate
(
$event
);
$this
->
_deleteQuoteCache
();
}
/**
* Deletes cached shipping quotes on any setting change
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
OnAfterItemUpdate
(
kEvent
$event
)
{
parent
::
OnAfterItemUpdate
(
$event
);
$this
->
_deleteQuoteCache
();
}
/**
* Deletes cached shipping quotes on any setting change
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
OnAfterItemDelete
(
kEvent
$event
)
{
parent
::
OnAfterItemDelete
(
$event
);
$this
->
_deleteQuoteCache
();
}
/**
* Deletes cached shipping quotes
*
*/
function
_deleteQuoteCache
()
{
$sql
=
'DELETE FROM '
.
TABLE_PREFIX
.
'SystemCache
WHERE VarName LIKE "ShippingQuotes%"'
;
$this
->
Conn
->
Query
(
$sql
);
}
}
Event Timeline
Log In to Comment