Jump to content

Edit History

ps8modules

ps8modules

in top of your module:

use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\TextType; 
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
// class your_module extends Module ......

 

and install function add hooks:

$this->registerHook('actionOrderGridDefinitionModifier');
$this->registerHook('actionOrderGridQueryBuilderModifier');
$this->registerHook('actionOrderGridDataModifier');

 

and hooks and functions:

    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        $definition = $params['definition'];

        if (empty($params['definition'])) {
            return;
        }
        

        $definition
            ->getColumns()
            ->addAfter(
                'osname',
                (new DataColumn('DayOfDelivery'))
                ->setName($this->l('Day Of Delivery'))
                ->setOptions([
                    'field' => 'DayOfDelivery',
                ])
		);

        $definition->getFilters()->add(
            (new Filter('DayOfDelivery', TextType::class))
            ->setAssociatedColumn('DayOfDelivery')
            ->setTypeOptions([
                'required' => false,
            ])
        );

    }

    public function hookActionOrderGridQueryBuilderModifier( array $params ) 
    {
        if (empty($params['search_query_builder']) || empty($params['search_criteria'])){
            return;
        } 

        $searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
            
        $searchQueryBuilder->addSelect('o.`DayOfDelivery` as `day_of_delivery`, opa.`date_add` AS `opa_date_add`');
        $searchQueryBuilder->leftJoin(
            'o',
            '`' . _DB_PREFIX_ . 'order_payment`',
            'opa',
            'opa.`order_reference` = o.`reference`'
        );

        if ('DayOfDelivery' === $searchCriteria->getOrderBy()) {
            $searchQueryBuilder->orderBy('opa.`date_add`', $searchCriteria->getOrderWay());
        }

        foreach ($searchCriteria->getFilters() as $filterName => $filterValue) {
            if ('DayOfDelivery' === $filterName) {
                $searchQueryBuilder->andWhere('opa.`date_add` = :opa_date_add');
                $searchQueryBuilder->setParameter('opa_date_add', $filterValue);
            }
        }

    }

    public function hookActionOrderGridDataModifier(array $params)
    {
        if (empty($params['data'])) {
            return;
        }

        $gridData = $params['data'];
        $modifiedRecords = $gridData->getRecords()->all();


        foreach ($modifiedRecords as $key => $data) {
            if (empty($data['DayOfDelivery'])) {
                $modifiedRecords[$key]['DayOfDelivery'] = $this->getIsDayOfDelivery($modifiedRecords[$key]['opa_date_add']);
            }
        }

        $params['data'] = new PrestaShop\PrestaShop\Core\Grid\Data\GridData(
            new PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection($modifiedRecords),
            $gridData->getRecordsTotal(),
            $gridData->getQuery()
        );
    }

    public function getIsDayOfDelivery($data)
    {
        $getDateNumber = date('N', strtotime($data));

        $newDate = Tools::displayDate($data);

        if (in_array($getDateNumber, array(5, 6)) && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +2 days')));
        } 

        if ($getDateNumber < 5 && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +7 days')));
        } 

        if (!$data) {
            $newDate = '--';
        } 

        return $newDate;
    }

 

You won't learn anything by copying codes. If you want to be a developer, you need to study the documentation.

ps8modules

ps8modules

in top of your module:

use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\TextType; 
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
// class your_module extends Module ......

 

and install function add hooks:

$this->registerHook('actionOrderGridDefinitionModifier');
$this->registerHook('actionOrderGridQueryBuilderModifier');
$this->registerHook('actionOrderGridDataModifier');

 

and hooks and functions:

    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        $definition = $params['definition'];

        if (empty($params['definition'])) {
            return;
        }
        

        $definition
            ->getColumns()
            ->addAfter(
                'osname',
                (new DataColumn('DayOfDelivery'))
                ->setName($this->l('Day Of Delivery'))
                ->setOptions([
                    'field' => 'DayOfDelivery',
                ])
		);

        $definition->getFilters()->add(
            (new Filter('DayOfDelivery', TextType::class))
            ->setAssociatedColumn('DayOfDelivery')
            ->setTypeOptions([
                'required' => false,
            ])
        );

    }

    public function hookActionOrderGridQueryBuilderModifier( array $params ) 
    {
        if (empty($params['search_query_builder']) || empty($params['search_criteria'])){
            return;
        } 

        $searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
            
        $searchQueryBuilder->addSelect('o.`DayOfDelivery` as `day_of_delivery`, opa.`date_add` AS `opa_date_add`');
        $searchQueryBuilder->leftJoin(
            'o',
            '`' . _DB_PREFIX_ . 'order_payment`',
            'opa',
            'opa.`order_reference` = o.`reference`'
        );

		$searchQueryBuilder = $params['search_query_builder'];
        $searchCriteria = $params['search_criteria'];

    }

    public function hookActionOrderGridDataModifier(array $params)
    {
        if (empty($params['data'])) {
            return;
        }

        $gridData = $params['data'];
        $modifiedRecords = $gridData->getRecords()->all();


        foreach ($modifiedRecords as $key => $data) {
            if (empty($data['DayOfDelivery'])) {
                $modifiedRecords[$key]['DayOfDelivery'] = $this->getIsDayOfDelivery($modifiedRecords[$key]['opa_date_add']);
            }
        }

        $params['data'] = new PrestaShop\PrestaShop\Core\Grid\Data\GridData(
            new PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection($modifiedRecords),
            $gridData->getRecordsTotal(),
            $gridData->getQuery()
        );
    }

    public function getIsDayOfDelivery($data)
    {
        $getDateNumber = date('N', strtotime($data));

        if (in_array($getDateNumber, array(5, 6)) && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +2 days')));
        } 

        if ($getDateNumber < 5 && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +7 days')));
        } 

        if (!$data) {
            $newDate = '--';
        } 

        return $newDate;
    }

 

You won't learn anything by copying codes. If you want to be a developer, you need to study the documentation.

ps8modules

ps8modules

in top of your module:

use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\TextType; 
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
// class your_module extends Module ......

 

and install function add hooks:

$this->registerHook('actionOrderGridDefinitionModifier');
$this->registerHook('actionOrderGridQueryBuilderModifier');
$this->registerHook('actionOrderGridDataModifier');

 

and hooks and functions:

    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        $definition = $params['definition'];

        if (empty($params['definition'])) {
            return;
        }
        

        $definition
            ->getColumns()
            ->addAfter(
                'osname',
                (new DataColumn('DayOfDelivery'))
                ->setName($this->l('Day Of Delivery'))
                ->setOptions([
                    'field' => 'DayOfDelivery',
                ])
		);

        $definition->getFilters()->add(
            (new Filter('DayOfDelivery', TextType::class))
            ->setAssociatedColumn('DayOfDelivery')
            ->setTypeOptions([
                'required' => false,
            ])
        );

    }

    public function hookActionOrderGridQueryBuilderModifier( array $params ) 
    {
        if (empty($params['search_query_builder']) || empty($params['search_criteria'])){
            return;
        } 

        $searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
            
        $searchQueryBuilder->addSelect('o.`DayOfDelivery` as `day_of_delivery`, opa.`date_add` AS `opa_date_add`');
        $searchQueryBuilder->leftJoin(
            'o',
            '`' . _DB_PREFIX_ . 'order_payment`',
            'opa',
            'opa.`order_reference` = o.`reference`'
        );

		$searchQueryBuilder = $params['search_query_builder'];
        $searchCriteria = $params['search_criteria'];

    }

    public function hookActionOrderGridDataModifier(array $params)
    {
        if (empty($params['data'])) {
            return;
        }

        $gridData = $params['data'];
        $modifiedRecords = $gridData->getRecords()->all();


        foreach ($modifiedRecords as $key => $data) {
            if (empty($data['DayOfDelivery'])) {
                $modifiedRecords[$key]['DayOfDelivery'] = $this->getIsDayOfDelivery($modifiedRecords[$key]['opa_date_add']);
            }
        }

        $params['data'] = new PrestaShop\PrestaShop\Core\Grid\Data\GridData(
            new PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection($modifiedRecords),
            $gridData->getRecordsTotal(),
            $gridData->getQuery()
        );
    }

    public function getIsDayOfDelivery($data)
    {
        $getDateNumber = date('N', strtotime($data));

        if (in_array($getDateNumber, array(5, 6)) && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +2 days')));
        } 

        if ($getDateNumber < 5 && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +7 days')));
        } 

        if (!$data) {
            $newDate = '--';
        } 

        return $newDate;
    }

 

ps8modules

ps8modules

in top of your module:

use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\TextType; 
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
// class your_module extends Module ......

 

and install function add hooks:

$this->registerHook('actionOrderGridDefinitionModifier');
$this->registerHook('actionOrderGridQueryBuilderModifier');
$this->registerHook('actionOrderGridDataModifier');

 

and hooks and functions:

    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        $definition = $params['definition'];

        if (empty($params['definition'])) {
            return;
        }
        

        $definition
            ->getColumns()
            ->addAfter(
                'osname',
                (new DataColumn('DayOfDelivery'))
                ->setName($this->l('Day Of Delivery'))
                ->setOptions([
                    'field' => 'DayOfDelivery',
                ])
		);

        $definition->getFilters()->add(
            (new Filter('DayOfDelivery', TextType::class))
            ->setAssociatedColumn('DayOfDelivery')
            ->setTypeOptions([
                'required' => false,
            ])
        );

    }

    public function hookActionOrderGridQueryBuilderModifier( array $params ) 
    {
        if (empty($params['search_query_builder']) || empty($params['search_criteria'])){
            return;
        } 

        $searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
            
        $searchQueryBuilder->addSelect('o.`DayOfDelivery` as `day_of_delivery`, opa.`date_add` AS `opa_date_add`');
        $searchQueryBuilder->leftJoin(
            'o',
            '`' . _DB_PREFIX_ . 'order_payment`',
            'opa',
            'opa.`order_reference` = o.`reference`'
        );

		$searchQueryBuilder = $params['search_query_builder'];
        $searchCriteria = $params['search_criteria'];

    }

    public function hookActionOrderGridDataModifier(array $params)
    {
        if (empty($params['data'])) {
            return;
        }

        $gridData = $params['data'];
        $modifiedRecords = $gridData->getRecords()->all();


        foreach ($modifiedRecords as $key => $data) {
            if (empty($data['DayOfDelivery'])) {
                $modifiedRecords[$key]['DayOfDelivery'] = $this->getIsDayOfDelivery($modifiedRecords[$key]['opa_date_add']);
            }
        }

        $params['data'] = new PrestaShop\PrestaShop\Core\Grid\Data\GridData(
            new PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection($modifiedRecords),
            $gridData->getRecordsTotal(),
            $gridData->getQuery()
        );
    }

    public function getIsDayOfDelivery($data)
    {
        $getDateNumber = date('N', strtotime($data));

        if (in_array($getDateNumber, array(5, 6)) && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +2 days')));
        } 

        if ($getDateNumber < 5 && $data) {
            $newDate = Tools::displayDate(date('Y-m-d', strtotime($data.' +7 days')));
        } 

        if (!$data) {
            $newDate = '--';
        } 

        return $newDate;
    }

 

×
×
  • Create New...