4

We have Custom POS system enabled on the website.

Like to append some labels in the order id and order current status for the display purpose only in the POS system not for the website(frontend) order view /admin sales order view.

For e.g. If sales table having 10000101 order id then in POS it should show POS-10000101

Likewise for the current status, if order having PROCESSING status then it should show POS-PROCESSING.

Below is the webapi.xml code

<route url="/V1/webpos/orders/search" method="GET">
    <service class="Custom\Webpos\Api\Sales\OrderSearchRepositoryInterface" method="search"/>
    <resources>
        <resource ref="Custom_Webpos::manage_pos" />
    </resources>
</route>

code for \Custom\Webpos\Api\OrderSearchRepositoryInterface.php

namespace Custom\Webpos\Api\Sales;
interface OrderSearchRepositoryInterface
{

    public function search(\Custom\Webpos\Api\SearchCriteriaInterface $searchCriteria);
}

code for model OrderSearchRepository which is implementing OrderSearchRepositoryInterface

namespace Custom\Webpos\Model\Sales;
class OrderSearchRepository extends OrderRepository
    implements \Custom\Webpos\Api\Sales\OrderSearchRepositoryInterface
{

    public function search(\Custom\Webpos\Api\SearchCriteriaInterface $searchCriteria)
    {
        $collection = $this->getOrderCollection($searchCriteria);
        $searchResult = $this->searchResultFactory->create();
        $searchResult->setSearchCriteria($searchCriteria);
        $searchResult->setItems($collection->getItems());
        $searchResult->setTotalCount($collection->getSize());
        return $searchResult;
    }


    public function getOrderCollection($searchCriteria) {        
        $collection = $this->collectionFactory->create();
        /** @var \Custom\Webpos\Api\Data\Sales\OrderSearchResultInterface $searchResult */
        if($searchCriteria ->getCurrentPage()) {
            $collection->setCurPage($searchCriteria->getCurrentPage());
        }
        if($searchCriteria ->getPageSize()) {
            $collection->setPageSize($searchCriteria->getPageSize());
        }

        $isLimit = $searchCriteria->getIsLimit();
        if($searchCriteria->getIsHold()) {
            $collection->addFieldToFilter('main_table.state', \Magento\Sales\Model\Order::STATE_HOLDED);
        } else {            
            $collection->addFieldToFilter('main_table.state', ['nin' => \Magento\Sales\Model\Order::STATE_HOLDED]);
        }        
        if($searchCriteria->getQueryString()) {
            $queryString = '%' . $searchCriteria->getQueryString() . '%';
            $collection
                ->joinToGetSearchString($queryString);
            ;
        }
        $collection->addOrder('main_table.created_at', 'DESC');
        return $collection;
    }


    }
}

Any sort of help would be appreciated.

Your Answer

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

Browse other questions tagged or ask your own question.