简体   繁体   中英

OctoberCMS - How to call a function inside a component

I am building an order form and I warn you in advance I am a noob with backend dev :)

So my first component takes all data from the order form and saves it to the database, then I use this same data to generate a quote. After this I have a thrird part which generates the invoice if the quote is accepted, so far my code looks like this:

// this runs when order is submitted on front end (runs from same component)
public function onAddOrder() {
    $this->submitOrder();
    $this->submitQuote();
    Flash::success('Order successfully submitted!');
    return Redirect::to('/home');
}

public function submitOrder() {
        // Add it to the database
        $order = new Order();
        $order ->quote_no = $this->generateQuoteNo();
        $order ->company_name = Input::get('company_name');
        $order ->client_name = Input::get('client_name');
        $order ->client_email = Input::get('client_email');
        $order ->emergency_contact = Input::get('emergency_contact');
        $order ->due_date = Input::get('due_date');
        $order ->project_name = Input::get('project_name');
        $order ->quote_query = Input::get('quote_query');
        $order ->order_no = Input::get('order_no');
        $order ->order_type = Input::get('order_type');
        $order ->save();
    }
}

public function submitQuote() {
    $quote = new Quote();
    $quote->quote_no = $this->generateQuoteNo();
    $quote->customer = Input::get('company_name');
    $quote->job_name = Input::get('project_name');
    $quote->order_no = Input::get('order_no');
    $quote->proof_price = $this->calculateProofPrice();
    $quote->sub_total = $this->calculateSubTotal();
    $quote->vat = $this->calculateVat();
    $quote->total = $this->calculateTotal();
    $quote->save();        
}

This works fine but then I would like to run another function if a selection is made but this component is under a different class and I am not sure how to reference it.

if (Input::get('quote_query') === 'Order') {
        $this->AcmeInvoice->onSubmitInvoice();
    }

If someone could help me to fire the public function onSubmitInvoice() I will really appreciate it.

You can instantiate the object in the class & fire it off? eg: $invoice = new AcmeInvoice(); //add namespace if not in the name space; $invoice->onSubmitInvoice();

 if (Input::get('query') === 'Invoice') {
            $invoice = new AcmeInvoice();
            $invoice->onSubmitInvoice('quote_no');
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM