public function freepurchaseAction() { $producturrency = new Admin_Model_DbTable_Countries(); $modelAuthor = new Publisher_Model_DbTable_Publishers(); $tempObj = new Model_DbTable_Checkout(); $creditHistoryObj = new User_Model_DbTable_Chistory(); $transactionHistoryObj = new User_Model_DbTable_Transactionhistory(); $this->modelBooks = new Publisher_Model_DbTable_Books(); $modelImage = new Publisher_Model_DbTable_BookImages(); $modelStore = new Admin_Model_DbTable_Countries(); $productPrice = new Publisher_Model_DbTable_BookPrices(); $productPrice = new Publisher_Model_DbTable_BookPrices(); $orderId = time(); $subscription_store = ""; $subscription_language = ""; $subscription_issues = ""; $formDataTransApproved = array("orderId" => $orderId, "transactionType" => $transactionType, "pan" => $pan, "purchaseAmount" => $purchaseAmount, "tranDateTime" => $tranDateTime, "responseCode" => $responseCode, "responseDescription" => $responseDescription, "orderStatus" => $orderStatus, "approvalCode" => $approvalCode, "approvalCode" => $approvalCode, "merchantTranId" => $merchantTranId, "orderDescription" => $orderDescription, "approvalCodeScr" => $approvalCodeScr, "currency" => $currency, "threeDsVerification" => $threeDsVerification); $inserted_id = $transactionHistoryObj->insert($formDataTransApproved); $tempData = $tempObj->fetchAll("order_id='" . $orderIdForPurchase . "'"); foreach ($tempData as $dataDet) { $productPriceInfo = $productPrice->getPriceByStoreId($dataDet['product_id'], $dataDet['store_id']); if ($dataDet['subscription_type'] == '' || $dataDet['subscription_type'] == '0') { if ($dataDet['group_id'] > 0) { $price = $productPriceInfo['group_price']; } else { $price = $productPriceInfo['price']; } } else { $price = $dataDet['subscription_price']; $subscription_store = $dataDet['subscription_store']; $subscription_language = $dataDet['subscription_language']; $subscription_issues = $dataDet['subscription_issues']; } if ($orderStatus == 'APPROVED') { $orderSt = 1; } else { $orderSt = 0; } $product_details = $this->modelBooks->fetchRow("id='" . $dataDet['product_id'] . "'"); $getBrandInfo = $this->modelBooks->getBrandInfo($product_details['title']); if (!empty($getBrandInfo) && is_numeric($this->{$product_details}['title'])) { $titleBrand = $getBrandInfo['brand']; } else { $titleBrand = $product_details['title']; } if (!empty($product_details['parent_brand_id']) && $product_details['cat_id'] != '3') { $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"'); $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title); if (!empty($getParentBrandInfo)) { $titleBrand = $getParentBrandInfo['brand'] . " - " . $titleBrand; } } $getCurrencyName = $producturrency->getCurrencyCode($dataDet['store_id']); $authorInfo = $modelAuthor->getInfoByPublisherId($product_details['author_id']); $imageInfo = $modelImage->getImageInfoByProductId($product_details['id']); $tempDatInsert = array(); $tempDatInsert['userid'] = $dataDet['user_id']; $tempDatInsert['bookid'] = $dataDet['product_id']; $tempDatInsert['store_id'] = $dataDet['store_id']; $tempDatInsert['price'] = $price; $tempDatInsert['userid'] = $dataDet['user_id']; $tempDatInsert['quantity'] = $dataDet['quntity']; $tempDatInsert['book_name'] = $titleBrand; $tempDatInsert['transaction_id'] = $inserted_id; $tempDatInsert['add_date'] = date('Y-m-d H:i:s'); $tempDatInsert['group_id'] = $dataDet['group_id']; $tempDatInsert['order_id'] = $dataDet['order_id']; $tempDatInsert['payment_status'] = $orderSt; $tempDatInsert['subscription_type'] = $dataDet['subscription_type']; $tempDatInsert['subscription_name'] = $dataDet['subscription_name']; $tempDatInsert['subscription_store'] = $dataDet['subscription_store']; $tempDatInsert['subscription_language'] = $dataDet['subscription_language']; $tempDatInsert['subscription_issues'] = $dataDet['subscription_issues']; $creditHistoryObj->insert($tempDatInsert); $total_price = $total_price + $dataDet['quntity'] * $price; $todaysdate = date('Y-m-d H:i:s'); if ($dataDet['subscription_name'] == 'Weekly') { $date = new DateTime($todaysdate); $date->modify("+7 day"); $end_date = $date->format("Y-m-d H:i:s"); } else { if ($dataDet['subscription_name'] == 'Monthly') { $date = new DateTime($todaysdate); $date->modify("+30 day"); $end_date = $date->format("Y-m-d H:i:s"); } else { if ($dataDet['subscription_name'] == 'Quarterly') { $date = new DateTime($todaysdate); $date->modify("+90 day"); $end_date = $date->format("Y-m-d H:i:s"); } else { if ($dataDet['subscription_name'] == 'Half Yearly') { $date = new DateTime($todaysdate); $date->modify("+182 day"); $end_date = $date->format("Y-m-d H:i:s"); } else { if ($dataDet['subscription_name'] == 'Yearly') { $date = new DateTime($todaysdate); $date->modify("+365 day"); $end_date = $date->format("Y-m-d H:i:s"); } } } } } $subscriptionObj = array(); $subscriptionObj['order_id'] = $orderid; $subscriptionObj['product_id'] = $dataDet['product_id']; $subscriptionObj['group_id'] = $dataDet['group_id']; $subscriptionObj['user_id'] = ''; $subscriptionObj['subscription_type'] = $dataDet['subscription_type']; $subscriptionObj['subscription_name'] = $dataDet['subscription_name']; $subscriptionObj['subscription_price'] = $price; $subscriptionObj['country'] = $dataDet['subscription_store']; $subscriptionObj['language'] = $dataDet['subscription_language']; $subscriptionObj['number_of_issues'] = $dataDet['subscription_issues']; $subscriptionObj['start_date'] = date('Y-m-d H:i:s'); $subscriptionObj['end_date'] = $end_date; $subscriptionObj['remaining_downloads'] = $dataDet['subscription_issues']; $subscriptionObj['publication_id'] = $product_details['parent_brand_id']; $UsersubObj->insert($subscriptionObj); } $tempObj->delete('order_id="' . $orderIdForPurchase . '"'); $this->_redirect('/checkout/displayorder/orderid/' . $orderIdForPurchase); //exit; }
public function activeAction() { $arrayids = array(); $this->usersubscriptions = new Model_DbTable_Usersubscription(); $this->userdetails = new Model_DbTable_Companies(); $modelCategory = new Publisher_Model_DbTable_Books(); $this->notifications = new Admin_Model_DbTable_Notifications(); $modelImage = new Admin_Model_DbTable_ProductImages(); $modelPrice = new Admin_Model_DbTable_ProductPrices(); $creditHistoryObj = new User_Model_DbTable_Chistory(); $this->modelBooks = new Publisher_Model_DbTable_Books(); $notificationdata = $this->notifications->fetchAll('ntype="booksubscription" and status=1'); $bookuploaddata = $this->notifications->fetchAll('ntype="bookupload" and status=1'); $pid = $this->_request->getParam('pid', 0); $id = $this->_request->getParam('id', 0); $transactionHistoryObj = new User_Model_DbTable_Transactionhistory(); if ($id > 0 && $this->modelPublications->isExist($id)) { $data['admin_approve'] = 1; $success = $this->modelPublications->update($data, 'id="' . $id . '"'); if ($success) { $this->usersubscriptionsdata = $this->usersubscriptions->fetchAll('subscription_type >0 and publication_id=' . $pid . ' and start_date!="0000-00-00 00:00:00"'); if (count($this->usersubscriptionsdata) > 0) { if (count($bookuploaddata) > 0) { foreach ($this->usersubscriptionsdata as $row_subdata) { /*echo "publication id : - ".$pid; echo 'subscription_type >0 AND number_of_issues > number_of_downloaded and product_id='.$id.' and user_id="'.$row_userids['id'].'"'; die();*/ $product_details = $this->modelBooks->fetchRow("id='" . $id . "'"); $explode_product_addtime = @explode(" ", $product_details['add_time']); $explode_start_date = @explode(" ", $row_subdata['start_date']); $this->totalactivesubscription = $this->usersubscriptions->fetchAll('subscription_type >0 and publication_id=' . $pid . ' and user_id="' . $row_subdata['user_id'] . '" and start_date IS NULL'); $this->totalactivesubscription_with_startdate = $this->usersubscriptions->fetchAll('subscription_type >0 AND number_of_issues > number_of_downloaded and publication_id=' . $pid . ' and user_id="' . $row_subdata['user_id'] . '" and start_date IS NOT NULL'); $totalactive = count($this->totalactivesubscription) + 1; if ($this->totalactivesubscription_with_startdate[0]['number_of_issues'] > $totalactive && strtotime($product_details['add_time']) > strtotime($row_subdata['start_date'])) { $this->userdata = $this->userdetails->fetchAll('id="' . $row_subdata['user_id'] . '" and status="1"'); $chk_subscription = $this->usersubscriptions->fetchAll('user_id="' . $row_subdata['user_id'] . '" and product_id="' . $id . '"'); if (count($chk_subscription) == 0) { $getBrandInfo = $this->modelBooks->getBrandInfo($product_details['title']); if (!empty($getBrandInfo) && is_numeric($product_details['title'])) { $titleBrand = $getBrandInfo['brand']; } else { $titleBrand = $product_details['title']; } if (!empty($product_details['parent_brand_id']) && $product_details['cat_id'] != '3') { $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"'); $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title); if (!empty($getParentBrandInfo)) { $titleBrand = $getParentBrandInfo['brand']; } } $productInfo = $this->modelBooks->fetchRow('id="' . $product_details['parent_brand_id'] . '"'); $getParentBrandInfo = $this->modelBooks->getBrandInfo($productInfo->title); if (!empty($getParentBrandInfo)) { //$titleBrand=$titleBrand.' ('.$getParentBrandInfo['brand'].')'; //$titleBrand=$getParentBrandInfo['brand']." - ".$titleBrand; $titleBrand = $getParentBrandInfo['brand']; } $tempDatInsert = array(); $formDataTransApproved = array(); $getdata = $transactionHistoryObj->fetchRow('orderId=' . $row_subdata['order_id'] . ''); $tempDatInsert['userid'] = $row_subdata['user_id']; $tempDatInsert['bookid'] = $id; $tempDatInsert['store_id'] = '226'; $tempDatInsert['price'] = $row_subdata['subscription_price']; $tempDatInsert['quantity'] = '1'; $tempDatInsert['transaction_id'] = $getdata->id; $tempDatInsert['book_name'] = $titleBrand; $tempDatInsert['add_date'] = date('Y-m-d H:i:s'); $tempDatInsert['group_id'] = $this->userdata[0]['group_id']; $tempDatInsert['order_id'] = $row_subdata['order_id']; $tempDatInsert['payment_status'] = '1'; $tempDatInsert['converted_price'] = $row_subdata['subscription_price']; $tempDatInsert['subscription_type'] = $row_subdata['subscription_type']; $tempDatInsert['subscription_store'] = $row_subdata['country']; $tempDatInsert['subscription_language'] = $row_subdata['language']; $tempDatInsert['subscription_name'] = $row_subdata['subscription_name']; $creditHistoryObj->insert($tempDatInsert); $formDataTransApproved = array("orderId" => $row_subdata['order_id'], "transactionType" => $getdata->transactionType, "pan" => $getdata->pan, "purchaseAmount" => $getdata->purchaseAmount, "tranDateTime" => $getdata->tranDateTime, "responseCode" => $getdata->responseCode, "responseDescription" => $getdata->responseDescription, "orderStatus" => $getdata->orderStatus, "approvalCode" => $getdata->approvalCode, "merchantTranId" => $getdata->merchantTranId, "orderDescription" => $getdata->orderDescription, "approvalCodeScr" => $getdata->approvalCodeScr, "currency" => $getdata->currency, "brand" => $getdata->brand, "card_holder_name" => $getdata->card_holder_name, "ThreeDSStatus" => $getdata->ThreeDSStatus, "threeDsVerification" => $getdata->threeDsVerification, "transaction_xml" => $getdata->transaction_xml); $inserted_id = $transactionHistoryObj->insert($formDataTransApproved); $insert_user_sub_details_array = array("order_id" => $row_subdata['order_id'], "product_id" => $id, "publisher_id" => $row_subdata['publisher_id'], "author_id" => $row_subdata['author_id'], "group_id" => $this->userdata[0]['group_id'], "user_id" => $row_subdata['user_id'], "subscription_type" => $row_subdata['subscription_type'], "subscription_name" => $row_subdata['subscription_name'], "subscription_price" => $row_subdata['subscription_price'], "country" => $row_subdata['country'], "language" => $row_subdata['language'], "publication_id" => $row_subdata['publication_id'], "company_id" => $this->userdata[0]['parent_id'], "active_date" => date('Y-m-d H:i:s')); $this->usersubscriptions->insert($insert_user_sub_details_array); $sql1 = "update pclive_products set best_seller=best_seller+1 where id='" . $id . "'"; $result1 = $this->modelBooks->getAdapter()->query($sql1); } $publicationdetails = $this->modelPublications->fetchAll('id=' . $id . ''); $product_price = $modelPrice->fetchAll('product_id="' . $id . '" and country_id=226 and language_id=1'); $getproductimage = $modelImage->fetchAll('product_id="' . $publicationdetails[0]['id'] . '"'); $publisher_info_array = $this->modelPublications->getPublisherInfo($publicationdetails[0]['publisher_id']); $author_info_array = $this->modelPublications->getAuthorInfo($publicationdetails[0]['author_id']); $getBrandInfo = $modelCategory->getBrandInfo($publicationdetails[0]['title']); if (!empty($getBrandInfo)) { $titleBrand = $getBrandInfo['brand']; } else { $titleBrand = $publicationdetails[0]['title']; } $fullname = $this->userdata[0]['first_name'] . ' ' . $this->userdata[0]['last_name']; $description_full = stripslashes($bookuploaddata[0]['message_body']); $description_full = nl2br($description_full); $description = str_replace("{name}", $fullname, $description_full); $description = str_replace("{title}", $titleBrand, $description); if (count($this->usersubscriptionsdata) > 0) { $description = str_replace("{price}", "N/A", $description); } else { if (isset($product_price[0]['price']) && $product_price[0]['price'] != '') { $description = str_replace("{price}", "₦" . $product_price[0]['price'], $description); } } if (count($getproductimage) > 0) { $linkdata = 'http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/catalogue/detail/id/' . $publicationdetails[0]['id'] . '/store/226/lang/1'; } else { $linkdata = "javascript:void(0);"; } $description = str_replace("{link}", $linkdata, $description); if (count($getproductimage) > 0) { $imagedata = 'http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/public/uploads/users/' . $getproductimage[0]['image_name_thumb'] . ''; } else { $imagedata = ""; } $description = str_replace("{image}", $imagedata, $description); $publishername = $publisher_info_array['first_name'] . " " . $publisher_info_array['last_name']; $authorname = $author_info_array['first_name'] . " " . $author_info_array['last_name']; $description = str_replace("{publisher}", $publishername, $description); $description = str_replace("{desc}", $publicationdetails[0]['description'], $description); $description = str_replace("{author}", $authorname, $description); $mailhost = SMTP_SERVER; $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD); $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig); Zend_Mail::setDefaultTransport($transport); $mail = new Zend_Mail(); $mail->addTo($this->userdata[0]['user_email']); $mail->setSubject(stripslashes($bookuploaddata[0]['title'])); $mail->setBodyHtml($description); $mail->setFrom(SETFROM, SETNAME); //$mail->send(); /*$reg='APA91bEZVTcqtar_br_cipLae9TyYe26JhsE2jHHnV76K_zWSAAyly2ZW6SCd4-REMgY_lGtHLh-2VvObjlj-pRvHd2932KlKY7anEOKQMyviVLs1A1Y7RYDPNtXwuRqTY7rILdF_LcXvY4GntxKouBU1EUv8E1mCQ'; $title = str_replace("_"," ",$title); $regID = array($reg); // $message="You have registerted successfully"; $message = array("userID" =>$row_userids['id'],"msg" =>$bookuploaddata[0]['title']." is ready to download","email" =>$row_userids['user_email']); send_push_notification($regID, $message);*/ if (isset($publicationdetails[0]['file_name']) && $publicationdetails[0]['file_name'] != '' && count($getproductimage) > 0 && count($product_price) > 0) { $get_registeration_id = mysql_query("select * from pclive_deviceID where user_publisher_id='" . $this->userdata[0]['id'] . "' and reg_id!=''"); $res_registeration_id = mysql_fetch_array($get_registeration_id); $reg = $res_registeration_id['reg_id']; $regID = array($reg); // $message="You have registerted successfully"; $message = array("userID" => $this->userdata[0]['id'], "msg" => "publication is ready to download", "email" => $this->userdata[0]['user_email']); if ($res_registration_id['os_type'] == 0) { send_push_notification($regID, $message); } else { send_push_notification_ios($regID, $row_userids['user_email'], $this->userdata[0]['id'], "publication is ready to download"); } } } } } } $this->_flashMessenger->addMessage('<div class="div-success">Product activated successfully</div>'); } else { $this->_flashMessenger->addMessage('<div class="div-error">Sorry!, unable to activate product</div>'); } } $this->_redirect('admin/publications/'); }