dasdsa

Kolorwanie:
Status:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Drzewa\Drzewa\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drzewa\Drzewa\Model\Cron;
use \Magento\Framework\App\Config\ScopeConfigInterface;
use \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory;
use \Magento\Framework\App\State;
use \Magento\Framework\App\Area;

class RemoveBaskets extends Command
{
    protected $scopeConfig;
    protected $quoteCollectionFactory;

    public function __construct(
        ScopeConfigInterface $scopeConfig,
        CollectionFactory $quoteCollectionFactory,
        State $state
    )
    {
        parent::__construct();

        $this->scopeConfig = $scopeConfig;
        $this->quoteCollectionFactory = $quoteCollectionFactory;

        $state->setAreaCode(Area::AREA_FRONTEND);
    }
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this->setName('drzewa:remove-baskets')
            ->setDescription('Usuwa nieaktualne koszyki');
        parent::configure();
    }
    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $days = (int) $this->scopeConfig->getValue('baskets/general/days');
        if ($days > 0) {
            $toDate = strtotime('-' . $days . ' day', strtotime(date("Y-m-d h:i:s")));
            $quoteCollection = $this->quoteCollectionFactory->create()
                ->addFieldToFilter('created_at', ['to' => $toDate, 'date' => true]);

            $output->writeln('<info>' . $quoteCollection->getSelectSql() .  ' <info>');

            foreach ($quoteCollection as $quote) {
                $quote->delete();
            }
        }
    }
}

Copyrights 2014-2018 © Wklejaj.pl Wszelkie prawa zastrzeżone.