how to store multiple products in add to carts using session in codeigniter-3 - codeigniter-3

I want to add multiple product in SESSION when user click on add to cart button and how to fetch all product from SESSION using codeigniter...please help.
if ($_POST)
{
$sessionData = [
'p_id' => $this->input->post('pid'),
'p_name' => $this->input->post('pname'),
'p_qty' =>$this->input->post('viewproduct_details_qty'),
'p_price' => $this->input->post('pprice'),
'p_discount' => $this->input->post('pdiscount'),
'p_dprice' => $this->input->post('pdiscountprice'),
'p_imagename' => $this->input->post('pimagename'),
];
echo "<pre>";
print_r($sessionData);
$p_session = $this->session->set_userdata($sessionData);
//$this->load->view("add_to_cart_page_session");
}

Please Use Below code :
First You have to load session library in : config->autoload.php
$autoload['libraries'] = array('session'); // Load session Library in autoload.php
if ($_POST)
{
$sessionData = [
'p_id' => $this->input->post('pid'),
'p_name' => $this->input->post('pname'),
'p_qty' =>$this->input->post('viewproduct_details_qty'),
'p_price' => $this->input->post('pprice'),
'p_discount' => $this->input->post('pdiscount'),
'p_dprice' => $this->input->post('pdiscountprice'),
'p_imagename' => $this->input->post('pimagename'),
];
echo "<pre>";
print_r($sessionData);
$this->session->set_userdata('YOUR_SESSION_NAME',$sessionData); // You have to give session name
print_r($this->session->userdata('YOUR_SESSION_NAME')); // You Can Access Session by name
//$this->load->view("add_to_cart_page_session");
}

Related

Yii2 remember sort option after submit the searchForm

I use an ActiveForm in Yii2 for my SearchModel. After click on search button the form fields remember previous values but SorterDropdown is refreshed.
<?php echo SorterDropdown::widget(['sort' => $dataProvider->sort,
'label' => $model->sortedBy($dataProvider->sort->attributes),])
?>
SorterDropdown is just a wrapper of ButtonDropdown.
How can I forse the SorterDropdown to remember sort order (and show it) after the form submition?
class SorterDropdown extends LinkSorter
{
public $label;
protected function renderSortLinks()
{
$attributes = empty($this->attributes) ? array_keys($this->sort->attributes) : $this->attributes;
$links = [];
foreach ($attributes as $name) {
$links[] = Html::tag('li', $this->sort->link($name, ['tabindex' => '-1']));
}
if (empty($this->label))
$this->label = 'Sort';
return \yii\bootstrap\ButtonDropdown::widget([
'encodeLabel' => false,
'label' => $this->label,
'dropdown' => [
'items' => $links,
],
]);
}
You should add some class to li element, which indicate active state of it and special style in CSS file.

Dynamic facebook app credentials for Laravel 5.1 socialite

We are trying to use dynamic facebook app credentials for Laravel 5.1 socialite.
config/services.php
'facebook' => [
'client_id' => 'xxxx',
'client_secret' => 'xxxx',
'redirect' => 'http://example.com/facebook-callback',
],
On my controller file:
public function getConnectFacebook()
{
return Socialite::driver('facebook')->redirect();
}
public function getFacebookCallback()
{
$user = Socialite::driver('facebook')->user();
}
We tried to overwrite the facebook driver this way:
public function getConnectFacebook()
{
Config::Set("services.facebook.client_id", "dynamic_app_id");
Config::Set("services.facebook.client_secret", "dynamic_app_secret");
Config::Set("services.facebook.redirect", "dynamic_app_redirect");
return Socialite::driver('facebook')->redirect();
}
But it was not working. Could you please let me know how we can achieve this?
Thanks.
like this
return Socialite::driver('facebook')->redirect()->setTargetUrl('your callback url');
Here is my solution.
private function makeFacebookDriver($domain){
//grab and set your config values from database or array. Don't do Config::Set.
$config['client_id'] = '';//grab fb id based from db based on domain
$config['client_secret'] = '';//grab fb secret from db based on domain
$config['redirect'] = 'http://'.$domain.'/fbcallback';
return Socialite::buildProvider(\Laravel\Socialite\Two\FacebookProvider::class, $config);
}
then use the function instead of calling Socialite::driver('Facebook');
$fb = $this->makeFacebookDriver('www.test.com');
return $fb->redirect();
just use it in your controller
use Laravel\Socialite\Two\FacebookProvider;
config
$config = [
'client_id' => '969935-d61celu1qck667krmbgql.apps.googlesercontent.com',
'client_secret' => 'sHrnnOz3Fmz4',
'redirect' => 'http://localhost:8000/api/login/facebook/callback'
];
$user= Socialite::buildProvider(FacebookProvider::class, $config)->stateless();
return $user->redirect();
stateless in callback
$userSocial =$config = [
'client_id' => '969d61celu1qck667krmbgql.apps.googlesercontent.com',
'client_secret' => 'sHrnnO3Fmz4',
'redirect' => 'http://localhost:8000/api/login/facebook/callback'
];
$user=Socialite::buildProvider(FacebookProvider::class, $config)-
>stateless()->user();
api or web.php
Route::get('login/{provider}', 'SocialController#redirect');
Route::get('login/{provider}/callback','SocialController#Callback');
You could also do a simple find and replace.
Let's say you have a config file like this
'facebook' => [
'client_id' => '{ID}',
'client_secret' => '{SECRET}',
'redirect' => '{REDIRECT}',
],
Now within your controller you can do something like this.
$fileName = 'path/to/file.php';
$configData = file_get_contents($file);
$configData = str_replace('{ID}','dynamic_id',$configData);
$configData = str_replace('{SECRET}','dynamic_secret',$configData);
$configData = str_replace('{REDIRECT}','dynamic_link',$configData);
file_put_contents($file, $configData);
That's it, nothing fancier.

Cant Create Facebook Ad via Ads API

I am trying to create a Facebook AD via their PHP SDK. The problem lies in the creation of the ad itself. If I comment out the last piece, its creates the adset. When I run this code, I get the error "a Parent ID is required"
try {
///////////////////////////// CREATE AD SET ////////////////////////////////////
$data = array(
AdSetFields::NAME => $adname,
AdSetFields::BID_TYPE => 'CPC',
AdSetFields::BID_INFO => array(
'CLICKS' => 6,
),
AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_PAUSED,
AdSetFields::DAILY_BUDGET => 500000,
AdSetFields::CAMPAIGN_GROUP_ID => $campaign_id,
AdSetFields::TARGETING => array(
'age_min' => 30,
'age_max' => 45,
'page_types' => array(
'desktopfeed',
),
'geo_locations' => array(
'countries' => array(
'US',
),
),
),
);
$adset = new AdSet(null, $account_id);
$adset->create($data);
$adset_id = $adset->id;
echo $adset_id.'-';
//////////////////////CREATE AD IMAGE ///////////////////////////////
$image = new AdImage(null, $account_id);
$image->{AdImageFields::FILENAME} = '../adimages/epsom.jpg';
$image->create();
$creative = new AdCreative(null, $account_id);
$creative->setData(array(
AdCreativeFields::TITLE => $adtitle,
AdCreativeFields::BODY => $addesc,
AdCreativeFields::OBJECT_URL => $tracking_promoted_url,
AdCreativeFields::IMAGE_HASH => $image->hash,
));
$creative->create();
echo $creative->id.'-';
/////////////////////////////// CREATE AD GROUP ////////////////////////////
$fields = array(array(
AdGroupFields::CREATIVE =>
array('creative_id' => $creative->id),
AdGroupFields::ADGROUP_STATUS => AdGroup::STATUS_PAUSED,
AdGroupFields::NAME => 'My First AdGroup',
AdGroupFields::CAMPAIGN_ID => $adset_id,
));
$ad = new AdGroup();
$ad->create($fields);
echo 'AdGroup ID:' . $adgroup->id . "-";
} catch (RequestException $e) {
echo 'Caught Exception: '.$e->getMessage().PHP_EOL
.'Code: '.$e->getCode().PHP_EOL
.'HTTP status Code: '.$e->getHttpStatusCode().PHP_EOL;
}
You're missing the parent ID parameter when you create the adgroup. The 2nd parameter should be the account ID you want to create this adgroup under:
$adgroup = new Adgroup(null, $accountId);
If you copied this from a doc, let me know and we can update.
You may reference to the latest doc: https://developers.facebook.com/docs/marketing-api/reference/ad-campaign
From there, you will need to specify the ad account id(AD_ACCOUNT_ID) and ad campaign id(CAMPAIGN_GROUP_ID)

Attributes exchange using Net::OpenID::Consumer

my $csr = Net::OpenID::Consumer->new(
ua => LWP::UserAgent->new,
consumer_secret => '123456xXx',
required_root => "http://www.myopenidsample.net/",
);
my $openid = "https://me.yahoo.com";
my $claimed_id = $csr->claimed_identity($openid);
if ($claimed_id){
my $check_url = $claimed_id->check_url(
delayed_return => 1,
return_to => "http://www.myopenidsample.net/response.cgi",
trust_root => "http://www.myopenidsample.net/",
);
print $q->redirect($check_url);
}
How do I get attributes such as email, firstName, lastName, and country?
How do I append the following parameters to a URL?
openid.ext1.mode fetch_request
openid.ext1.required country,email,firstname,lastname,language
openid.ext1.type.country http://axschema.org/contact/country/home
openid.ext1.type.email http://axschema.org/contact/email
openid.ext1.type.firstname http://axschema.org/namePerson/first
openid.ext1.type.language http://axschema.org/pref/language
openid.ext1.type.lastname http://axschema.org/namePerson/
openid.ns.ext1 http://openid.net/srv/ax/1.0
You need to add the following code before the call to check_url (the example was tested with Google in order to get only the email):
$claimed_id->set_extension_args(
"http://openid.net/srv/ax/1.0",
{
'mode' => 'fetch_request',
'type.email' => 'http://axschema.org/contact/email',
'required' => 'email',
});
To get the value back in the return, I use:
my $email = $csr->message->get_ext
("http://openid.net/srv/ax/1.0", "value.email");

How to create sub category on Magento APi

I am currently using Magento ver. 1.5.0.1. Can anyone tell me how do i create a sub category using soapv2.
Here my code format
category_data = { "name" => "LIGHTING", "is_active" => 1 }
soap.call('catalogCategoryCreate',session,4,category_data,1, "include_in_menu")
I got some errors when i run this code.
: Attribute "include_in_menu" is required. (SOAP::FaultError)
Is that any solution for this problem.
Thanks.
category_data = { "name" => "LIGHTING", "is_active" => 1, "include_in_menu" => 1 }
This is how you can create category using SOAP V2
<?php
$host = "192.168.0.10/~aliasgar/magentoext/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/v2_soap/?wsdl"); //soap handle
$apiuser= "aliasgar"; //webservice user login
$apikey = "aliasgar"; //webservice user pass
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
$result = $client->catalogCategoryCreate($sess_id, 3, array(
'name' => 'Test Category',
'is_active' => 1,
'available_sort_by' => array('position'),
'default_sort_by' => 'position',
'include_in_menu' => '1',
));
var_dump ($result);
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
Here 3 in the catalogCategoryCreate function is the parent category id.