Silverstripe: SwipeStripe Member/Customer record not defined - php

So I'm using the SwipeStripe module as an ecommerce shop, and having issues logging member details as customer details. I'll outline the process and what i've tried so far.
I am currently logged in as a member of my website.
I can view, and add products to my cart.
When I reach the checkout page, it asks me to register my details (become a member).
I have gone through the Customer.php, and OrderForm.php files. What I have discovered is:
Customer::currentUser() is not recognising me as a logged in user.
When I print Member::currentUser() it can see I am a logged in, registered member and I can print the details of that record.
Customer::currentUser() is as follows in the Customer.php file:
static function currentUser() {
$id = Member::currentUserID();
if($id) {
return DataObject::get_one("Customer", "\"Member\".\"ID\" = $id");
}
}
I was wondering if anyone could help me understand why Customer::currentUser() isn't recognising me as a logged in user?
Also, in the OrderForm.php, when I change the validation for the "register as a member" form fields (the function is called 'createFields') to Member::currentUserID() it recognises that I'm logged in and skips that section. It's only when it goes to save my order and customer details to the customer DB table, that it can't retrieve my email address.

I know this is an old post, but I've used this code/method all the way up to SS 3.4.
You will need to update Aram's code to work with SS 3.x.x
https://www.silverstripe.org/community/forums/e-commerce-modules/show/21390
-helenclarko

Related

Easy Digital Downloads (Recurring Payments) if User Has Active Subscription show Something

I need to show something only to users with active subscriptions, im using the edd recurring payments plugin, I found this is their docs
$subscriber->has_active_subscription()
But im not sure how to make use of it to show something only to users with active subscriptions.
So i will be adding this code in my archive.php file and show extra php code for active users.
that code you found is part of the OOP class used by Easy Digital Downloads. Their docs are here: https://docs.easydigitaldownloads.com/article/1160-recurring-payments-developer-eddrecurringsubscriber
What you'd need to do is something like:
$my_user = get_current_user_id(); //grab current user
$subscriber = new EDD_Recurring_Subscriber( $my_user, true ); //pass user id to EDD class
//The EDD class will return its own user object, and on that you can do your check from the question:
if ($subscriber->has_active_subscription()) {
echo 'some special message for users with subscriptions';
} else {
//do something else
}
Watch out though, because that method will return true both if user has an active subscription and if he/she has a cancelled subscription (but false if subscription has expired). That may or may not be what you want.
I don't have EDD so haven't tested this but I hope it at least gets you started.

Alter authorize.net transaction key dynamically?

I am currently building an ecommerce website that is used for 5 separate companies using woocommerce and authorize.net for the payment.
So far the authorization is working great for a single vendor, the issue comes in that once I have selected the vendor by location, I need to change the api_transaction_key and api_login_id to the correct vendor before payment is processed.
I have been searching the files for hours now and cannot find where the key and id are set.
Can someone help me find where I can overwrite the key and id values to what I need?
or would it be better to create a new payment gateway for each of the vendors and copy all of the authorize.net gateway information except the key and id?
This answer is here for if anyone is curious on how I was able to make this work.in the Authorize.net woocommerce payment gateway you'll find a file called
class-wc-authorize-net-cim-api.php
and it is in this file's contruct function that your hook needs to be placed.
public function __construct( $api_user_id, $api_transaction_key, $environment ) {
// File default code
}
This needs the follow three lines of code to be placed BEFORE the default file code
$custom_auth_info = apply_filters('get_custom_auth', $custom_auth_info );
$api_user_id = $custom_auth_info['api_user_id'];
$api_transaction_key = $custom_auth_info['api_transaction_key'];
The apply_filters refers to the following function that is placed in my plugin
add_filter('get_custom_auth', 'select_distributor_by_state');
function select_distributor_by_state($custom_auth_info = []) {
global $wpdb;
//Your Query is here to select the proper distributor from the DB
//and retrieve their custom Authorize.net ID and Transaction Key
$custom_auth_info['api_user_id'] = $your_query[0]['api_loginid'];
$custom_auth_info['api_transaction_key'] = $your_query[0]['api_transactionkey'];
$_SESSION['dealer'] = $vendor[0]['id'];
return $custom_auth_info;
}
This filter allows you to hook in, grab the data you need, then return it and apply it directly into the code before the payment is processed.

PHP: Check for profile fields completedness

I have a social networking site built on a PHP framework. I'm using a plugin to award members points when they update their profile. Right now, whenever a member clicks on 'Save' it triggers the profileupdate event, and that event triggers the points being awarded. But, even if the profile fields are all empty, the event is still triggered and they still get points… so, my clever users are gaming the system to get points without really updating their profile :\
I want to add a function that checks that the profile fields aren't empty -- or, ideally, checks that a significant amount of changes have been made to at least 1 of the profile fields, but I'm not sure how to do that.
I'm still pretty new to PHP (about 1 year experience), so if anyone could help both with explaining what the checking process should be and the specifics on the code to execute the checking function, I'd really appreciate it!
Here are the current events and functions:
When the owner of the page clicks on 'Save', this is the event in the core of the PHP framework that gets triggered to notify the user of the update:
$owner->save();
trigger_event('profileupdate', $owner->type, $owner);
system_message(echo("profile:saved"));
This is the function in the points plugin that checks to see if the plugin is configured to award points based on a profile update, and then calls the points_add function to add points to the user:
function points_profile($event, $type, $object) {
if ($points = get_plugin_setting('profileupdate')) {
if (function_exists('points_add')) {
points_add(get_logged_in_user_guid(), $points, $event, $type, $object->entity_guid);
}
}
return(true);
}
This is an example of how the individual profile fields are defined/labelled -- ie, "admin_defined_profile_1"
if (save_config("admin_defined_profile_$id", $label) &&
save_config("admin_defined_profile_type_$id", $type) &&
save_config('profile_custom_fields', $fieldlist))
look on rowcount() http://www.php.net/manual/en/pdostatement.rowcount.php
it will -on single UPDATE -return 1 if anything was actually changed and 0 if nothing was changed.

How can I access the ID of the user that just completed registration form in Gravity Forms?

I am using the Gravity Forms registration plugin to register users on a website I am building and I am trying to add the ID of the newly created user to a URL which gets emailed to specific emails.
I found info herehttp://www.gravityhelp.com/documentation/page/Entry_Object that says you can get the current user ID of the logged in user however the value returns 0 because it seems as though the user isn't quite logged in at the time this function is called.
This is how I am currently trying to access the ID
add_action("gform_after_submission", "set_post_content_stuff", 10, 2);
function set_post_content_stuff($entry, $form){
//get id of user submitting the form
$currUserID = $entry['created_by'];
}
Does anyone know how to access the ID from the wp_users table when a new user is registered?
You can use the gform_user_registered hook to access the recently created user id:
add_action( 'gform_user_registered', 'send_user_email', 10, 4 );
function send_user_email($user_id, $feed, $entry, $user_pass) {
// Add function to send email
}
See documentation: https://www.gravityhelp.com/documentation/article/gform_user_registered/

Magento - Insufficient Stock Notification on Product Page

I am using Magento 1.7.0.2. Whilst on the product page, if a customer attempts to add a quantity greater than we have in stock they receive a message stating ".. the requested quantity is not available".
Is there any way for magento to either email or log when this occurs? I.e. I receive an automatic email stating a customer has attempted to add X number of item X? This would allow me to identify lost sales due to us not having enough stock of a particular item?
Has anyone come across anything like this before or is this even possible?
Thank you in advance
Mike Prentice
yes this is possible
You have to code for this.
I came across this problem one time and what i have do like this below.
I have make one observer event to check if customer is requesting quantity more then available if so i sent email to admin.
What you can do is create one observer for chekout_cart_add_before event in this event you can put your logic.
Or otherwise you can use magento feature Backorders you can find this in inventory tab,if you enable this then customer can order even requested quantity > available quantity, customer can see one message in cart page about backorder.
There is no standart functionality to notify about low quantity products by email.
But there is RSS notification http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_config/edit/cataloginventory
Extend this functionality to match your needs.
You could write some script which would parse RSS, and send email etc.
EDIT
Here is some extension you may like http://www.magentocommerce.com/magento-connect/low-stock-email-notification.html
But is is not free.
Here's how I've done it so that it sends a google analytics tracking event whenever a customer tries to order more than the available stock level.
First copy: app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
To: app/code/local/Mage/CatalogInventory/Model/Stock/Item.php
so that you're not modifying a core file.
In app/code/local/Mage/CatalogInventory/Model/Stock/Item.php add this function
public function notifyOutOfStock($productId){
$session = Mage::getSingleton('checkout/session');
//Initialise as empty array, or use existing session data
$outOfStockItems = array();
if ($session->getOutOfStock()){
$outOfStockItems = $session->getOutOfStock();
}
try {
$product = Mage::getModel('catalog/product')->load($productId);
$sku = $product->getSKu();
if($sku){
//Add the current sku to our out of stock items (if not already there)
if(! isset($outOfStockItems[$sku]) ) {
$outOfStockItems[$sku] = 0;
}
}
} catch (Exception $e){
//Log your error
}
Mage::getSingleton('checkout/session')->setOutOfStock($outOfStockItems);
}
In that same file is another function called checkQuoteItemQty.
Inside that function you need to call your new function using $this->notifyOutOfStock($this->getProductId()); right after it sets each of the error messages and before the return statement.
So:
public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0)
{
....
if ($this->getMinSaleQty() && ($qty) < $this->getMinSaleQty()) {
$result->setHasError(true)
->setMessage(
$_helper->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1)
)
->setQuoteMessage($_helper->__('Some of the products cannot be ordered in requested quantity.'))
->setQuoteMessageIndex('qty');
//** Call to new function **
$this->notifyOutOfStock($this->getProductId());
return $result;
}
.....
->setQuoteMessageIndex('qty');
//** Call to new function **
$this->notifyOutOfStock($this->getProductId());
return $result;
.....
What this does is add your product sku to an array in the checkout session.
This means you will have access to that info in the template file right after your page loads displaying the "Insufficient stock" notification.
So in one of your template files you can add some code to render the necessary JavaScript.
I've chosen header.phtml since it loads on every page. (Users can add quantities of items to the cart in the cart page as well as the product view page).
app/design/frontend/CUSTOMNAME/default/template/page/html/header.phtml
Somewhere down the bottom of the code add this:
<!-- GA tracking for out of stock items -->
<script>
try {
<?php
$session = Mage::getSingleton('checkout/session');
if ($session->getOutOfStock()){
$outOfStockItems = $session->getOutOfStock();
foreach($outOfStockItems as $sku=>$value) {
if($value==0){
//Render the GA tracking code
echo "_gaq.push(['_trackEvent', 'AddToCart', 'ProductQtyNotAvailable', '".$sku."']); \r\n";
//Set it to 1 so we know not to track it again this session
$outOfStockItems[$sku] = 1;
}
}
//Update the main session
Mage::getSingleton('checkout/session')->setOutOfStock($outOfStockItems);
}
?>
}
catch(err) {
//console.log(err.message);
}
</script>
Can confirm this works well and in my opinion is better than an email or RSS feed as you can analyse it along with the rest of your analytics.

Categories