Answers for "how to access value of a dynamic row magento 2"

0

how to access value of a dynamic row magento 2

app\code\Vendor\Extension\Helper\Data.php

<?php 
namespace Vendor\Extension\Helper;

use Magento\Store\Model\ScopeInterface;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    const PRODUCTCOST = 'pme_giftcard/prices/add_item';

    protected $_storeManager;
    protected $serialize;

    public function __construct(
    \Magento\Framework\App\Helper\Context $context,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Framework\Serialize\Serializer\Json $serialize)
    {
        $this->_storeManager = $storeManager;
        $this->serialize = $serialize;
        parent::__construct($context);
    }

    public function getStoreid()
    {
        return $this->_storeManager->getStore()->getId();
    }


    public function getProductCost()
    {
        $productcostconfig = $this->scopeConfig->getValue(self::PRODUCTCOST,ScopeInterface::SCOPE_STORE,$this->getStoreid());

        if($productcostconfig == '' || $productcostconfig == null)
            return;

        $unserializedata = $this->serialize->unserialize($productcostconfig);

        $productcostarray = array();
        foreach($unserializedata as $key => $row)
        {
            $productcostarray[] = $row['productcost'];
        }

        return $productcostarray;
    }
}
Posted by: Guest on April-20-2022

Browse Popular Code Answers by Language