You need to sign in or sign up before continuing.
Commit 95c510b6 by Angel FS

Subcategory page completed

parent 55be8c37
......@@ -70,6 +70,8 @@
046618E627EC2DB500D65702 /* Onboarding.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 046618E527EC2DB500D65702 /* Onboarding.storyboard */; };
0466828C27F4262400696FB4 /* ItemListCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0466828B27F4262400696FB4 /* ItemListCollectionViewCell.swift */; };
0466828F27F4264300696FB4 /* ItemsListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0466828E27F4264300696FB4 /* ItemsListTableViewCell.swift */; };
0469CB222892C07B00A71453 /* SubCatModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0469CB212892C07B00A71453 /* SubCatModel.swift */; };
0469CB252892C13B00A71453 /* SubCatVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0469CB242892C13B00A71453 /* SubCatVM.swift */; };
046D44592872B82A0097BFF0 /* SearchViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 046D44582872B82A0097BFF0 /* SearchViewModel.swift */; };
047234A6288018FB000407B1 /* ProductByIdModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047234A5288018FB000407B1 /* ProductByIdModel.swift */; };
047234A928801AAA000407B1 /* SeeAllItemsVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047234A828801AAA000407B1 /* SeeAllItemsVM.swift */; };
......@@ -126,8 +128,8 @@
04158CF4282A3D9B00C03E36 /* ImageListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageListVC.swift; sourceTree = "<group>"; };
04158CF7282A3E0E00C03E36 /* ImagesCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ImagesCollectionViewCell.swift; path = Garmentoo/Controller/Main/ImagesCollectionViewCell.swift; sourceTree = SOURCE_ROOT; };
041762B9284628030017B676 /* TabVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabVC.swift; sourceTree = "<group>"; };
041CEE8E2849E75C00D05C61 /* SubCategoryVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SubCategoryVC.swift; path = Garmentoo/Controller/SubCategoryVC.swift; sourceTree = SOURCE_ROOT; };
041CEE922849E85A00D05C61 /* SubcategoryCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SubcategoryCollectionViewCell.swift; path = Garmentoo/Controller/Main/SubcategoryCollectionViewCell.swift; sourceTree = SOURCE_ROOT; };
041CEE8E2849E75C00D05C61 /* SubCategoryVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SubCategoryVC.swift; path = Garmentoo/Controller/Modules/Home/SubCategoryVC.swift; sourceTree = SOURCE_ROOT; };
041CEE922849E85A00D05C61 /* SubcategoryCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SubcategoryCollectionViewCell.swift; path = Garmentoo/Controller/Modules/Home/Cells/CVC/SubcategoryCollectionViewCell.swift; sourceTree = SOURCE_ROOT; };
041E8686280FF093002AF111 /* AddAddress2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAddress2.swift; sourceTree = "<group>"; };
041F7F8B28620D5000F21F1A /* PostApiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostApiService.swift; sourceTree = "<group>"; };
04204F6E27FFFFC700DEE8A9 /* NotificationsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NotificationsTableViewCell.swift; path = Garmentoo/Cells/TVC/NotificationsTableViewCell.swift; sourceTree = SOURCE_ROOT; };
......@@ -173,6 +175,8 @@
046618E527EC2DB500D65702 /* Onboarding.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Onboarding.storyboard; sourceTree = "<group>"; };
0466828B27F4262400696FB4 /* ItemListCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemListCollectionViewCell.swift; sourceTree = "<group>"; };
0466828E27F4264300696FB4 /* ItemsListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsListTableViewCell.swift; sourceTree = "<group>"; };
0469CB212892C07B00A71453 /* SubCatModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubCatModel.swift; sourceTree = "<group>"; };
0469CB242892C13B00A71453 /* SubCatVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubCatVM.swift; sourceTree = "<group>"; };
046D44582872B82A0097BFF0 /* SearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewModel.swift; sourceTree = "<group>"; };
047234A5288018FB000407B1 /* ProductByIdModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductByIdModel.swift; sourceTree = "<group>"; };
047234A828801AAA000407B1 /* SeeAllItemsVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeeAllItemsVM.swift; sourceTree = "<group>"; };
......@@ -261,6 +265,7 @@
046D44582872B82A0097BFF0 /* SearchViewModel.swift */,
043366D6286037A600B10DCB /* HomeViewModel.swift */,
047234A828801AAA000407B1 /* SeeAllItemsVM.swift */,
0469CB242892C13B00A71453 /* SubCatVM.swift */,
);
path = VM;
sourceTree = "<group>";
......@@ -384,6 +389,7 @@
04D333C7283F5B50002BE271 /* HomeCategCollectionViewCell.swift */,
04605B8E284094C000A15B84 /* HomePopularCollectionViewCell.swift */,
04605B912840AB5D00A15B84 /* HomemadeforyouCollectionViewCell.swift */,
041CEE922849E85A00D05C61 /* SubcategoryCollectionViewCell.swift */,
04605B952840C91700A15B84 /* HomeRecommendedCollectionViewCell.swift */,
04BD608E286F048E00379038 /* SearchCVC.swift */,
);
......@@ -396,6 +402,7 @@
042E8623286B0E1200BB12FC /* SearchModel.swift */,
043366DA286038C600B10DCB /* Home2Model.swift */,
047234A5288018FB000407B1 /* ProductByIdModel.swift */,
0469CB212892C07B00A71453 /* SubCatModel.swift */,
);
path = Model;
sourceTree = "<group>";
......@@ -481,7 +488,6 @@
04960C9F27F5B51E00299FE2 /* CVC */ = {
isa = PBXGroup;
children = (
041CEE922849E85A00D05C61 /* SubcategoryCollectionViewCell.swift */,
04158CF7282A3E0E00C03E36 /* ImagesCollectionViewCell.swift */,
048DE66D28116F9A0078C1E1 /* ImageCollectionViewCell.swift */,
0431513927FDADB800634714 /* MyOrderCategCollectionViewCell.swift */,
......@@ -557,6 +563,7 @@
04D333C3283F5955002BE271 /* Home1VC.swift */,
04AC8EC8282180D80035CDA1 /* SeeAllItemsVC.swift */,
04BD608B286F034500379038 /* SearchVC.swift */,
041CEE8E2849E75C00D05C61 /* SubCategoryVC.swift */,
04754C37286EF817003E812B /* Cells */,
042B9A13287C1E6F00A535F6 /* VM */,
04754C3A286EF84C003E812B /* Model */,
......@@ -579,7 +586,6 @@
children = (
041762B9284628030017B676 /* TabVC.swift */,
048D36B427F2E6B40000B3AC /* HomeVC.swift */,
041CEE8E2849E75C00D05C61 /* SubCategoryVC.swift */,
040098EA28069F8300E76FD4 /* TrackingVC.swift */,
04DDE4FA27FFFECC00623394 /* NotificationVC.swift */,
04158CF4282A3D9B00C03E36 /* ImageListVC.swift */,
......@@ -754,6 +760,7 @@
0466828F27F4264300696FB4 /* ItemsListTableViewCell.swift in Sources */,
0443FEAB28774CAF000112AD /* ProfileModel.swift in Sources */,
04A8BC8C27ED8169004D221F /* SigninVC.swift in Sources */,
0469CB222892C07B00A71453 /* SubCatModel.swift in Sources */,
04B52CF127FD6FFD00968B97 /* ItemsCollectionViewCell.swift in Sources */,
041F7F8C28620D5000F21F1A /* PostApiService.swift in Sources */,
04DDE4FB27FFFECC00623394 /* NotificationVC.swift in Sources */,
......@@ -831,6 +838,7 @@
040098EB28069F8300E76FD4 /* TrackingVC.swift in Sources */,
04BD608F286F048E00379038 /* SearchCVC.swift in Sources */,
04605B922840AB5D00A15B84 /* HomemadeforyouCollectionViewCell.swift in Sources */,
0469CB252892C13B00A71453 /* SubCatVM.swift in Sources */,
047EAF7627EDE28B00222ED6 /* ConfirmAddressVC.swift in Sources */,
045B65D128856215004EB5F8 /* FavouritesVM.swift in Sources */,
044839BC27F474EA00A72E1F /* SettingsTableViewCell.swift in Sources */,
......
......@@ -6,8 +6,29 @@
//
import UIKit
import Kingfisher
class SubcategoryCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var img:UIImageView!
@IBOutlet weak var titleText:UILabel!
var subCatDetails : Subcategories?
{
didSet
{
self.titleText.text = subCatDetails?.name
let imagelink = subCatDetails?.image
if imagelink != nil
{
let url = URL(string:(RestApiManager.sharedInstance.baseURL + imagelink!))
self.img.kf.indicatorType = .activity
self.img.kf.setImage(with: url, placeholder: UIImage(named: "placeholderImage"), options: .none, completionHandler: nil)
}
}
}
override func setNeedsLayout() {
}
}
......@@ -197,7 +197,7 @@ extension Home1VC:UICollectionViewDelegate,UICollectionViewDataSource
if (collectionView == categCV)
{
let sb = UIStoryboard(name: "Main", bundle: nil)
let nextVc = sb.instantiateViewController(withIdentifier: "SeeAllItemsVC") as! SeeAllItemsVC
let nextVc = sb.instantiateViewController(withIdentifier: "SubCategoryVC") as! SubCategoryVC
nextVc.header = self.homeViewModel.Model?.categories?[indexPath.row].category ?? ""
nextVc.catId = self.homeViewModel.Model?.categories?[indexPath.row].category_id ?? ""
nextVc.hidesBottomBarWhenPushed = true
......
//
// SubCatModel.swift
// Garmentoo
//
// Created by Angel F Syrus on 28/07/22.
//
import Foundation
struct SubCatModel : Codable {
let status : Bool?
let message : String?
let subcategories : [Subcategories]?
enum CodingKeys: String, CodingKey {
case status = "status"
case message = "message"
case subcategories = "subcategories"
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
status = try values.decodeIfPresent(Bool.self, forKey: .status)
message = try values.decodeIfPresent(String.self, forKey: .message)
subcategories = try values.decodeIfPresent([Subcategories].self, forKey: .subcategories)
}
}
struct Subcategories : Codable {
let category_id : String?
let name : String?
let image : String?
enum CodingKeys: String, CodingKey {
case category_id = "category_id"
case name = "name"
case image = "image"
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
category_id = try values.decodeIfPresent(String.self, forKey: .category_id)
name = try values.decodeIfPresent(String.self, forKey: .name)
image = try values.decodeIfPresent(String.self, forKey: .image)
}
}
......@@ -13,11 +13,11 @@ class SubCategoryVC: UIViewController {
@IBOutlet weak var headerTitle:UILabel!
@IBOutlet weak var subcategCV:UICollectionView!
// var subcategName = []
// var subcategImage = []
var header = ""
var catId = ""
let subCatVM = SubCatVM()
var subCatList : [Subcategories]?
override func viewDidLoad() {
super.viewDidLoad()
......@@ -26,6 +26,7 @@ class SubCategoryVC: UIViewController {
// Do any additional setup after loading the view.
subcategCV.backgroundColor = UIColor.viewBg
headerTitle.text = header
self.subCatDetails()
}
func flowlayout()
......@@ -46,21 +47,24 @@ class SubCategoryVC: UIViewController {
extension SubCategoryVC:UICollectionViewDelegate,UICollectionViewDataSource
{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
return self.subCatVM.subCatModel?.subcategories?.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "subcategCell", for: indexPath) as! SubcategoryCollectionViewCell
// cell.titleText.text = subcategName[indexPath.row]
// cell.img.image = categImg[indexPath.row]
if !(self.subCatVM.subCatModel?.subcategories?.isEmpty ?? false)
{
cell.subCatDetails = self.subCatList?[indexPath.row]
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let sb = UIStoryboard(name: "Main", bundle: nil)
let nextVc = sb.instantiateViewController(withIdentifier: "ProductDetailVC") as! ProductDetailVC
nextVc.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(nextVc, animated: true)
// let sb = UIStoryboard(name: "Main", bundle: nil)
// let nextVc = sb.instantiateViewController(withIdentifier: "ProductDetailVC") as! ProductDetailVC
// nextVc.hidesBottomBarWhenPushed = true
// self.navigationController?.pushViewController(nextVc, animated: true)
}
}
......@@ -84,3 +88,33 @@ extension SubCategoryVC:UICollectionViewDelegateFlowLayout
}
}
extension SubCategoryVC
{
func subCatDetails()
{
DispatchQueue.main.async {
AppInstance.showLoader()
self.subCatVM.getSubCatDetails(catId: self.catId)
}
self.subCatVM.subCatDatahData.bind { (subcatModel) in
if subcatModel?.status == true
{
self.subCatList = subcatModel?.subcategories
DispatchQueue.main.async {
AppInstance.hideLoader()
self.subcategCV.reloadData()
}
}
else
{
DispatchQueue.main.async {
AppInstance.hideLoader()
self.showSnackBar(Message: subcatModel?.message ?? "Something went wrong!!!", duration: .middle)
}
}
}
}
}
......@@ -21,7 +21,7 @@ class SearchViewModel {
func searchItems(key : String)
{
let parameters = "{\"search_key\":\"Ana Running Short\"}"
let parameters = "{\"search_key\":\"\(key)\"}"
let postData = parameters.data(using: .utf8)
PostApiService.searchData(params: postData!) { (success, data, message) in
......
//
// SubCatVM.swift
// Garmentoo
//
// Created by Angel F Syrus on 28/07/22.
//
import Foundation
import UIKit
class SubCatVM {
let apiDataParser = PostApiService()
var subCatDatahData = Bindable<SubCatModel>()
var subCatModel: SubCatModel? {
didSet {
self.subCatDatahData.value = subCatModel
}
}
func getSubCatDetails(catId : String)
{
let parameters = "{\"category_id\":\(catId)}"
let postData = parameters.data(using: .utf8)
PostApiService.getSubCat(params: postData!) { (success, data, message) in
if success && data?[0].status == true
{
self.subCatModel = data?[0]
}
else
{
DispatchQueue.main.async {
AppInstance.hideLoader()
}
print(message ?? "Something went wrong")
return
}
}
}
}
......@@ -16,6 +16,13 @@ class CartVM
}
}
var removeCartData = Bindable<StatusMessageModel>()
var removeCartModel: StatusMessageModel? {
didSet {
self.removeCartData.value = removeCartModel
}
}
var cartData = Bindable<CartListModel>()
var cartModel: CartListModel? {
didSet {
......@@ -45,7 +52,6 @@ class CartVM
{
let parameters = "{\"product_id\": \(prdctId),\"quantity\": 1}"
let postData = parameters.data(using: .utf8)
print(parameters)
PostApiService.addToCart(params: postData!) { (status, data, message) in
if status && data?[0].status == true
......@@ -63,5 +69,26 @@ class CartVM
}
}
func removeFromCart(cartId : String)
{
let parameters = "{\"quote_id\": \(cartId)}"
let postData = parameters.data(using: .utf8)
print(parameters)
PostApiService.removeFromCart(params: postData!) { (status, data, message) in
if status && data?[0].status == true
{
self.removeCartModel = data?[0]
}
else
{
DispatchQueue.main.async {
self.removeCartModel = data?[0]
AppInstance.hideLoader()
}
return
}
}
}
}
......@@ -128,5 +128,27 @@ extension MyCartVC
}
}
}
func removeFromCart(cartId : String)
{
DispatchQueue.main.async {
AppInstance.showLoader()
}
self.cartVM.removeFromCart(cartId: cartId)
self.cartVM.removeCartData.bind { (cartData) in
DispatchQueue.main.async {
AppInstance.hideLoader()
}
if cartData?.status == true
{
self.showSnackBar(Message: cartData?.message ?? "Success", duration: .middle)
}
else
{
self.showSnackBar(Message: cartData?.message ?? "Something went wrong!!!", duration: .middle)
}
}
}
}
......@@ -495,5 +495,76 @@ struct PostApiService {
}
}
}
// Product remove from cart
static func removeFromCart(params: Data, complete:@escaping ( Bool , _ serviceList:[StatusMessageModel]?,_ errorString : String?) -> ())
{
let url = RestApiManager.sharedInstance.baseURL + "/rest/V2/cart_remove"
var request = URLRequest(url: NSURL.init(string: url)! as URL)
request.httpMethod = "POST"
request.addValue(self.getAccessToken(), forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = params
AF.request(request).validate().responseJSON { response in
switch response.result
{
case .success( _):
if response.response?.statusCode == 200
{
if let jsonData = response.data {
let jsonDecoder = JSONDecoder()
do {
_ = String(data: response.data!, encoding: String.Encoding.utf8)
let responseOBJ = try jsonDecoder.decode([StatusMessageModel].self, from: jsonData)
// print(responseOBJ)
complete(true, responseOBJ, responseOBJ[0].message)
}catch _{
complete(false,[], response.error?.localizedDescription)
}
}
}
case .failure( _):
complete( false,nil,"Something went wrong")
}
}
}
// SubCategories from Category Id
static func getSubCat(params: Data, complete:@escaping ( Bool , _ serviceList:[SubCatModel]?,_ errorString : String?) -> ())
{
let url = RestApiManager.sharedInstance.baseURL + "/rest/V2/subcategory"
var request = URLRequest(url: NSURL.init(string: url)! as URL)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = params
AF.request(request).validate().responseJSON { response in
switch response.result
{
case .success( _):
if response.response?.statusCode == 200
{
if let jsonData = response.data {
let jsonDecoder = JSONDecoder()
do {
_ = String(data: response.data!, encoding: String.Encoding.utf8)
let responseOBJ = try jsonDecoder.decode([SubCatModel].self, from: jsonData)
complete(true, responseOBJ, responseOBJ[0].message)
}catch _{
complete(false,[], response.error?.localizedDescription)
}
}
}
case .failure( _):
complete( false,nil,"Something went wrong")
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment