Custom Payment Module:How Can i Pass smarty variables with in paymentoptions hook in prestashop 1.7? - prestashop

I am worried about how can i pass smarty variable in paymentoptions hook in prestashop 1.7 version and get that variables in payment page.
In prestashop 1.7 paymentoptions hooks looks like this,
public function hookPaymentOptions($params)
{
$payment_options = new PaymentOption();
$action_text = $this->l('Pay by Credit Card with Stripe Payment');
/*$payment_options->setLogo(Media::getMediaPath(_PS_MODULE_DIR_.$this->name.'/views/img/card.png'));*/
$payment_options->setCallToActionText($action_text);
$payment_options->setAction($this->context->link->getModuleLink($this->name, 'confirmation', array(), true));
$payment_options->setModuleName($this->name);
$payment_options->setAdditionalInformation($this->context->smarty->fetch('module:stripepay/views/templates/hook/checkout.tpl'));
$payments_options[] = $payment_options;
return $payments_options;
}
with in this hook how can i pass this secure_key ="FGDWFGF$#%#%!$" values in checkout.tpl files for making successful payments.
Now i have keep this values as static.
Please anybody knows this please assist with this.
I hope you understand my question.

Maybe try to use $_SESSION if you just only have to preserve it for later.
For checkout.tpl you should use hookPayment($params) instead, it's meant to populate a TPL and it's retrocompatible with older versions :
public function hookPayment($params)
{
$this->context->smarty->assign(array('myvar'=>'thevalue'));
return $this->display(__FILE__, 'checkout.tpl');
}

Related

How to retrieve the values of the checkboxes 'Available carriers' that we check

In order to reproduce a list of checkboxes like the one of the 'available carriers' in the Delivery section of the product page in the admin which allows to record the product-carrier associations, I ask for your help because I can't find how to retrieve the selected checkboxes to be able to use the setter of the association table ps_product_carrier defined in the product.php class
it would be in a JavaScript?
[Screen Admin Product page checkboxes list][1]
[1]: https://i.stack.imgur.com/4C79g.png
To get the carriers you need to use the getCarriers() function from the product class.
If the list is empty, all carriers are available. Therefore, if you want to display them you will need to use the Carrier::getCarriers() function to retrieve the list
If the list contains data, then that product has the specific carriers set.
So working directly on the front won't be enough as the variable is not loaded by default in the templates. What I would do is to create a micro-module with just the function to get that data.
Then you can use either a standard hook or create your own to display the data exactly where you want.
An example could be:
In the TPL add a custom hook call:
{hook h='displayProductCarriers' product=$product}
Then in your micro module:
public function hookDisplayProductCarriers($params)
{
if (isset($params['product'])) {
// Depending on the PS version product will be an array or an instance
if (is_array($params['product'])) {
$p = new Product((int)$params['product']['id_product']);
} elseif (is_object($params['product'])) {
$p = $params['product']);
}
$carriers = $p->getCarriers();
if (empty($carriers)) {
// Product has no specific carrier assigned
// Get all carriers here and assign them to smarty
$carriers = Carrier::getCarriers();
}
$this->context->smarty->assign('product_carriers', $carriers);
return $this->display(__FILE__, 'views/templates/hook/product-carriers.tpl');
}
}
That will allow the usage of the variable inside the template product-carriers.tpl there you can iterate through the {$product_carriers} variable and display whatever you need.

Refresh the Cart from the Backend

We have some custom functions for managing the Cart (add entries, remove cart etc.) which often times takes place in the backend.
I am searching for a way to refresh the cart in Spartacus so that it can show the actual data without the need of reloading the whole page. This is noticeable in the Minicart count as well as when we navigate to the cartpage. There you can see that the Data is not up to date. When you reload the page (F5) then the right data gets loaded.
Does someone have any idea how to force reload the "current" cart? I say current, cause when we remove the cart in the backend, we would expect that "hidden" method to create a new cart and give that back to Spartacus without reloading the page.
I found some sort of solution which feels kinda wonky and somehow does not work 100%:
refreshCart(): void {
this.getUser().pipe(
map((usr) => {
return usr;
}),
map(usr => {
this.cartService.reloadCart(usr, "");
}
)
).subscribe()
}
getUser(): Observable<string | undefined> {
return this.userIdService.getUserId().pipe(
map((userid) => {
return userid;
})
);
}
We extended the ActiveCartService and added a new method "reloadCart" which loos like the follwing:
reloadCart(userId: string, cartId: string): void {
this.loadOrMerge(cartId, userId, userId);
}
Please note that this is my first Angular Project and i feel that i miss some of the concepts (most noticeable i struggle with the whole Observables / subscribe / pipe / map and everything surrounding that).
Thank you in advance.
Not sure what spartacus version you are using, but I believe it applies to most of the versions.
To force a reload of the cart, you can use the MultiCartService to use the loadCart method.
Or if you don't want to use the actual service, you can always dispatch the action on your custom service, which what the loadCart method does from MultiCartService. You just need to provide the userId and cartId.
new CartActions.LoadCart({
userId,
cartId,
})

How to use store.filter / store.find with Ember-Data to implement infinite scrolling?

This was originally posted on discuss.emberjs.com. See:
http://discuss.emberjs.com/t/what-is-the-proper-use-of-store-filter-store-find-for-infinite-scrolling/3798/2
but that site seems to get worse and worse as far as quality of content these days so I'm hoping StackOverflow can rescue me.
Intent: Build a page in ember with ember-data implementing infinite scrolling.
Background Knowledge: Based on the emberjs.com api docs on ember-data, specifically the store.filter and store.find methods ( see: http://emberjs.com/api/data/classes/DS.Store.html#method_filter ) I should be able to set the model hook of a route to the promise of a store filter operation. The response of the promise should be a filtered record array which is a an array of items from the store filtered by a filter function which is suppose to be constantly updated whenever new items are pushed into the store. By combining this with the store.find method which will push items into the store, the filteredRecordArray should automatically update with the new items thus updating the model and resulting in new items showing on the page.
For instance, assume we have a Questions Route, Controller and a model of type Question.
App.QuestionsRoute = Ember.Route.extend({
model: function (urlParams) {
return this.get('store').filter('question', function (q) {
return true;
});
}
});
Then we have a controller with some method that will call store.find, this could be triggered by some event/action whether it be detecting scroll events or the user explicitly clicking to load more, regardless this method would be called to load more questions.
Example:
App.QuestionsController = Ember.ArrayController.extend({
...
loadMore: function (offset) {
return this.get('store').find('question', { skip: currentOffset});
}
...
});
And the template to render the items:
...
{{#each question in controller}}
{{question.title}}
{{/each}}
...
Notice, that with this method we do NOT have to add a function to the store.find promise which explicitly calls this.get('model').pushObjects(questions); In fact, trying to do that once you have already returned a filter record array to the model does not work. Either we manage the content of the model manually, or we let ember-data do the work and I would very much like to let Ember-data do the work.
This is is a very clean API; however, it does not seem to work they way I've written it. Based on the documentation I cannot see anything wrong.
Using the Ember-Inspector tool from chrome I can see that the new questions from the second find call are loaded into the store under the 'question' type but the page does not refresh until I change routes and come back. It seems like the is simply a problem with observers, which made me think that this would be a bug in Ember-Data, but I didn't want to jump to conclusions like that until I asked to see if I'm using Ember-Data as intended.
If someone doesn't know exactly what is wrong but knows how to use store.push/pushMany to recreate this scenario in a jsbin that would also help too. I'm just not familiar with how to use the lower level methods on the store.
Help is much appreciated.
I just made this pattern work for myself, but in the "traditional" way, i.e. without using store.filter().
I managed the "loadMore" part in the router itself :
actions: {
loadMore: function () {
var model = this.controller.get('model'), route = this;
if (!this.get('loading')) {
this.set('loading', true);
this.store.find('question', {offset: model.get('length')}).then(function (records) {
model.addObjects(records);
route.set('loading', false);
});
}
}
}
Since you already tried the traditional way (from what I see in your post on discuss), it seems that the key part is to use addObjects() instead of pushObjects() as you did.
For the records, here is the relevant part of my view to trigger the loadMore action:
didInsertElement: function() {
var controller = this.get('controller');
$(window).on('scroll', function() {
if ($(window).scrollTop() > $(document).height() - ($(window).height()*2)) {
controller.send('loadMore');
}
});
},
willDestroyElement: function() {
$(window).off('scroll');
}
I am now looking to move the loading property to the controller so that I get a nice loader for the user.

Yii Framework Captcha conflict with beforeAction() function

I have app in Yii and i extend all classes from some base controller and i have these code in it :
protected function beforeAction($action)
{
$this->setglobalvariable();
return parent::beforeAction($action);
}
as i just understand , these code prevent the Captcha to show , because when i delete it , the captcha shows up ! the captcha function is :
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'minLength'=>2,
'maxLength'=>3,
'width'=>60,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
So how could i use beforeAction and captcha in same time ?
The confilict is in your structure , Show us more code . put the program in fresh yii and test it.
beforeAction function , Do not have any conflict with other Yii methods or functions.
The probelm is in your code.
Obviously there is some code in your Controller::setglobalvariables() method that conflicts with the captcha's code.
The CCaptachAction::run() method uses $_GET parameters. Are you somehow resetting $_GET ?
Can you show us the code ?

InAppPurchases not working on PhoneGap App

I'm having some problems trying to get running inAppPurchases inside my iPhone phoneGap-based app.
I got the inAppPurchase-plugin on gitHub https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/InAppPurchaseManager
Then i created my developer account, purchased de u$d 99, and made my inAppPurchase Catalog
Created my iTunes Connect account to get a Test User for this.
I placed all the plugins file where it says... And, if i try to run "alert(typeof window.plugins.inAppPurchaseManager)" it shows "object" so, plugins are being loaded correctly!
The problem appears when i try to do my purchase..
I logout my itunes account, run my binary inside my iphone, and when i make the purchase i should see a prompt asking me for my test account information in order to make a symbolic purchase! But it never happens!
The javascript code (very basic) im trying to run is the following
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady(event) {
window.plugins.inAppPurchaseManager.onPurchased = function(transactionIdentifier, productId, transactionReceipt) {
alert("purchased");
};
window.plugins.inAppPurchaseManager.onRestored = function(originalTransactionIdentifier, productId, originalTransactionReceipt) {
alert("restored");
};
window.plugins.inAppPurchaseManager.onFailed = function(errorCode, errorText) {
alert("error");
};
window.plugins.inAppPurchaseManager.requestProductData(
"com.mycompany.myproduct.myproductid",
function(productId, title, description, price) {
alert("data retrieved");
window.plugins.inAppPurchaseManager.makePurchase(productId, 1);
},
function(id) {
alert("Invalid product id: " + id);
}
);
}
Hope you can help me! thank you!
You need to call js functions like window.plugins.inAppPurchaseManager.onPurchased in html.index for these functions to work.i.e these functions call onPurchased in js and correspondingly it will call obj-C functions.
(js function in index.html)->(js function in js file)->(objective-C function)...is the sequence.
Are you getting any invalid product ID's back? There are a lot of gotchas on Apple's end. Try reading through this guide to find what you need to get the product info request to return valid products.