Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show orders history from shopify store ?

    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 772
    Comment on it

    This is our last blog on shopify where we will show listing of orders history of particular customer.
    With this api you can track all orders in your webview by passing only order number.

    1. Fetch orders in your main activity like this :

    private void fetchCustomerOrdersWithCallback(final Customer customer) {
    
        SampleApplication.getBuyClient().getOrders(new Callback<List<Order>>() {
            @Override
            public void success(final List<Order> orders) {
                if(orders.size()>0) {
                    OrderListAdapter orderListAdapter = new OrderListAdapter(MyOrderListActivity.this, orders, MyOrderListActivity.this);
                    rvOrderList.setAdapter(orderListAdapter);
                }else
                {
                    Toast.makeText(MyOrderListActivity.this, AppConstant.sNoOrder, Toast.LENGTH_LONG).show();
    
                }
            }
    
            @Override
            public void failure(final BuyClientError error) {
                System.out.println("fetchCustomerOrdersWithCallback failure" + error.toString());
    
            }
        });
    }

    Note : getOrder() is a callback method of shopify this will return list of orders :

    CancellableTask getOrders(Callback<List<Order>> callback);
    

    2. Set adapter for your list :

    public class OrderListAdapter extends RecyclerView.Adapter<OrderListAdapter.MyViewHolder> {
    
        private List<Order> orderList;
        private Activity mActivity;
        private OrderListClickInterface orderListClickListner;
    
        public OrderListAdapter(Activity aActivity, List<Order> orderList, OrderListClickInterface orderListClickListner) {
            this.orderList = orderList;
            this.orderListClickListner = orderListClickListner;
            mActivity = aActivity;
        }
    
        public static class MyViewHolder extends RecyclerView.ViewHolder {
            TextView tvOrderedWineName, tvOrderDeliveryDate, getTvOrderDeliverystatus, tvDeliveryText;
            LinearLayout linearLayoutOrderedWineRow;
            ImageView ivOrderedWine;
            ProgressBar progressBarOrderList;
    
            public MyViewHolder(View itemView) {
                super(itemView);
                this.tvDeliveryText = (TextView) itemView.findViewById(tv_DeliveryText);
                this.tvOrderedWineName = (TextView) itemView.findViewById(tvWineNameOrderList);
                this.tvOrderDeliveryDate = (TextView) itemView.findViewById(R.id.tvDeliveryDate);
                this.getTvOrderDeliverystatus = (TextView) itemView.findViewById(R.id.tvDeliveryState);
                this.progressBarOrderList = (ProgressBar) itemView.findViewById(R.id.wineLoadProgressBarOrderList);
                this.ivOrderedWine = (ImageView) itemView.findViewById(R.id.imgOrderedWine);
                this.progressBarOrderList.setVisibility(View.GONE);
                this.linearLayoutOrderedWineRow = (LinearLayout) itemView.findViewById(R.id.ll_ordered_wine_row);
                this.ivOrderedWine.setVisibility(View.GONE);
            }
        }
    
        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.order_list_item, parent, false);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }
    
        @Override
        public void onBindViewHolder(final MyViewHolder holder, final int listPosition) {
            Date date =orderList.get(listPosition).getProcessedAt();
            String dateString = new SimpleDateFormat("dd-MM-yyyy").format(date);
           // String dateString=orderList.get(listPosition).getProcessedAt().toString();
    
    
            List<LineItem> fulfillmentLineItem = orderList.get(listPosition).getFulfilledLineItems();
            List<LineItem> UnfulfillMentLineItem = orderList.get(listPosition).getUnfulfilledLineItems();
            holder.tvOrderDeliveryDate.setText(dateString+"");
    
            final String statusUrl=orderList.get(listPosition).getOrderStatusUrl();
            if (fulfillmentLineItem.size() > 0) {
                holder.tvOrderedWineName.setText(fulfillmentLineItem.get(0).getTitle());
                holder.getTvOrderDeliverystatus.setText("Delivered");
            } else if (UnfulfillMentLineItem.size() > 0) {
                holder.tvOrderedWineName.setText(UnfulfillMentLineItem.get(0).getTitle());
                holder.getTvOrderDeliverystatus.setText("Pending");
            }
            holder.linearLayoutOrderedWineRow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (Utills.isConnectingToInternet(mActivity)) {
                        orderListClickListner.OrderItemClicked(statusUrl);
                    } else {
    
                        Toast.makeText(mActivity, AppConstant.sNotConnected, Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    
        @Override
        public int getItemCount() {
            return orderList.size();
        }
    }

    Note : Here we are setting click listener on list item using interface and we are getting order url to show that in webview.

    3. implement onItem clicked in your main activity :

    @Override
    public void OrderItemClicked(String url) {
        Intent intent = new Intent(MyOrderListActivity.this, OrderTrackDetailActivity.class);
        intent.putExtra("URL", url);
        startActivity(intent);
    }

    4. Activity to show order tracking details only you have to set some webview in layout file:

    String url = getIntent().getStringExtra("URL");
    
    webView.loadUrl(url);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: