Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Success method does not work #4

Closed
krestt opened this issue Jul 13, 2024 · 3 comments
Closed

Success method does not work #4

krestt opened this issue Jul 13, 2024 · 3 comments

Comments

@krestt
Copy link

krestt commented Jul 13, 2024

Call to undefined method Webkul\Checkout\Cart::prepareDataForOrder()

Tasted on latest version of Bagisto

@krestt
Copy link
Author

krestt commented Jul 13, 2024

This Method does not exist enymore in latest Bagisto in
"packages\Webkul\Checkout\src\Cart.php"

`
/**
* Prepare data for order.
*/
public function prepareDataForOrder(): array
{
$data = $this->toArray();

    $finalData = [
        'cart_id'               => $this->getCart()->id,
        'customer_id'           => $data['customer_id'],
        'is_guest'              => $data['is_guest'],
        'customer_email'        => $data['customer_email'],
        'customer_first_name'   => $data['customer_first_name'],
        'customer_last_name'    => $data['customer_last_name'],
        'customer'              => auth()->guard()->check() ? auth()->guard()->user() : null,
        'total_item_count'      => $data['items_count'],
        'total_qty_ordered'     => $data['items_qty'],
        'base_currency_code'    => $data['base_currency_code'],
        'channel_currency_code' => $data['channel_currency_code'],
        'order_currency_code'   => $data['cart_currency_code'],
        'grand_total'           => $data['grand_total'],
        'base_grand_total'      => $data['base_grand_total'],
        'sub_total'             => $data['sub_total'],
        'base_sub_total'        => $data['base_sub_total'],
        'tax_amount'            => $data['tax_total'],
        'base_tax_amount'       => $data['base_tax_total'],
        'coupon_code'           => $data['coupon_code'],
        'applied_cart_rule_ids' => $data['applied_cart_rule_ids'],
        'discount_amount'       => $data['discount_amount'],
        'base_discount_amount'  => $data['base_discount_amount'],
        'billing_address'       => Arr::except($data['billing_address'], ['id', 'cart_id']),
        'payment'               => Arr::except($data['payment'], ['id', 'cart_id']),
        'channel'               => core()->getCurrentChannel(),
    ];

    if ($this->getCart()->haveStockableItems()) {
        $finalData = array_merge($finalData, [
            'shipping_method'               => $data['selected_shipping_rate']['method'],
            'shipping_title'                => $data['selected_shipping_rate']['carrier_title'].' - '.$data['selected_shipping_rate']['method_title'],
            'shipping_description'          => $data['selected_shipping_rate']['method_description'],
            'shipping_amount'               => $data['selected_shipping_rate']['price'],
            'base_shipping_amount'          => $data['selected_shipping_rate']['base_price'],
            'shipping_address'              => Arr::except($data['shipping_address'], ['id', 'cart_id']),
            'shipping_discount_amount'      => $data['selected_shipping_rate']['discount_amount'],
            'base_shipping_discount_amount' => $data['selected_shipping_rate']['base_discount_amount'],
        ]);
    }

    foreach ($data['items'] as $item) {
        $finalData['items'][] = $this->prepareDataForOrderItem($item);
    }

    if ($finalData['payment']['method'] === 'paypal_smart_button') {
        $finalData['payment']['additional'] = request()->get('orderData');
    }

    return $finalData;
}

`

@krestt
Copy link
Author

krestt commented Jul 14, 2024

Ok, I found the solution.... I will post it here:
I took the success function from Paypal payment Method,
so all I had to do is:

  1. Open : vendor\wontonee\stripe\src\Http\Controllers\StripeController.php
  2. Add use Webkul\Sales\Transformers\OrderResource;
  3. Replace the existing success method with:
    public function success()
    {
    $cart = Cart::getCart();
    $data = (new OrderResource($cart))->jsonSerialize();
    $order = $this->orderRepository->create($data);
    Cart::deActivateCart();
    session()->flash('order_id', $order->id);
    return redirect()->route('shop.checkout.onepage.success');
    }

@wontone18
Copy link
Owner

Hi

you should use their github version not the one which they are giving from installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants