1

i am trying to add custom_attribute to quote table name as is_requested. this work fine, column is created. here is Upgrade schem

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{

    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        $setup->getConnection()
            ->addColumn(
                $setup->getTable('quote'),
                'is_requested',
                [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    'length' => 255,
                    'nullable' => true,
                    'default' => 0,
                    'comment' => 'Requested Quote'
                ]
            );
        $setup->endSetup();
    }
}

now the problem is when i try to add value by this code

Magento\Quote\Model\QuoteFactory $quote;

$quote = $this->quote->create();
$quote->setCustomAttribute('is_requested', '1')->save();

value is not save in quote table.

2
protected $quote;

public function __construct(
    ...
    \Magento\Quote\Model\QuoteFactory $quoteFactory,
    ....
) {
    ....
    $this->quote = $quoteFactory;
    ....
}


$quote = $this->quote->create();

$quote->setData('is_requested', '1');

$quote->save();
1
  • thank you for your answer.
    – Ali Raza
    Oct 15 '20 at 6:36
2
 /**
 * @var \Magento\Quote\Model\QuoteRepository
 */
protected $quoteRepository;

/**
 * @param \Magento\Quote\Model\QuoteRepository $quoteRepository
 */
public function __construct(
    \Magento\Quote\Model\QuoteRepository $quoteRepository
) {
    $this->quoteRepository = $quoteRepository;
}

public function updateQuoteData($quoteId, int $customData)
{
    $quote = $this->quoteRepository->get($quoteId); // Get quote by id
    $quote->setData('custom_column', $customData); // Fill data
    $this->quoteRepository->save($quote); // Save quote
}
1
  • thank you repository is better way to do things. but i use factory cause i want to create new object.
    – Ali Raza
    Oct 15 '20 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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