How do I insert Api Json data into database using Model in codeigniter, please help me - codeigniter-4

<?php
namespace App\Controllers\api;
use App\Models\OrdersModel;
class Get_data extends BaseController
{ `enter code here`
public function index()
{
$API_KEY = '34***************************';
$PASSWORD = 'sh************************';
$STORE_URL = 'v*******.myshopify.com';
$url = 'https://' . $API_KEY . ':' . $PASSWORD . '#' . $STORE_URL . '/admin/api/2020-04/orders.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, False);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //can check status code, requst successfully processed if return 200
if(curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$arr1= json_decode($result, JSON_OBJECT_AS_ARRAY);
//echo "<pre>";
//print_r($arr1);
$ordersModel = new OrdersModel;
foreach ($arr1['orders'] as $res){
$data=[
'id' => $res['id'],
'created_at' => $res['created_at'],
'currency' => $res['currency'],
];
echo"<pre>";
print_r($data);
}
}
}
// this is the output of the print_r($data);
Array
(
[id] => **********
[created_at] => 2022-06-30T01:58:55-04:00
[currency] => USD
)
Array
(
[id] => ************
[created_at] => 2021-03-11T08:24:07-05:00
[currency] => USD
)
Array
(
[id] => **********
[created_at] => 2020-12-11T09:12:32-05:00
[currency] => USD
)
Array
(
[id] => 2921853485215
[created_at] => 2020-12-11T02:57:02-05:00
[currency] => USD
)

Related

Stripe symfony subscription user

I'm new to stripe, I managed to make the payment via the doc but I can't link my user to the subscription, for example I would like that when the payment is made, in my user entity I would like whether the user is put in premium or when the subscription is cancelled, whether the user is not in premium.
In my user entity I put a "premium" boolean field
Can you help me please?
#[Route('/abonnement/panier/2/checkout', name: 'aboCheck')]
public function stripe2(Request $request): Response
{
if (!$this->getUser()) {
return $this->redirectToRoute('public');
}
\Stripe\Stripe::setApiKey('sk_test....');
$priceId = 'price.....';
if (!$priceId) {
throw $this->createNotFoundException('Bad plan id!');
}
$username = $this->getUser()->getUsername();
$email = $this->getUser()->getEmail();
$session = \Stripe\Checkout\Session::create([
'success_url' => 'http://127.0.0.1:8000/abonnement/panier/2/order/success?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'http://127.0.0.1:8000/abonnement/panier/2',
'mode' => 'subscription',
'line_items' => [[
'price' => $priceId,
// For metered billing, do not pass quantity
'quantity' => 1,
]],
'client_reference_id' => $username,
'customer_email' => $email,
'metadata' => [
'username' => $username
]
]);
return $this->redirect($session->url);
}
#[Route('/webhook', name: 'webhook')]
public function handle(ManagerRegistry $doctrine)
{
\Stripe\Stripe::setApiKey('sk....');
$endpoint_secret = 'whsec.....';
$payload = file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload,
$sig_header,
$endpoint_secret
);
} catch (\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
} catch (\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}
$user = $this->getUser();
// Handle the event
switch ($event->type) {
case 'customer.subscription.trial_will_end':
$subscription = $event->data->object;
print_r($subscription); // contains a \Stripe\Subscription
// Then define and call a method to handle the trial ending.
// handleTrialWillEnd($subscription);
break;
case 'customer.subscription.created':
$subscription = $event->data->object;
print_r($subscription); // contains a \Stripe\Subscription
// Then define and call a method to handle the subscription being created.
// handleSubscriptionCreated($subscription);
break;
case 'customer.subscription.deleted':
$subscription = $event->data->object;
print_r($subscription); // contains a \Stripe\Subscription
// Then define and call a method to handle the subscription being deleted.
// handleSubscriptionDeleted($subscription);
break;
case 'customer.subscription.updated':
$subscription = $event->data->object;
print_r($subscription); // contains a \Stripe\Subscription
// Then define and call a method to handle the subscription being updated.
// handleSubscriptionUpdated($subscription);
break;
default:
// Unexpected event type
error_log('Received unknown event type');
}
return new Response(Response::HTTP_OK);
}
#[Route('/abonnement/panier/2/order/success', name: 'success')]
public function successStripe(ManagerRegistry $doctrine, Request $request): Response
{
if (!$this->getUser()) {
return $this->redirectToRoute('public');
}
$priceId = 'price......';
\Stripe\Stripe::setApiKey('sk......');
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
$myuser = $this->getUser();
$session = \Stripe\Checkout\Session::retrieve($request->get('session_id'));
$customer = \Stripe\Customer::retrieve($session->customer);
if (($session->status == 'complete') & ($customer->email == $myuser->getEmail())) {
$entityManager = $doctrine->getManager();
$myuser->setProfileId($customer->id);
$myuser->setPremium(true);
$entityManager->flush();
} else {
return $this->redirectToRoute('aboStripe');
}
return $this->render('stripe/success.html.twig', [
'customer' => $customer
]);
}
#[Route('/customer-portal', name: 'customer-portal')]
public function portal(): Response
{
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('sk_test.....');
// This is the URL to which the user will be redirected after they have
// finished managing their billing in the portal.
$myuser = $this->getUser();
$stripe_customer_id = $myuser->getProfileId();
$session = \Stripe\BillingPortal\Session::create([
'customer' => $stripe_customer_id,
'return_url' => 'http://127.0.0.1:8000/abonnement/panier/2',
]);
return $this->redirect($session->url);
}

how to get transaction id in stripe payment gateway

I am using stripe payment gateway in php. Everything is working. But not showing transaction id after successful payment. How to get transaction id?
if(isset($_POST['stripeToken']))
{
$amount_cents = str_replace(".","","1.00"); // Chargeble amount
$invoiceid = "14526321"; // Invoice ID
$description = "Invoice #" . $invoiceid . " - " . $invoiceid;
try {
$charge = Stripe_Charge::create(array(
"amount" => $amount_cents,
"currency" => "usd",
"source" => $_POST['stripeToken'],
"description" => $description)
);
// Payment has succeeded, no exceptions were thrown or otherwise caught
$result = "success";
} catch(Stripe_CardError $e) {
$error = $e->getMessage();
$result = "declined";
} catch (Stripe_InvalidRequestError $e) {
$result = "declined";
} catch (Stripe_AuthenticationError $e) {
$result = "declined";
} catch (Stripe_ApiConnectionError $e) {
$result = "declined";
} catch (Stripe_Error $e) {
$result = "declined";
} catch (Exception $e) {
}
// Charge the Customer instead of the card
if($result=="success") {
$response = "<div class='col-sm-offset-3 col-sm-9 text-success'>Your Payment has been processed successfully.</div>";
} else{
$response = "<div class='text-danger'>Stripe Payment Status : \".$result.</div>";
}
}
?>
Above code is for after form submit.
You are getting your API response in the variable $charge. Comment out $result = s"success"; and write echo($charge);. You will see the response. In the response, the 'balance_transaction' value that starts with 'tx_' is the transaction id. Do save it to your database for further use.
Check the stripe API docs: https://stripe.com/docs/api/charges/object

How to configure docusign demo to live after promoting integration key

I used embedded signing and after successfully running on demo, promoted integration key and passed review.
What changes I need to in my code? Where I need to put promoted integration key? I know live have no token key integration like demo which is for 8 hours only.
I changed https://demo.docusign.net/restapi to https://www.docusign.net/restapi
$dsConfig = array(
'ds_client_id' => isset($session->data['user_id']) ? $session->data['user_id'] : "1",
'ds_client_secret' => 'eyJ0eXAiOiJNVCIsImFsZxxxxxxxxxxxxxx',
'signer_email' => $customer->isLogged() ? $customer->getEmail() : 'user#example.com',
'signer_name' => $customer->isLogged() ? $customer->getFirstName() . ' ' . $customer->getLastName() : 'John Doe',
'app_url' => HTTPS_SERVER . 'public/agreement-accept.html',
'authorization_server' => 'https://demo.docusign.net/restapi',
'session_secret' => isset($session->data['token']) ? $session->data['token'] : md5(time()),
'allow_silent_authentication' => true,
'accountId' => 'xxxxxxx',
'templateId' => 'xxxxx-xxxx-xxx-xxx-xxxx'
);
$config = new Configuration();
$config->setHost($dsConfig['authorization_server']);
$config->addDefaultHeader(
"Authorization",
"Bearer " . $dsConfig['ds_client_secret']
);
$apiClient = new ApiClient($config);
https://docusign.net/restapi is not a valid API endpoint.
In order to make API calls using your integration key, you'll need to implement one of the Authentication Workflows as documented here: https://developers.docusign.com/esign-rest-api/guides/authentication/
Once you have a valid token, you'll need to make a User Info call to determine the base URI for your account: https://developers.docusign.com/esign-rest-api/guides/authentication/user-info-endpoints
I did it by creating a generateRefreshToken() function in ApiClient Class:-
public function generateRefreshToken($client_id = null, $client_secret = null, $refresh_token = null)
{
if (!$client_id) {
throw new \InvalidArgumentException('Missing the required parameter $client_id when calling generateAccessToken');
}
if (!$client_secret || !$refresh_token) {
throw new \InvalidArgumentException('Missing the required parameter $client_secret when calling generateAccessToken');
}
if (!$refresh_token) {
throw new \InvalidArgumentException('Missing the required parameter $refresh_token when calling generateAccessToken');
}
$resourcePath = "/oauth/token";
$queryParams = array();
$integrator_and_secret_key = "Basic " . utf8_decode(base64_encode("{$client_id}:{$client_secret}"));
$headers = array(
"Authorization" => $integrator_and_secret_key,
"Content-Type" => "application/x-www-form-urlencoded",
);
$postData = array(
"grant_type" => "refresh_token",
"refresh_token" => $refresh_token
);
list($response, $statusCode, $httpHeader) = $this->callApi($resourcePath, self::$POST, $queryParams, $postData, $headers, null, null, true);
if(isset($response->access_token))
$this->config->addDefaultHeader("Authorization", "{$response->token_type} {$response->access_token}");
return array($this->getSerializer()->deserialize($response, '\DocuSign\eSign\Client\Auth\OAuthToken', $httpHeader), $statusCode, $httpHeader);
}
protected static function requestNewToken($refresh_token) {
$config = new Configuration();
$apiClient = new ApiClient($config);
$token = $apiClient->generateRefreshToken('clientid', 'secret_key', $refresh_token);
return array($token[0]['access_token'],$token[0]['refresh_token'],time() + 86400 * 27);
}
protected static function getToken() {
$tokenFile = __DIR__ . '/token.json';
$access_token = null;
if (file_exists($tokenFile)) {
$data = json_decode(file_get_contents($tokenFile), true);
$access_token = $data['access_token']; // todo consider field names
$refresh_token = $data['refresh_token']; // todo consider field names
$expires_in = $data['expires_in']; // todo consider field names
if ($expires_in <= time()) {
$access_token = null;
}
}
if (!$access_token) {
list($access_token,$refresh_newtoken,$expires_in) = self::requestNewToken($refresh_token);
if (!$access_token || !$refresh_newtoken || !$expires_in) {
throw new Exception('Could not request new token.');
}
file_put_contents($tokenFile, json_encode(array(
'access_token' => $access_token,
'refresh_token' => $refresh_newtoken,
'expires_in' => $expires_in
)));
}
return $access_token;
}
Also https://www.docusign.net/restapi is a valid API endpoint for production.It works for me. https:// and www should be there...
$dsConfig = array(
'ds_client_id' => isset($session->data['user_id']) ? $session->data['user_id'] : "1",
// The app's DocuSign integration key's secret
'ds_client_secret' => $token,
'signer_email' => $customer->isLogged() ? $customer->getEmail() : 'user#example.com',
'signer_name' => $customer->isLogged() ? $customer->getFirstName() . ' ' . $customer->getLastName() : 'John Doe',
// return url
'app_url' => HTTPS_SERVER . 'public/agreement-accept.html',
'authorization_server' => 'https://www.docusign.net/restapi',
'session_secret' => isset($session->data['token']) ? $session->data['token'] : md5(time()),
'allow_silent_authentication' => true,
'accountId' => 'xxx',
'templateId' => 'xxxx'
);

docusign :: how to void a "in-progress" envelope?

Please help.
I have been trying to void a "in-progress" envelope with one signature out of three signatures, but I receive this error msg.
I follow the instruction from : http://www.docusign.com/p/RESTAPIGuide/Content/REST%20API%20References/Void%20Envelope.htm.
Also looked at the previous question asked, but that didn't help me at all.
Error
The request contained at least one invalid parameter. Invalid value for 'status' in envelope definition. Only 'sent' or 'created' (default) are allowed.
URL: https://demo.docusign.net/restapi/v2/accounts/35*/envelopes/f466ad3f-d391-*--*****
PARAMS: {"status":"voided","voidedReason":"Voided due to late change request."}
INVALID_REQUEST_PARAMETER
Thanks in advance.
Are you sure you're doing a PUT request and not a POST?
Just tested and was able to void 3 envelopes just fine with no problems, using the same request body as you've listed. Not sure what language you're using, but here's a full working PHP program that creates and sends an envelope so that's in-process, then it immediately voids it.
To run this program:
Save code as local file, say "test.php".
Enter credentials at top (email, pwd, integrator key, name)
Copy a test PDF document to same directory, rename to "document.pdf"
run php test.php on command line
Here's the code, don't forget to replace creds...
<?php
// Input your info here:
$integratorKey = '***';
$email = '***';
$password = '***';
$name = '***';
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close($curl);
//--- display results
echo "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with one recipient, one tab, and one document and send
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array (
"emailBlurb" => "Custom PHP script",
"emailSubject" => "Radio Buttons Testing",
"status" => "sent",
"documents" => array(array( "documentId" => "1", "name" => "document.pdf")),
"recipients" => array( "signers" => array(
array( "email" => $email,
"name" => "$name",
"recipientId" => "1",
"clientUserId" => "1001",
"tabs" => array(
"signHereTabs" => array(
array(
"xPosition" => "100",
"yPosition" => "200",
"documentId" => "1",
"pageNumber" => "1"
)
),
"radioGroupTabs" => array(
array (
"documentId" => "1",
"groupName" => "RadioGroup1",
"radios" => array (
array(
"pageNumber" => "1",
"selected" => "false",
//"value" => "X",
"xPosition" => "300",
"yPosition" => "75"
),
array(
"pageNumber" => "1",
"selected" => "false",
"xPosition" => "350",
"yPosition" => "75"
)
)
)
)
)
)
)
)
);
$data_string = json_encode($data);
$file_contents = file_get_contents("document.pdf");
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data_string\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\ā€¯document.pdf\"; documentid=1 \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
// *** append "/envelopes" to baseUrl and as signature request endpoint
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
curl_close($curl);
//--- display results
echo "Document is sent! Envelope ID = " . $envelopeId . "\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Singing View
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("status" => "voided", "voidedReason" => "test");
$data_string = json_encode($data);
echo "Attempting to void envelope $envelopeId\nVoid request body is: $data_string\n";
$curl = curl_init($baseUrl . "/envelopes/$envelopeId" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
echo "Done.\n";
curl_close($curl);
?>

Opencart adding 3rd level category in filter module

i'm using a module for product filter,
In my admin backend i can able to set filter only for first and second level categories. I need to add 3rd level category too.
Below mentioned is my module controller file,
<?php
class ControllerModuleSuperCategoryMenu extends Controller {
private $error = array();
public function index() {
$this->data['current_version']='2.0.7';
//remove cache files
$this->cache->delete('product_filters');
$this->cache->delete('attribute_filters');
$this->load->language('module/supercategorymenu');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('supercategorymenu', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['tab_general'] = $this->language->get('tab_general');
$this->data['tab_settings'] = $this->language->get('tab_settings');
$this->data['tab_layouts'] = $this->language->get('tab_layouts');
$this->data['tab_contact'] = $this->language->get('tab_contact');
$this->data['entry_all_values'] = $this->language->get('entry_all_values');
$this->data['entry_list_number'] = $this->language->get('entry_list_number');
$this->data['entry_list_number_explanation'] = $this->language->get('entry_list_number_explanation');
$this->data['entry_pricerange'] = $this->language->get('entry_pricerange');
$this->data['entry_pricerange_explanation'] = $this->language->get('entry_pricerange_explanation');
$this->data['entry_set_vat'] = $this->language->get('entry_set_vat');
$this->data['entry_set_vat_explanation'] = $this->language->get('entry_set_vat_explanation');
$this->data['default_vat_price_range'] = $this->language->get('default_vat_price_range');
$this->data['default_vat_price_range_explanation'] = $this->language->get('default_vat_price_range_explanation');
$this->data['entry_manufacturer'] = $this->language->get('entry_manufacturer');
$this->data['entry_manufacturer_explanation'] = $this->language->get('entry_manufacturer_explanation');
$this->data['text_yes'] = $this->language->get('text_yes');
$this->data['text_no'] = $this->language->get('text_no');
$this->data['entry_count'] = $this->language->get('entry_count');
$this->data['entry_count_explanation'] = $this->language->get('entry_count_explanation');
$this->data['entry_ocscroll'] = $this->language->get('entry_ocscroll');
$this->data['entry_ocscroll_explanation'] = $this->language->get('entry_ocscroll_explanation');
$this->data['entry_nofollow'] = $this->language->get('entry_nofollow');
$this->data['entry_nofollow_explanation'] = $this->language->get('entry_nofollow_explanation');
$this->data['entry_track_google'] = $this->language->get('entry_track_google');
$this->data['entry_track_google_explanation'] = $this->language->get('entry_track_google_explanation');
$this->data['entry_ajax'] = $this->language->get('entry_ajax');
$this->data['entry_ajax_explanation'] = $this->language->get('entry_ajax_explanation');
$this->data['entry_order'] = $this->language->get('entry_order');
$this->data['entry_order_explanation'] = $this->language->get('entry_order_explanation');
$this->data['text_enabled'] = $this->language->get('text_enabled');
$this->data['text_disabled'] = $this->language->get('text_disabled');
$this->data['text_content_top'] = $this->language->get('text_content_top');
$this->data['text_content_bottom'] = $this->language->get('text_content_bottom');
$this->data['text_column_left'] = $this->language->get('text_column_left');
$this->data['text_column_right'] = $this->language->get('text_column_right');
$this->data['entry_layout'] = $this->language->get('entry_layout');
$this->data['entry_position'] = $this->language->get('entry_position');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
$this->data['entry_value'] = $this->language->get('entry_value');
$this->data['entry_separator'] = $this->language->get('entry_separator');
$this->data['entry_examples'] = $this->language->get('entry_examples');
$this->data['entry_separator_explanation'] = $this->language->get('entry_separator_explanation');
$this->data['entry_values_explanation'] = $this->language->get('entry_values_explanation');
$this->data['text_none'] = $this->language->get('text_none');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['button_add_module'] = $this->language->get('button_add_module');
$this->data['button_remove'] = $this->language->get('button_remove');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/supercategorymenu', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['action'] = $this->url->link('module/supercategorymenu', 'token=' . $this->session->data['token'], 'SSL');
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['settings'] = $this->url->link('module/supercategorymenu/settings', 'token=' . $this->session->data['token'], 'SSL');
$this->data['modules'] = array();
if (isset($this->request->post['supercategorymenu_module'])) {
$this->data['modules'] = $this->request->post['supercategorymenu_module'];
} elseif ($this->config->get('supercategorymenu_module')) {
$this->data['modules'] = $this->config->get('supercategorymenu_module');
}
$this->data['settings'] = array();
if (isset($this->request->post['supercategorymenu_settings'])) {
$this->data['settings'] = $this->request->post['supercategorymenu_settings'];
} elseif ($this->config->get('supercategorymenu_settings')) {
$this->data['settings'] = $this->config->get('supercategorymenu_settings');
}
if (isset($this->data['settings']['track_google'])){
$this->data['settings_trackgoogle']=$this->data['settings']['track_google'];
}else{
$this->data['settings_trackgoogle']=0;
}
if (isset($this->data['settings']['list_number'])){
$this->data['settings_listnumber']=$this->data['settings']['list_number'];
}else{
$this->data['settings_listnumber']=7;
}
if (isset($this->data['settings']['nofollow'])){
$this->data['settings_nofollow']=$this->data['settings']['nofollow'];
}else{
$this->data['settings_nofollow']=1;
}
if (isset($this->data['settings']['ajax'])){
$this->data['settings_ajax']=$this->data['settings']['ajax'];
}else{
$this->data['settings_ajax']=0;
}
if (isset($this->data['settings']['order'])){
$this->data['settings_order']=$this->data['settings']['order'];
}else{
$this->data['settings_order']="OH";
}
if (isset($this->data['settings']['ocscroll'])){
$this->data['settings_ocscroll']=$this->data['settings']['ocscroll'];
}else{
$this->data['settings_ocscroll']=0;
}
if (isset($this->data['settings']['countp'])){
$this->data['settings_countp']=$this->data['settings']['countp'];
}else{
$this->data['settings_countp']=1;
}
if (isset($this->data['settings']['pricerange'])){
$this->data['settings_pricerange']=$this->data['settings']['pricerange'];
}else{
$this->data['settings_pricerange']=1;
}
if (isset($this->data['settings']['setvat'])){
$this->data['settings_setvat']=$this->data['settings']['setvat'];
}else{
$this->data['settings_setvat']=1;
}
if (isset($this->data['settings']['manufacturer'])){
$this->data['settings_manufacturer']=$this->data['settings']['manufacturer'];
}else{
$this->data['settings_manufacturer']=1;
}
if (isset($this->data['settings']['tax_class_id'])){
$this->data['tax_class_id']=$this->data['settings']['tax_class_id'];
}else{
$this->data['tax_class_id']="";
}
$this->load->model('localisation/tax_class');
$this->data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
$this->load->model('module/supercategorymenu');
$this->data['categories'] = array();
$categories = $this->model_module_supercategorymenu->getCategories(0);
foreach ($categories as $category) {
if (isset($this->request->post['VALORES_'.$category['category_id'].''])) {
$this->data['category_attributes'][$category['category_id']]= $this->request->post['VALORES_'.$category['category_id'].''];
} else {
$this->data['category_attributes'][$category['category_id']] = $this->config->get('VALORES_'.$category['category_id'].'');
}
$children_data = array();
$children = $this->model_module_supercategorymenu->getCategories($category['category_id']);
foreach ($children as $child) {
if (isset($this->request->post['VALORES_'.$child['category_id'].''])) {
$this->data['category_attributes'][$child['category_id']]= $this->request->post['VALORES_'.$child['category_id'].''];
} else {
$this->data['category_attributes'][$child['category_id']] = $this->config->get('VALORES_'.$child['category_id'].'');
}
$results = $this->model_module_supercategorymenu->getCategoryAttributes($child['category_id']);
$attribute_data = array();
foreach ($results as $result) {
if (isset($this->data['category_attributes'][$child['category_id']]['attributes'][$result['attribute_id']])){
$attribute_checked=true;
$attribute_seperator=$this->data['category_attributes'][$child['category_id']]['attributes'][$result['attribute_id']]['separator'];
}else{
$attribute_checked=false;
$attribute_seperator="no";
}
$attribute_values=array();
$attribute_values = $this->model_module_supercategorymenu->getAttributeValues($result['attribute_id']);
//foreach ($res as $attribute_value){
//$attribute_values[key($res)]=$attribute_value;
//}
$attribute_data[] = array(
'attribute_id' => $result['attribute_id'],
'name' => $result['name'],
'checked' => $attribute_checked,
'separator' => $attribute_seperator,
'attribute_values'=> $attribute_values
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'],
'attributes' => $attribute_data
);
}
$results = $this->model_module_supercategorymenu->getCategoryAttributes($category['category_id']);
$attribute_data = array();
foreach ($results as $result) {
if (isset($this->data['category_attributes'][$category['category_id']]['attributes'][$result['attribute_id']])){
$attribute_checked=true;
$attribute_seperator=$this->data['category_attributes'][$category['category_id']]['attributes'][$result['attribute_id']]['separator'];
}else{
$attribute_checked=false;
$attribute_seperator="no";
}
$attribute_values_child=array();
$attribute_values_child = $this->model_module_supercategorymenu->getAttributeValues($result['attribute_id']);
//foreach ($res_child as $attribute_value_child){
//$attribute_values_child[key($res)]=$attribute_value_child;
//}
$attribute_data[] = array(
'attribute_id' => $result['attribute_id'],
'name' => $result['name'],
'checked' => $attribute_checked,
'separator' => $attribute_seperator,
'attribute_values'=> $attribute_values_child
);
}
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'],
'children' => $children_data,
'attributes' => $attribute_data,
//'valores_bd' => $this->data['category_attributes'][$category['category_id']]
);
}
$this->load->model('setting/extension');
if(in_array("ocscroll",$this->model_setting_extension->getInstalled('module'))){
$this->data['ocscroll']=true;
}else{
$this->data['ocscroll']=false;
}
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL,"http://opencart.tictachome.com/version/version.xml");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
$analizador=simplexml_load_string($output,null);
$this->data['version']['version']=$analizador->children()->version;
$this->data['version']['whats_new']=$analizador->children()->whats_new;
foreach($analizador->children()->other_modules as $other_modules){
$this->data['version']['modules'][]=array(
'name' =>$other_modules->name,
'version' =>$other_modules->version,
'url' =>$other_modules->url,
'manual' =>$other_modules->manual,
'price' =>$other_modules->price,
'resume' =>$other_modules->resume,
);
}
$this->load->model('localisation/language');
$this->data['languages'] = $this->model_localisation_language->getLanguages();
$this->load->model('design/layout');
$this->data['layouts'] = $this->model_design_layout->getLayouts();
$this->template = 'module/supercategorymenu.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
private function validate() {
if (!$this->user->hasPermission('modify', 'module/supercategorymenu')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>
Did anyone know how to add the 3rd level category too..
Please share your suggestions.
Thanks,

Resources