public function getData() { // define $markup to store all screen output $item_request = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'getitem', 'id' => $this->options['item_id'])); $item = $item_request->response['payload']; $this->element_data['item_name'] = $item['name']; $this->element_data['item_price'] = number_format($item['price'], 2, '.', ''); $this->element_data['item_flexible_price'] = $item['flexible_price']; $this->element_data['item_description'] = $item['description']; $this->element_data['item_asset'] = $item['fulfillment_asset']; if ($item['available_units'] != 0) { $this->element_data['is_available'] = true; } else { $this->element_data['is_available'] = false; } $currency_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'getsettings', 'type' => 'use_currency', 'user_id' => $this->element_data['user_id'])); if ($currency_request->response['payload']) { $this->element_data['currency'] = CASHSystem::getCurrencySymbol($currency_request->response['payload']); } else { $this->element_data['currency'] = CASHSystem::getCurrencySymbol('USD'); } if ($this->status_uid == 'commerce_finalizepayment_200' || $this->status_uid == 'element_redeemcode_200' || $this->status_uid == 'commerce_initiatecheckout_200' && $this->original_response['payload'] == 'force_success') { if ($item['fulfillment_asset'] != 0) { $fulfillment_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'getfulfillmentassets', 'asset_details' => $item['fulfillment_asset'])); if ($fulfillment_request->response['payload']) { $this->element_data['fulfillment_assets'] = new ArrayIterator($fulfillment_request->response['payload']); } } $this->setTemplate('success'); } elseif ($this->status_uid == 'commerce_initiatecheckout_400') { // could happen on a database glitch, but probably means the user set a pay-minimum price below the // minimum price. what a heel. $this->element_data['error_message'] = 'Make sure you enter a price of at least ' . $this->element_data['currency'] . $item['price'] . ' and try again.'; } elseif ($this->status_uid == 'commerce_finalizepayment_400' || $this->status_uid == 'element_redeemcode_400') { // payerid is specific to paypal, so this is temporary to tell between canceled and errored: if (isset($_GET['PayerID'])) { //$this->element_data['error_message'] = $this->options['message_error']; $this->element_data['error_message'] = print_r($this->original_response, true); } } elseif (isset($_POST['singlepurchase1'])) { $total_price = $item['price']; if (isset($_POST['total_price'])) { $total_price = $_POST['total_price']; } $this->element_data['total_price'] = $total_price; if ($this->element_data['region1_cost'] + $this->element_data['region2_cost'] == 0.0) { $this->element_data['no_shipping'] = true; } if ($total_price >= $item['price']) { $this->setTemplate('shipping'); } else { $this->element_data['error_message'] = 'Make sure you enter a price of at least ' . $this->element_data['currency'] . $item['price'] . ' and try again.'; } } return $this->element_data; }
} } $orders_currency = $order['currency']; } $total_spend = round($total_spend); } $cash_admin->page_data['dashboard_lists'] = $session_news['activity']['lists']; if ($session_news['activity']['orders']) { $cash_admin->page_data['total_orders'] = count($session_news['activity']['orders']); if ($cash_admin->page_data['total_orders'] == 1) { $cash_admin->page_data['orders_singular'] = true; } } else { $cash_admin->page_data['total_orders'] = false; } $cash_admin->page_data['total_spend'] = CASHSystem::getCurrencySymbol($orders_currency) . $total_spend; } // handle all of the sales options, first the change if (isset($_POST['currency_id'])) { $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'setsettings', 'type' => 'use_currency', 'value' => $_POST['currency_id'], 'user_id' => $cash_admin->effective_user_id)); $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'setsettings', 'type' => 'payment_defaults', 'value' => array('pp_default' => $_POST['paypal_default_id'], 'pp_micro' => $_POST['paypal_micropayment_id']), 'user_id' => $cash_admin->effective_user_id)); if ($settings_response['payload']) { AdminHelper::formSuccess('Success.', '/commerce/'); } } // now get the current currency setting $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'getsettings', 'type' => 'use_currency', 'user_id' => $cash_admin->effective_user_id)); if ($settings_response['payload']) { $current_currency = $settings_response['payload']; } else { $current_currency = 'USD';
protected function sendOrderReceipt($id = false, $order_details = false, $finalize_url = false) { if (!$id && !$order_details) { return false; } if (!$order_details) { $order_details = $this->getOrder($id, true); } $order_totals = $this->getOrderTotals($order_details['order_contents']); try { $personalized_message = ''; if ($order_details['element_id']) { $element_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getelement', 'id' => $order_details['element_id'])); if ($element_request->response['payload']) { if (isset($element_request->response['payload']['options']['message_email'])) { if ($element_request->response['payload']['options']['message_email']) { $personalized_message = $element_request->response['payload']['options']['message_email'] . "\n\n"; } } } } if ($order_details['digital']) { $addcode_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addlockcode', 'element_id' => $order_details['element_id'])); if (!$finalize_url) { $finalize_url = CASHSystem::getCurrentURL(); } return CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $order_details['customer_details']['email_address'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $order_totals['description'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($order_details['gross_price'], 2) . "\n\n" . "\n\n" . '[View your receipt and any downloads](' . $finalize_url . '?cash_request_type=element&cash_action=redeemcode&code=' . $addcode_request->response['payload'] . '&element_id=' . $order_details['element_id'] . '&email=' . urlencode($order_details['customer_details']['email_address']) . '&order_id=' . $order_details['id'] . ')', 'Thank you.'); } else { return CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $order_details['customer_details']['email_address'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $order_totals['description'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($order_details['gross_price'], 2) . "\n\n", 'Thank you.'); } } catch (Exception $e) { // TODO: handle the case where an email can't be sent. maybe display the download // code on-screen? that plus storing it with the order is probably enough return false; } }
protected function finalizeRedirectedPayment($order_id, $creation_date, $direct_post_details = false, $session_id = false) { $order_details = $this->getOrder($order_id); $transaction_details = $this->getTransaction($order_details['transaction_id']); $connection_type = $this->getConnectionType($transaction_details['connection_id']); $r = new CASHRequest(); $r->startSession(false, $session_id); $finalize_url = $r->sessionGet('payment_finalize_url'); if ($finalize_url) { $r->sessionClear('payment_finalize_url'); } switch ($connection_type) { case 'com.paypal': if (isset($_GET['token'])) { if (isset($_GET['PayerID'])) { $pp = new PaypalSeed($order_details['user_id'], $transaction_details['connection_id'], $_GET['token']); $initial_details = $pp->getExpressCheckout(); if ($initial_details['ACK'] == 'Success') { $order_totals = $this->getOrderTotals($order_details['order_contents']); if ($initial_details['AMT'] >= $order_totals['price']) { $final_details = $pp->doExpressCheckout(); if ($final_details) { // look for a user to match the email. if not present, make one $user_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getuseridforaddress', 'address' => $initial_details['EMAIL'])); $user_id = $user_request->response['payload']; if (!$user_id) { $user_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => $initial_details['EMAIL'], 'password' => time(), 'is_admin' => 0, 'display_name' => $initial_details['FIRSTNAME'] . ' ' . $initial_details['LASTNAME'], 'first_name' => $initial_details['FIRSTNAME'], 'last_name' => $initial_details['LASTNAME'], 'address_country' => $initial_details['COUNTRYCODE'])); $user_id = $user_request->response['payload']; } // deal with physical quantities if ($order_details['physical'] == 1) { $order_items = json_decode($order_details['order_contents'], true); if (is_array($order_items)) { foreach ($order_items as $i) { if ($i['available_units'] > 0 && $i['physical_fulfillment'] == 1) { $item = $this->getItem($i['id']); if ($i['variant']) { $variant_id = 0; $variant_qty = 0; if ($item['variants']) { foreach ($item['variants']['quantities'] as $q) { if ($q['key'] == $i['variant']) { $variant_id = $q['id']; $variant_qty = $q['value']; break; } } if ($variant_id) { $this->editItemVariant($variant_id, max($variant_qty - $i['qty'], 0), $i['id']); } } } else { $available_units = $this->editItem($i['id'], false, false, false, false, false, max($item['available_units'] - $i['qty'], 0)); } } } } } // record all the details if ($order_details['digital'] == 1 && $order_details['physical'] == 0) { // if the order is 100% digital just mark it as fulfilled $is_fulfilled = 1; } else { // there's something physical. sorry dude. gotta deal with it still. $is_fulfilled = 0; } $this->editOrder($order_id, $is_fulfilled, 0, false, $initial_details['COUNTRYCODE'], $user_id); $this->editTransaction($order_details['transaction_id'], strtotime($final_details['TIMESTAMP']), $final_details['CORRELATIONID'], json_encode($initial_details), json_encode($final_details), 1, $final_details['PAYMENTINFO_0_AMT'], $final_details['PAYMENTINFO_0_FEEAMT'], 'complete'); // empty the cart at this point $this->emptyCart($session_id); // TODO: add code to order metadata // bit of a hack, hard-wiring the email bits: try { $personalized_message = ''; if ($order_details['element_id']) { $element_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getelement', 'id' => $order_details['element_id'])); if ($element_request->response['payload']) { if (isset($element_request->response['payload']['options']['message_email'])) { if ($element_request->response['payload']['options']['message_email']) { $personalized_message = $element_request->response['payload']['options']['message_email'] . "\n\n"; } } } } if ($order_details['digital']) { $addcode_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addlockcode', 'element_id' => $order_details['element_id'])); if (!$finalize_url) { $finalize_url = CASHSystem::getCurrentURL(); } CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $initial_details['EMAIL'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $initial_details['PAYMENTREQUEST_0_DESC'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($final_details['PAYMENTINFO_0_AMT'], 2) . "\n\n" . "\n\n" . '[View your receipt and any downloads](' . $finalize_url . '?cash_request_type=element&cash_action=redeemcode&code=' . $addcode_request->response['payload'] . '&element_id=' . $order_details['element_id'] . '&email=' . urlencode($initial_details['EMAIL']) . '&order_id=' . $order_details['id'] . ')', 'Thank you.'); } else { CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $initial_details['EMAIL'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "** \n" . $initial_details['PAYMENTREQUEST_0_DESC'] . " \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($final_details['PAYMENTINFO_0_AMT'], 2) . "\n\n", 'Thank you.'); } } catch (Exception $e) { // TODO: handle the case where an email can't be sent. maybe display the download // code on-screen? that plus storing it with the order is probably enough } return $order_details['id']; } else { // make sure this isn't an accidentally refreshed page if ($initial_details['CHECKOUTSTATUS'] != 'PaymentActionCompleted') { $initial_details['ERROR_MESSAGE'] = $pp->getErrorMessage(); // there was an error processing the transaction $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], strtotime($initial_details['TIMESTAMP']), $initial_details['CORRELATIONID'], false, json_encode($initial_details), 0, false, false, 'error processing payment'); return false; } else { // this is a successful transaction with the user hitting refresh // as long as it's within 30 minutes of the original return true, otherwise // call it false and allow the page to expire if (time() - strtotime($initial_details['TIMESTAMP']) < 180) { return true; } else { return false; } } } } else { // insufficient funds — user changed amount? $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], strtotime($initial_details['TIMESTAMP']), $initial_details['CORRELATIONID'], false, json_encode($initial_details), 0, false, false, 'incorrect amount'); return false; } } else { // order reporting failure $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], strtotime($initial_details['TIMESTAMP']), $initial_details['CORRELATIONID'], false, json_encode($initial_details), 0, false, false, 'payment failed'); return false; } } else { // user canceled transaction $this->editOrder($order_id, 0, 1); $this->editTransaction($order_details['transaction_id'], time(), false, false, false, 0, false, false, 'canceled'); return false; } } break; default: return false; } }
if ($variant_response['payload']) { $item['variant'] = $variant_response['payload']; } } } if ($o['gross_price'] - $item_price) { $shipping_cost = CASHSystem::getCurrencySymbol($o['currency']) . number_format($o['gross_price'] - $item_price, 2); $item_price = CASHSystem::getCurrencySymbol($o['currency']) . number_format($item_price, 2); } else { $shipping_cost = false; } $customer_name = $o['customer_shipping_name']; if (!$customer_name) { $customer_name = $o['customer_name']; } $all_order_details[] = array('id' => $o['id'], 'customer_name' => $customer_name, 'customer_email' => $o['customer_email'], 'customer_address1' => $o['customer_address1'], 'customer_address2' => $o['customer_address2'], 'customer_city' => $o['customer_city'], 'customer_region' => $o['customer_region'], 'customer_postalcode' => $o['customer_postalcode'], 'customer_country' => $o['customer_country'], 'number' => '#' . str_pad($o['id'], 6, 0, STR_PAD_LEFT), 'date' => CASHSystem::formatTimeAgo((int) $order_date, true), 'order_description' => str_replace("\n", ' ', $o['order_description']), 'order_contents' => new ArrayIterator($order_contents), 'shipping' => $shipping_cost, 'itemtotal' => $item_price, 'gross' => CASHSystem::getCurrencySymbol($o['currency']) . number_format($o['gross_price'], 2), 'fulfilled' => $o['fulfilled'], 'notes' => $o['notes']); } } if (count($all_order_details) > 0) { if (count($all_order_details) > 10) { $cash_admin->page_data['show_pagination'] = true; $cash_admin->page_data['show_next'] = true; if ($cash_admin->page_data['show_previous']) { $cash_admin->page_data['show_nextandprevious'] = true; } array_pop($all_order_details); } $cash_admin->page_data['orders_recent'] = new ArrayIterator($all_order_details); $cash_admin->page_data['show_filters'] = true; } }
/** * MONIES * * @return array */ public static function echoCurrencyOptions($selected = 'USD') { $currencies = CASHSystem::getCurrencySymbol('all'); $all_options = ''; $has_selected = false; foreach ($currencies as $currency => $symbol) { $all_options .= '<option value="' . $currency . '"'; if (!$has_selected && $currency == $selected) { $all_options .= ' selected="selected"'; $has_selected = true; } $all_options .= '>' . $currency . ' / ' . $symbol . '</option>'; } return $all_options; }
public function getData() { $this->element_data['public_url'] = CASH_PUBLIC_URL; $item_request = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'getitemsforuser', 'user_id' => $this->element_data['user_id'])); $items = $item_request->response['payload']; $indexed_items = array(); foreach ($items as &$item) { $item['price'] = number_format($item['price'], 2, '.', ''); if ($item['available_units'] != 0) { $item['is_available'] = true; } else { $item['is_available'] = false; } if ($item['variants']) { $item['has_variants'] = true; $verified_attributes = array(); $item['attributes_count'] = count($item['variants']['attributes']); foreach ($item['variants']['attributes'] as $key => $attribute) { $attribute['index'] = $key; $attribute['name'] = '' . strtolower(str_replace(' ', '', $attribute['key'])); $verified_items = array(); foreach ($attribute['items'] as $i) { if ($i['value'] > 0) { // this means we've got some quantity for this specific attribute if ($item['attributes_count'] > 1) { // check if we have multiple attribute types // hard coding for 2 attributes RN, sort out which is "other" $counter_index = 1; if ($attribute['index'] == 1) { $counter_index = 0; } $counter_attribute = $item['variants']['attributes'][$counter_index]; $counter_key = $counter_attribute['key']; $this_frag = $attribute['key'] . '->' . $i['key']; // current attribute id for qty $counter_options = array(); $defaultArray = array(); foreach ($counter_attribute['items'] as $ci) { if (!in_array($ci['key'], $defaultArray)) { // here we're storing the default "other" dropdown for JS to use if ($ci['value'] > 0) { // check qty here too $defaultArray[] = $ci['key']; } } $that_frag = $counter_key . '->' . $ci['key']; // other attribute id // combine attribute ids to get the quantity key if ($counter_index == 1) { $qty_key = $this_frag . '+' . $that_frag; } else { $qty_key = $that_frag . '+' . $this_frag; } // we need to loop through our list of quantities and check keys foreach ($item['variants']['quantities'] as $q) { if ($q['key'] == $qty_key && $q['value']) { // check that value > 0 $counter_options[] = $ci['key']; break; } } } $attribute['defaultcountermenu'] = str_replace("'", "\\'", json_encode($defaultArray)); $i['countermenu'] = str_replace("'", "\\'", json_encode($counter_options)); } $verified_items[] = $i; } } if (count($verified_items)) { $attribute['items'] = $verified_items; $verified_attributes[] = $attribute; } } $item['attributes'] = $verified_attributes; } $indexed_items[$item['id']] = $item; } $cart_request = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'getcart', 'session_id' => $this->session_id)); $cart = $cart_request->response['payload']; if ($cart) { if (is_array($cart)) { $checkcount = count($cart); if (isset($cart['shipto'])) { $checkcount = $checkcount - 1; } if ($checkcount) { $this->element_data['items_in_cart'] = true; } } } else { $cart = array(); } $featured_items = array(); $unfeatured_items = array(); if (is_array($this->element_data['featured_items'])) { foreach ($this->element_data['featured_items'] as $i) { $featured_items[] = $indexed_items[$i['item_id']]; } } if (is_array($this->element_data['additional_items'])) { foreach ($this->element_data['additional_items'] as $i) { $unfeatured_items[] = $indexed_items[$i['item_id']]; } } $this->element_data['items'] = new ArrayIterator($unfeatured_items); $this->element_data['features'] = new ArrayIterator($featured_items); // get currency info for element owner $currency_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'getsettings', 'type' => 'use_currency', 'user_id' => $this->element_data['user_id'])); if ($currency_request->response['payload']) { $this->element_data['currency'] = CASHSystem::getCurrencySymbol($currency_request->response['payload']); } else { $this->element_data['currency'] = CASHSystem::getCurrencySymbol('USD'); } // get region information for element owner // now get the current setting $settings_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'getsettings', 'type' => 'regions', 'user_id' => $this->element_data['user_id'])); if ($settings_request->response['payload']) { $this->element_data['region1'] = $settings_request->response['payload']['region1']; $this->element_data['region2'] = $settings_request->response['payload']['region2']; } else { $this->element_data['region1'] = 'US'; $this->element_data['region2'] = 'International'; } if ($this->status_uid == 'commerce_finalizepayment_200' || $this->status_uid == 'element_redeemcode_200') { if ($this->status_uid == 'commerce_finalizepayment_200') { $this->element_data['order_id'] = $this->original_response['payload']; $verified = true; } else { if ($this->status_uid == 'element_redeemcode_200') { $this->element_data['order_id'] = $_GET['order_id']; $verified = false; } } $order_request = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'getorder', 'id' => $this->element_data['order_id'], 'deep' => true)); $order_details = $order_request->response['payload']; if ($order_details) { if ($this->status_uid == 'element_redeemcode_200') { if ($_GET['email'] == $order_details['customer_details']['email_address']) { $verified = true; } } if ($verified) { $order_contents = json_decode($order_details['order_contents'], true); $this->element_data['has_physical'] = false; $this->element_data['item_subtotal'] = 0; foreach ($order_contents as &$i) { $i['total_price'] = number_format($i['qty'] * $i['price'], 2); $this->element_data['item_subtotal'] += $i['total_price']; if ($i['fulfillment_asset'] != 0) { $fulfillment_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'getfulfillmentassets', 'asset_details' => $i['fulfillment_asset'])); if ($fulfillment_request->response['payload']) { $i['digital_fulfillment_details'] = new ArrayIterator($fulfillment_request->response['payload']); } } if (!$this->element_data['has_physical'] && $i['physical_fulfillment']) { $this->element_data['has_physical'] = true; } if ($i['variant']) { $variant_request = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'getitemvariants', 'item_id' => $i['id'])); if ($variant_request->response['payload']) { if (is_array($variant_request->response['payload'])) { foreach ($variant_request->response['payload']['quantities'] as $v) { if ($v['key'] == $i['variant']) { $i['variant_name'] = $v['formatted_name']; break; } } } } } } $this->element_data['shipping_subtotal'] = number_format($order_details['gross_price'] - $this->element_data['item_subtotal'], 2); $this->element_data['item_subtotal'] = number_format($this->element_data['item_subtotal'], 2); $this->element_data['total'] = number_format($order_details['gross_price'], 2); $this->element_data['order_contents'] = $order_contents; $this->setTemplate('success'); } } } elseif ($this->status_uid == 'commerce_finalizepayment_400' || $this->status_uid == 'element_redeemcode_400') { // payerid is specific to paypal, so this is temporary to tell between canceled and errored: if (isset($_GET['PayerID'])) { //$this->element_data['error_message'] = $this->options['message_error']; $this->element_data['error_message'] = print_r($this->original_response, true); } } elseif (isset($_REQUEST['state'])) { if ($_REQUEST['state'] == 'cart') { $subtotal = 0; $shipping = 0; $shippingr1 = 0; $shippingr2 = 0; $physical = false; $shipto = false; if (isset($cart['shipto'])) { if ($cart['shipto'] == 'r2') { $this->element_data['shiptor2'] = true; } else { if ($cart['shipto'] == 'r1') { $this->element_data['shiptor1'] = true; } } $shipto = $cart['shipto']; unset($cart['shipto']); } foreach ($cart as $key => &$i) { foreach ($items as $ii) { if ($ii['id'] == $i['id']) { $i['price'] = max($i['price'], $ii['price']); $i['total_price'] = number_format($i['qty'] * $i['price'], 2); //$i['shipping_r1'] = $ii['shipping']['r1-1']; if ($ii['physical_fulfillment']) { if (!$physical) { $physical = true; } if ($ii['shipping']) { if (isset($ii['shipping']['r1-1'])) { $i['shipping_r1'] = $ii['shipping']['r1-1']; $i['shipping_r1rest'] = $ii['shipping']['r1-1+']; $i['shipping_r2'] = $ii['shipping']['r2-1']; $i['shipping_r2rest'] = $ii['shipping']['r2-1+']; if ($shipto == 'r1' || $shipto == 'r2') { $shipping += $i['shipping_' . $shipto . 'rest'] * ($i['qty'] - 1) + $i['shipping_' . $shipto]; } $shippingr1 += $i['shipping_r1rest'] * ($i['qty'] - 1) + $i['shipping_r1']; $shippingr2 += $i['shipping_r2rest'] * ($i['qty'] - 1) + $i['shipping_r2']; } } } $subtotal += $i['total_price']; $i['name'] = $ii['name']; if ($i['variant']) { //$i['variant_fixed'] = str_replace(' ','+',$i['variant']); foreach ($ii['variants']['quantities'] as $q) { if ($q['key'] == $i['variant']) { //TODO: hacky fix for plus signs decoded as spaces $i['variant_name'] = $q['formatted_name']; break; } } } break; } } } $this->element_data['has_physical'] = $physical; $this->element_data['cart'] = new ArrayIterator($cart); $this->element_data['subtotal'] = number_format($subtotal, 2); if ($shipto) { $this->element_data['shipping'] = number_format($shipping, 2); } else { $this->element_data['shipping'] = 'TBD'; } $this->element_data['shippingr1'] = number_format($shippingr1, 2); $this->element_data['shippingr2'] = number_format($shippingr2, 2); $this->element_data['total'] = number_format($subtotal + $shipping, 2); $this->setTemplate('cart'); } } return $this->element_data; }