0

I am working on an integration extension for Magento 2. I would like to create API endpoints for core_config_data table, because I would like to insert a html script to header of each specific store view.

Let's say that the Magento store has these records in core_config_data_table:

+-----------+---------+----------+-----------------------+----------------------+
| config_id | scope   | scope_id | path                  | value                |
+-----------+---------+----------+-----------------------+----------------------+
|        47 | stores  |        1 | design/head/includes  | <link  SOMETHING />  |
|        48 | stores  |        3 | design/head/includes  | <link  SOMETHING />  |
+-----------+---------+----------+-----------------------+----------------------+

I would like to end up with something like this:

+-----------+---------+----------+-----------------------+----------------------------------------------------------+
| config_id | scope   | scope_id | path                  | value                                                    |
+-----------+---------+----------+-----------------------+----------------------------------------------------------+
|        47 | stores  |        1 | design/head/includes  | <link  SOMETHING /><script async="" src=URL-1></script>  |
|        48 | stores  |        3 | design/head/includes  | <link  SOMETHING /><script async="" src=URL-2></script>  |
+-----------+---------+----------+-----------------------+----------------------------------------------------------+

I can figure out which value I want to include for which scope_id (store view id), but I don't know how to implement the endpoints that i need for this. I think I need 2 endpoints:

  1. endpoint to fetch the current value in path design/head/includes for specific scope_id
  • I need this because I want to extend the value, not replace it
  1. endpoint to update the value in path design/head/includes for specific scope_id

How should I go about solving this?

0

1 Answer 1

0

In custom module you have to do these steps, in here endpoint is /V1/kzcomfortgrade/getcomfortgrade You dont need 2 endpoints as one will serve the purpose

1.

    <?php
/**
 * Copyright ©  All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Kz\Comfortgrade\Api;

interface GetcomfortgradeManagementInterface
{

    /**
     * GET for getcomfortgrade api
     * @return string
     */
    public function getGetcomfortgrade();
}
  1. in etc/webapi.xml

    <route url="/V1/kzcomfortgrade/getcomfortgrade" method="GET">
        <service class="Kz\Comfortgrade\Api\GetcomfortgradeManagementInterface" method="getGetcomfortgrade"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>
    </route>
    
<?php
/**
 * Copyright ©  All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Kz\Comfortgrade\Model;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;


class GetcomfortgradeManagement implements \Kz\Comfortgrade\Api\GetcomfortgradeManagementInterface
{

    protected $eavConfig;

        public function __construct(
             ScopeConfigInterface $scopeConfig,

            \Magento\Framework\App\Config\Storage\WriterInterface $configWriter

        ) {
            $this->_configWriter = $configWriter;
            $this->scopeConfig = $scopeConfig;




        }
    /**
     * {@inheritdoc}
     */
    public function getGetcomfortgrade()
    {
        $ftp_server = $this->scopeConfig->getValue("ftp_settings/settings/ftp_server",ScopeInterface::SCOPE_STORE);
        $updateValue= $ftp_server. "html";
        $this->_configWriter->save("ftp_settings/settings/ftp_server", $updateValue, "default", 1);
        
    }
}
2
  • Thank You! I had to do some editing to fit my use case but this answer was definitely a huge help
    – Krumpel
    Commented Jul 3 at 12:20
  • Glad it helps, cheers !!
    – Kareem k
    Commented Jul 3 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.