* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link https://www.temando.com/ */ class QuotePickupLocation extends AbstractDb { /** * Serializable fields declaration * - serialized: JSON object * - unserialized: associative array * * @var mixed[] */ protected $_serializableFields = [ QuotePickupLocationInterface::OPENING_HOURS => [ [], [], ], QuotePickupLocationInterface::SHIPPING_EXPERIENCES => [ [], [], ] ]; /** * Resource initialization * * @return void */ protected function _construct() { $this->_init(SetupSchema::TABLE_QUOTE_PICKUP_LOCATION, QuotePickupLocationInterface::ENTITY_ID); } /** * @param AbstractModel|QuotePickupLocationInterface $object * @param int $value * @param string|null $field * @return $this * @throws \Exception */ public function load(AbstractModel $object, $value, $field = null) { parent::load($object, $value); $street = $object->getStreet(); if (is_string($street)) { $exploded = explode("\n", $street); $object->setData(QuotePickupLocationInterface::STREET, $exploded); } // as of v1.3.0 the serialized data structure changed $openingHours = $object->getOpeningHours(); if (!array_key_exists('general', $openingHours)) { $openingHours['general'] = $openingHours; $openingHours['specific'] = []; $object->setData(QuotePickupLocationInterface::OPENING_HOURS, $openingHours); } // cast values for type safety $distance = $object->getDistance() ? (int) $object->getDistance() : null; $object->setData(QuotePickupLocationInterface::DISTANCE, $distance); $object->setData(QuotePickupLocationInterface::SELECTED, (bool) $object->isSelected()); return $this; } /** * @param AbstractModel|QuotePickupLocationInterface $object * @return $this * @throws \Exception */ public function save(AbstractModel $object) { $street = $object->getStreet(); if (is_array($street)) { $imploded = implode("\n", $street); $object->setData(QuotePickupLocationInterface::STREET, $imploded); } parent::save($object); if (is_string($street)) { $exploded = explode("\n", $street); $object->setData(QuotePickupLocationInterface::STREET, $exploded); } return $this; } }