test

mail@pastecode.io avatar
unknown
php
2 years ago
1.1 kB
2
Indexable
Never
/**
     * @param \Magento\Framework\Model\AbstractModel $object
     * @return \Creativestyle\CustomizationMegaportKaspersky\Model\ResourceModel\KasperskyLicense
     */
    protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
    {
        if ($object->isObjectNew()) {
            $this->createRelation($object);
        }

        return $this;
    }

    /**
     * @param \Magento\Framework\Model\AbstractModel $object
     */
    protected function createRelation(\Magento\Framework\Model\AbstractModel $object): void
    {
        $relationData = [];
        $extensionAttributes = $object->getExtensionAttributes();

        foreach (self::RELATION_DATA_ITEMS as $field => $type) {
            if ($type == 'extension_attribute') {
                $relationData[$field] = $extensionAttributes->getData($field);
            } else {
                $relationData[$field] = $object->getData($field);
            }
        }

        $connection = $this->getConnection();
        $connection->insert($this->getTable('kaspersky_relations'), $relationData);
    }