WooCommerce Marketplace (WCMP) is a multivendor plugin for woo. In my PHP API I'm building, I need to iterate all vendors like this to get subscriber & product data per vendor (Psuedo-code):
foreach($vendors as $vendor){
$vendorsActiveSubscriptions = get_wcmp_active_subscriptions($vendor);
foreach($vendorsActiveSubscriptions as $subscription){
echo $vendor->userId;
echo $subscription->product_name;
echo $subscription->userId; // of customer
echo $subscription->product_categories;
}
}
I realize it won't be quite as simple as that but you see what I'm after. Having trouble finding docs that will lead me to doing it without a bunch of manual database queries.
Related
I'm working on getting all the active members in our Braintree account. I can list all customers but I don't know how to list the active ones.
In the Braintree dashboard, I can easily see it by going to subscriptions and filtering all Active subscriptions then clicking the subscription ID. From there I can see which customer has that subscription ID.
Then I tried getting all the active subscriptions first but I can't find any connection with any customers either.
I'm using the PHP SDK.
Here's how I get our active subscriptions.
My subscription code in my library:
function active_subscriptions(){
return Braintree_Configuration::gateway()->subscription()->search([
Braintree_SubscriptionSearch::status()->in([Braintree_Subscription::ACTIVE])
]);
}
Here's for the controller:
function active_subscriptions(){
$active_subscriptions = $this->braintree_lib->active_subscriptions();
$counter = 5;
foreach($active_subscriptions as $subscription) {
if($counter == 0){
die();
}
echo 'Subscription ID: '.$subscription->id.'<br />';
echo 'merchantAccountId: '.$subscription->merchantAccountId.'<br />';
echo 'planId: '.$subscription->planId.'<br /><br />';
$counter--;
}
}
I found this but it's in Ruby on Rails and there are no details about it in the documentation.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact
support.
Just to make sure I understand the result you are looking for: You are currently attempting to retrieve all of the customer records that are tied to active subscriptions, correct?
If so, you can achieve this by doing the following:
Iterate over the collection of active subscriptions you received from your search result.
Parse each subscription object for the payment method token associated to each subscription.
Separately, run a paymentMethod.find() call to retrieve the payment method's object.
The payment method object will contain the customer ID.
After following the above steps you can then create a list from your results, which will contain all customers with active subscriptions.
Here is a basic example of how this would be achieved:
$collection = $gateway->subscription()->search([
Braintree_SubscriptionSearch::status()->in(
[Braintree_Subscription::ACTIVE]
)
]);
foreach($collection as $subscription) {
$token = $subscription->paymentMethodToken;
$paymentMethod = $gateway->paymentMethod()->find($token);
$customer = $paymentMethod->customerId;
echo $customer . "\n";
}
If this isn't what you are looking for, or if you have any additional questions you can reach out to Braintree Support directly and we can assist you further.
Recurly Create Subscription. It doesn’t seem like they allow multiple coupons to be allowed added to the account during creation, but am I wrong? Or is there another way to add a coupon to the account subscription?
I already have multiple coupons setting in Recurly turned on, I'm just not sure how to apply them. I'm also using the PHP library if that makes any difference.
I found out you can actually create subscription with multiple coupons at once. All you need to do is organize coupon codes into comma separated list.
You must use the redeem subscription endpoint (rather than the create subscription endpoint) if you wish to apply multiple coupons
<?php
$coupon = Recurly_Coupon::get('special');
$redemption = $coupon->redeemCoupon('1', 'USD');
?>
More information here
You should work with Redeem a Coupon on an Account
Definition
https://:subdomain.recurly.com/v2/coupons/:coupon_code/redeem
PHP Examples
<?php
$coupon = Recurly_Coupon::get('special');
$redemption = $coupon->redeemCoupon('1', 'USD');
?>
Result Format
<redemption href="https://your-subdomain.recurly.com/v2/accounts/1/redemptions/316a4213e8fa9e97390aff4995bda9e6">
<coupon href="https://your-subdomain.recurly.com/v2/coupons/special"/>
<account href="https://your-subdomain.recurly.com/v2/accounts/1"/>
<subscription href="https://your-subdomain.recurly.com/v2/subscriptions/315fbd7a25b04f1333ea9f4418994fb5"/>
<uuid>316a4213e8fa9e97390aff4995bda9e6</uuid>
<single_use type="boolean">false</single_use>
<total_discounted_in_cents type="integer">0</total_discounted_in_cents>
<currency>USD</currency>
<state>active</state>
<created_at type="datetime">2015-09-23T17:13:30Z</created_at>
</redemption>
I am trying to get shipping and handling amount. I was trying the snippet code below but it's not working. I am successfully sending some data to third party API after the place order .
echo $item->getShippingAmount();
but if I tried with.
echo $order->getShippingAmount();
It works but it shows total of shipping amount of all orders, but conversely I want each single amount to be shown.
item ordered * quantity
Can anybody tell me how to do that?
Maybe you can use
$order->getShippingIncTax()
Try with below code :
for magento2 :
foreach ($order->getAllItems() as $item) {
echo $item->getShippingAmount();
}
We are running Magento with 2 stores, 1 store is retail, the other is wholesale. They share a single catalog, with split pricing between the two stores.
The script I am writing simply takes all of the pricing from the wholesaler site and is supposed to update the current price to the current price reflecting a 10% discount. My script is throwing the following error:
Total Products: 51937
PHP Fatal error: Uncaught exception 'Mage_Eav_Model_Entity_Attribute_Exception' in >/var/www/vhosts/mediagiantdesign.com/httpdocs/app/code/core/Mage/Core/Model/Config.php:1353
I have been wrestling with this for a little while. I know magento pretty well and for something trivial like this to stop me in my tracks is a bit aggravating.
Since there is no exception message attached to the stack trace, figuring out what it is has been difficult. It has something to do with setting the storeid on the load. if I take that out, or change it to setWebsiteId it works. However, it updates BOTH sites pricing not just the wholesale side.
Two Additional Notes:
Currently both sites prices in the catalog are the same. That is why you see me simply taking the same price from the same product. This script is supposed to apply the initial reduction in the wholesale side of the store.
Since I am debugging I have the break condition at the end. I do plan on removing it for a full run - also anyone who finds this post and finds the code useful (after its fixed of course) can remove it to have it run for the full catalog.
Here is my code:
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
require_once 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
try {
//get the magento product collection for the Vendors website products
$vendorproducts = Mage::getModel('catalog/product')->getCollection();
} catch (Exception $ex) {
echo "Exception thrown.";
echo $ex->getTraceAsString();
echo $ex->getMessage(); //no output - weird.
}
echo "Total Products: " . $vendorproducts->count() . "\r\n";
$count = 0;
foreach($vendorproducts as $product)
{
$priceupdate = Mage::getModel('catalog/product')->setStoreId(2)->load($product->getId());
$retailprice = $priceupdate->getPrice();
echo $product->getId() . " - " . ($retailprice - ($retailprice *.10)) . "\r\n";
$priceupdate->setPrice(($retailprice - ($retailprice *.10)));
$priceupdate->setUrlKey(false);
$priceupdate->save();
$count++;
if ($count > 0)
break;
}
echo $count . " products updated.\r\n";
Solved. After some double checking I realized I had specified the wrong StoreID. An invalid store id is a real good way to trip magento up - devil is in the details.
Enjoy the script.
I am looking to modify the transaction results email that is sent to the admin upon sale of an item (include and exclude certain information, etc), I've researched on google and looked on the wp-ecommerce support site and have been unable to locate where this is being done currently (a lot of references to older versions of the plugin that have since changed significantly). I will continue to look for where to do this but as I am not well versed in wp-ecommerce (or wordpress for that matter) I am not entirely sure where to look.
If anyone could shed light on this, it would be greatly appreciated.
Under wp-e-commerce/wpsc-updates/updating_tasks.php
Line 356-372 is where the email section is.
add_option('wpsc_email_receipt', '', __('Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page.All prices include tax and postage and packaging where applicable.You ordered these items:%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
add_option('wpsc_email_admin', '', __('%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
if(get_option('wpsc_email_receipt') == '') {
if(get_option('email_receipt') != '') {
update_option('wpsc_email_receipt', get_option('email_receipt'));
} else {
update_option('wpsc_email_receipt', __('Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page.All prices include tax and postage and packaging where applicable.You ordered these items:%product_list%%total_shipping%%total_price%', 'wpsc'));
}
}
if(get_option('wpsc_email_admin') == '') {
if(get_option('email_admin') != '') {
update_option('wpsc_email_admin', get_option('email_admin'));
} else {
update_option('wpsc_email_admin', __('%product_list%%total_shipping%%total_price%', 'wpsc'));
}
}
If you want to go even deeper into the whole email code, you can also go into this section
wp-e-commerce/wpsc-includes/purchase-log-notification.class.php
I created a plugin for this and many other wp e-commerce features.
With the shop styling plugin you can modify the transaction report with placeholders as well as any other mails from the wordpress backend without modifying any plugin files.