cancel
Showing results for 
Search instead for 
Did you mean: 

Get data from another model

Get data from another model

I overwrote model:

<?php

namespace Pagseguro\Magento2\Price;

/**
 * Special price model
 */
class SpecialPrice extends \Magento\Catalog\Pricing\Price\SpecialPrice
{
    /**
     * Returns special price
     *
     * @return float
     */
    public function getSpecialPrice()
    {
        $specialPrice = $this->product->getSpecialPrice();
        if ($specialPrice !== null && $specialPrice !== false && !$this->isPercentageDiscount()) {
            $specialPrice = $this->priceCurrency->convertAndRound($specialPrice);
        }
        return 3.11;
    }
}

But i want additionally, get data from my new model:

 

<?php

namespace Pagseguro\Magento2\Model;

class Items extends \Magento\Framework\Model\AbstractModel
{
    /**
     * Constructor
     *
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();
        $this->_init('Pagseguro\Magento2\Model\Resource\Items');
    }
}

 

<?php

namespace Pagseguro\Magento2\Model\Resource;

class Items extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
    /**
     * Model Initialization
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init('pagseguro_magento2_items', 'id');
    }
}
<?php

namespace Pagseguro\Magento2\Model\Resource\Items;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    /**
     * Define resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init('Pagseguro\Magento2\Model\Items', 'Pagseguro\Magento2\Model\Resource\Items');
    }
}

How me to do it? 

 

1 REPLY 1

Re: Get data from another model

Can you please share end goal for overriding SpecialPrice class?