Implemented View Purchased Lottery Tickets

Status
Not open for further replies.
Would it be possible to add a feature/option that allows people who have bought lottery tickets to view those lottery tickets after they purchased them?

As in, they buy a ticket and pick the numbers 3,7,8,10,25. They then have a display that shows they picked these numbers for this ticket, at least until the lottery draws for that time period.

It would be nice to have so users can see what numbers they've picked for a given lottery.

Thanks!
 
Upvote 2
This suggestion has been implemented. Votes are no longer accepted.
Hello @Lightning Lord Rule,

Thank you for your suggestion for DragonByte Shop. Your request will be reviewed by a member of our team shortly.

Unless there are any problems preventing these features from being added to the product, this thread will not receive another reply until it is time to review logged feature requests for implementation.

We appreciate you taking the time to help us improve our products!


- DragonByte Tech Staff
 
Would it be possible to add a feature/option that allows people who have bought lottery tickets to view those lottery tickets after they purchased them?

As in, they buy a ticket and pick the numbers 3,7,8,10,25. They then have a display that shows they picked these numbers for this ticket, at least until the lottery draws for that time period.

It would be nice to have so users can see what numbers they've picked for a given lottery.

Thanks!

I can solve this problem, do you want me to help?

8836
 
Last edited:
Sure, how did you get that to work?
1. Edit file \src\addons\DBTech\Shop\Repository\Lottery.php
- Add this function findLotteryTicketsForLottery2 below the function findLotteryTicketsForLottery
PHP:
//Hoangsang - Get my tickets for View draw
    public function findLotteryTicketsForLottery2(\DBTech\Shop\Entity\Lottery $lottery)
    {
        return $this->finder('DBTech\Shop:LotteryTicket');
    }
2. Edit file \src\addons\DBTech\Shop\Pub\Controller\Lottery.php
- Edit function actionLottery like:
PHP:
public function actionLottery(ParameterBag $params)
    {
        $lottery = $this->assertLotteryExists($params->lottery_id);
        
        if (!$lottery->canView())
        {
            throw $this->exception($this->noPermission());
        }
        
        $finder = $lottery->getRelationFinder('History')
            ->order('draw_date', 'DESC')
        ;
        $total = $finder->total();
        
        $page = $this->filterPage();
        $perPage = $this->options()->dbtechShopLotteriesPerPage;
        
        $this->assertValidPage($page, $perPage, $total, 'dbtech-shop/lotteries', $lottery);
        $this->assertCanonicalUrl($this->buildLink('dbtech-shop/lotteries', $lottery, ['page' => $page]));
        
        $history = $finder->limitByPage($page, $perPage)->fetch();
        // Hoang Sang Get lottery ticket by user
        $visitor = \XF::visitor();
         $user_id = $visitor['user_id'];
        $tickets = $this->getLotteryRepo()
            ->findLotteryTicketsForLottery($lottery)
            ->where('user_id', $user_id)
            ->pluckFrom('numbers')->fetch();
        ;
        // End get lottery ticket by user
        $viewParams = [
            'lottery' => $lottery,
            'entry' => $tickets,  //Show tickets.
            'historyEntries' => $history,
            'page' => $page,
            'perPage' => $perPage,
            'total' => $total,
        ];
        return $this->view('DBTech\Shop:Lottery\View', 'dbtech_shop_lottery_view', $viewParams);
    }
- Edit function actionViewDraw like:
PHP:
public function actionViewDraw(ParameterBag $params)
    {
        $entry = $this->assertLotteryHistoryExists($params->lottery_history_id, ['Lottery']);
        $lottery = $entry->Lottery;
        
        if (!$lottery->canView())
        {
            throw $this->exception($this->noPermission());
        }
        //Hoang Sang---- get ticket by draw_date ------------
        $visitor = \XF::visitor();
         $user_id = $visitor['user_id'];       
        $draw_date = $entry -> draw_date;   
        $lottery_id = $entry -> lottery_id;   
        $tickets = $this->getLotteryRepo()
            ->findLotteryTicketsForLottery2($lottery)
            ->where
            ([
                'user_id' => $user_id,
                'lottery_id' => $lottery_id,
                'draw_date' => $draw_date
            ])           
            ->pluckFrom('numbers')->fetch()
        ;
        //End get ticket
        
        $viewParams = [
            'lottery' => $lottery,
            'entry' => $entry,
            'tickets' => $tickets        //Show my tickets Hoang Sang
        ];
        return $this->view('DBTech\Shop:Lottery\ViewDraw', 'dbtech_shop_lottery_view_draw', $viewParams);
    }
3. Edit template: dbtech_shop_lottery_view like:
HTML:
.......
<xf:formrow label="{{ phrase('dbtech_shop_tickets_sold') }}">
                {$lottery.tickets_sold|number}
            </xf:formrow>
            <xf:formrow label="{{ phrase('dbtech_shop_my_tickets_sold') }}">
                 <xf:foreach loop="$entry" value="$entry.numbers">
                    {$entry.numbers|join(' - ')} <br>
                </xf:foreach>
                
                
            </xf:formrow>
.......
4. Edit template: dbtech_shop_lottery_view_draw like
HTML:
..............
<xf:formrow label="{{ phrase('dbtech_shop_tickets_sold') }}">
                {$entry.tickets_sold|number}
            </xf:formrow>
            
            <xf:formrow label="{{ phrase('dbtech_shop_my_tickets_sold') }}">
                                
              <xf:foreach loop="$tickets" value="$tickets.numbers">
                    {$tickets.numbers|join(' - ')} <br>
                </xf:foreach>
             </xf:formrow>
................
5. Add phrase: dbtech_shop_my_tickets_sold
Title : dbtech_shop_my_tickets_sold
Phrase text: Your tickets
 
Status
Not open for further replies.
Back
Top