public function productNames()
 {
     $product = new Cart66Product();
     $ids = explode(',', $this->products);
     $selected = array();
     foreach ($ids as $id) {
         $product->load($id);
         $selected[] = array('id' => $id, 'name' => $product->name);
     }
     return $selected;
 }
 public function accountCreate($attrs)
 {
     $render_form = false;
     if (isset($attrs['product'])) {
         $product = new Cart66Product();
         $product->load($attrs['product']);
         if ($product->id <= 0) {
             $product->loadByItemNumber($attrs['product']);
         }
         if ($product->isMembershipProduct() || $product->isPayPalSubscription()) {
             $render_form = true;
         }
     }
     $data = array('attrs' => $attrs, 'render_form' => $render_form);
     $view = Cart66Common::getView('pro/views/account-create.php', $data);
     return $view;
 }
Exemplo n.º 3
0
 /**
  * Check to see if the order includes a product that requires an account and if there is an account in the system
  *
  * Return values:
  *   1 = The account exists
  *   0 = There is no account associated with the order and there is no need for one
  *  -1 = There is no account associated with the order but there should be
  *
  * @return int
  */
 public function hasAccount()
 {
     if ($this->id == 0 || empty($this->id)) {
         throw new Cart66Exception(66400, 'Cannot get account status on an order with no order id');
     }
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Account ID on order: " . $this->account_id);
     if ($this->account_id > 0) {
         return 1;
         // The order has an account associated with it
     } else {
         // No account exists for this order, but does it need one?
         $product = new Cart66Product();
         $items = $this->getItems();
         foreach ($items as $item) {
             $product->load($item->product_id);
             if ($product->isMembershipProduct() || $product->isSubscription()) {
                 return -1;
                 // No account exists but there should be one
             }
         }
     }
     return 0;
     // No account exists and none is needed.
 }
',
  	      '<?php 
            echo $order->ship_country;
            ?>
'
  	    ]);
  	  /* ]]> */
      </script>  
    <?php 
        }
        ?>
    <?php 
        foreach ($order->getItems() as $item) {
            ?>
      <?php 
            $product->load($item->product_id);
            $price = $item->product_price * $item->quantity;
            ?>
      <tr>
        <td>
          <?php 
            if (Cart66Setting::getValue('display_item_number_cart')) {
                ?>
            <span class="cart66-receipt-item-number"><?php 
                echo $item->item_number;
                ?>
</span>
          <?php 
            }
            ?>
          <b><?php 
    } catch (Cart66Exception $e) {
        $errorCode = $e->getCode();
        if ($errorCode == 66102) {
            // Product save failed
            $errors = $product->getErrors();
            $errorMessage = Cart66Common::showErrors($errors, "<p><b>" . __("The product could not be saved for the following reasons", "cart66") . ":</b></p>");
        } elseif ($errorCode == 66101) {
            // File upload failed
            $errors = $product->getErrors();
            $errorMessage = Cart66Common::showErrors($errors, "<p><b>" . __("The file upload failed", "cart66") . ":</b></p>");
        }
        Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Product save failed ({$errorCode}): " . strip_tags($errorMessage));
    }
} elseif (isset($_GET['task']) && $_GET['task'] == 'edit' && isset($_GET['id']) && $_GET['id'] > 0) {
    $id = Cart66Common::getVal('id');
    $product->load($id);
} elseif (isset($_GET['task']) && $_GET['task'] == 'delete' && isset($_GET['id']) && $_GET['id'] > 0) {
    $id = Cart66Common::getVal('id');
    $product->load($id);
    $product->deleteMe();
    $product->clear();
} elseif (isset($_GET['task']) && $_GET['task'] == 'xdownload' && isset($_GET['id']) && $_GET['id'] > 0) {
    // Load the product
    $id = Cart66Common::getVal('id');
    $product->load($id);
    // Delete the download file
    $setting = new Cart66Setting();
    $dir = Cart66Setting::getValue('product_folder');
    $path = $dir . DIRECTORY_SEPARATOR . $product->download_path;
    unlink($path);
    // Clear the name of the download file from the object and database
Exemplo n.º 6
0
        _e('Rate', 'cart66');
        ?>
</th>
    		<th><?php 
        _e('Bundle rate', 'cart66');
        ?>
</th>
        <th>&nbsp;</th>
    	</tr>
    </thead>
    <tbody>
      <?php 
        foreach ($rates as $r) {
            ?>
        <?php 
            $product->load($r->product_id);
            $method->load($r->shipping_method_id);
            ?>
        <tr>
          <td><?php 
            echo $product->item_number;
            ?>
 <?php 
            echo $product->name;
            ?>
</td>
          <td><?php 
            echo $method->name;
            ?>
</td>
          <td><?php 
Exemplo n.º 7
0
 public function getWeight()
 {
     if ($this->_productId > 0) {
         $p = new Cart66Product();
         $p->load($this->_productId);
         return $p->weight;
     }
     return false;
 }
 public static function loadPromotionProducts()
 {
     $productId = Cart66Common::postVal('productId');
     $product = new Cart66Product();
     $ids = explode(',', $productId);
     $selected = array();
     foreach ($ids as $id) {
         $product->load($id);
         $selected[] = array('id' => $id, 'name' => $product->name);
     }
     echo json_encode($selected);
     die;
 }
Exemplo n.º 9
0
    _e('Item Price', 'cart66');
    ?>
</th>
      <th class="cart66-align-right"><?php 
    _e('Item Total', 'cart66');
    ?>
</th>
    </tr>
  </thead>
  <tbody>
    <?php 
    foreach ($items as $itemIndex => $item) {
        ?>
      <?php 
        Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Item option info: " . $item->getOptionInfo());
        $product->load($item->getProductId());
        $price = $item->getProductPrice() * $item->getQuantity();
        ?>
      <tr>
        <td <?php 
        if ($item->hasAttachedForms()) {
            echo "class=\"noBottomBorder\"";
        }
        ?>
 >
          <?php 
        if (Cart66Setting::getValue('display_item_number_cart')) {
            ?>
            <span class="cart66-cart-item-number"><?php 
            echo $item->getItemNumber();
            ?>
Exemplo n.º 10
0
     if (count($errors)) {
         try {
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to process order: " . print_r($errors, true));
             throw new Cart66Exception(__('Your order could not be processed for the following reasons:', 'cart66'), 66500);
         } catch (Cart66Exception $e) {
             $exception = Cart66Exception::exceptionMessages($e->getCode(), $e->getMessage(), $errors);
             echo Cart66Common::getView('views/error-messages.php', $exception);
         }
     }
 }
 if ($create_account) {
     $account->save();
     $accountId = $account->id;
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Just created account with id: {$accountId}");
     $product = new Cart66Product();
     $product->load($data['attrs']['product']);
     if ($product->id <= 0) {
         $product->loadByItemNumber($data['attrs']['product']);
     }
     if ($product->id > 0) {
         $account->attachMembershipProduct($product, $account->firstName, $account->lastName);
         $accountId = $account->id;
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Attached membership to account id: {$accountId}");
     }
     if ($account->login($acctData['username'], $acctData['password'])) {
         Cart66Session::set('Cart66AccountId', $account->id);
     }
     if (isset($data['attrs']['url'])) {
         wp_redirect($data['attrs']['url']);
         exit;
     }
Exemplo n.º 11
0
 /**
  * Save a PayPal IPN order from a Website Payments Pro cart sale.
  *
  * @param array $pp Urldecoded array of IPN key value pairs
  */
 public function saveOrder($pp)
 {
     global $wpdb;
     // NEW Parse custom value
     $referrer = false;
     $ouid = $pp['custom'];
     if (strpos($ouid, '|') !== false) {
         list($ouid, $referrer, $gfData) = explode('|', $ouid);
     }
     $order = new Cart66Order();
     $order->loadByOuid($ouid);
     if ($order->id > 0 && $order->status == 'checkout_pending') {
         $hasDigital = false;
         // Calculate subtotal
         $subtotal = 0;
         $numCartItems = $pp['num_cart_items'] > 0 ? $pp['num_cart_items'] : 1;
         for ($i = 1; $i <= $numCartItems; $i++) {
             // PayPal in not consistent in the way it passes back the item amounts
             $amt = 0;
             if (isset($pp['mc_gross' . $i])) {
                 $amt = $pp['mc_gross' . $i];
             } elseif (isset($pp['mc_gross_' . $i])) {
                 $amt = $pp['mc_gross_' . $i];
             }
             $subtotal += $amt;
         }
         $statusOptions = Cart66Common::getOrderStatusOptions();
         $status = $statusOptions[0];
         // Parse Gravity Forms ids
         $gfIds = array();
         if (!empty($gfData)) {
             $forms = explode(',', $gfData);
             foreach ($forms as $f) {
                 list($itemId, $formEntryId) = explode(':', $f);
                 $gfIds[$itemId] = $formEntryId;
             }
         }
         // Look for discount amount
         $discount = 0;
         if (isset($pp['discount'])) {
             $discount = $pp['discount'];
         }
         $data = array('bill_first_name' => $pp['first_name'], 'bill_last_name' => $pp['last_name'], 'bill_address' => $pp['address_street'], 'bill_city' => $pp['address_city'], 'bill_state' => $pp['address_state'], 'bill_zip' => $pp['address_zip'], 'bill_country' => $pp['address_country'], 'ship_first_name' => $pp['address_name'], 'ship_address' => $pp['address_street'], 'ship_city' => $pp['address_city'], 'ship_state' => $pp['address_state'], 'ship_zip' => $pp['address_zip'], 'ship_country' => $pp['address_country'], 'email' => $pp['payer_email'], 'phone' => $pp['contact_phone'], 'shipping' => $pp['mc_handling'], 'tax' => $pp['tax'], 'subtotal' => $subtotal, 'total' => $pp['mc_gross'], 'discount_amount' => $discount, 'trans_id' => $pp['txn_id'], 'ordered_on' => date('Y-m-d H:i:s', Cart66Common::localTs()), 'status' => $status);
         foreach ($data as $key => $value) {
             $data[$key] = is_null($value) ? '' : $value;
         }
         // Verify the first items in the IPN are for products managed by Cart66. It could be an IPN from some other type of transaction.
         $productsTable = Cart66Common::getTableName('products');
         $orderItemsTable = Cart66Common::getTableName('order_items');
         $sql = "SELECT id from {$productsTable} where item_number = '" . $pp['item_number1'] . "'";
         $productId = $wpdb->get_var($sql);
         if (!$productId) {
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] about to throw an exception, this is not an IPN that should be managed by cart66 because the item number does not match up");
             throw new Exception("This is not an IPN that should be managed by Cart66");
         }
         // Look for the 100% coupons shipping item and move it back to a shipping costs rather than a product
         if ($data['shipping'] == 0) {
             for ($i = 1; $i <= $numCartItems; $i++) {
                 $itemNumber = strtoupper($pp['item_number' . $i]);
                 if ($itemNumber == 'SHIPPING') {
                     $data['shipping'] = isset($pp['mc_gross_' . $i]) ? $pp['mc_gross_' . $i] : $pp['mc_gross' . $i];
                 }
             }
         }
         $order->setData($data);
         $order->save();
         $orderId = $order->id;
         // Handle email receipts
         if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) {
             $notify = new Cart66AdvancedNotifications($orderId);
             $notify->sendAdvancedEmailReceipts();
         } elseif (CART66_EMAILS) {
             $notify = new Cart66Notifications($orderId);
             $notify->sendEmailReceipts();
         }
         // Process affiliate reward if necessary
         if ($referrer && CART66_PRO) {
             Cart66Common::awardCommission($order->id, $referrer);
             // End processing affiliate information
             if (isset($_COOKIE['ap_id']) && $_COOKIE['ap_id']) {
                 setcookie('ap_id', $referrer, time() - 3600, "/");
                 unset($_COOKIE['ap_id']);
             }
             Cart66Session::drop('app_id');
         }
         if (CART66_PRO) {
             // Begin iDevAffiliate Tracking
             if (CART66_PRO && ($url = Cart66Setting::getValue('idevaff_url'))) {
                 require_once CART66_PATH . "/pro/idevaffiliate-award.php";
             }
             // End iDevAffiliate Tracking
         }
     } else {
         $orderTable = Cart66Common::getTableName('orders');
         // Make sure the transaction id is not already in the database
         $sql = "SELECT count(*) as c from {$orderTable} where trans_id=%s";
         $sql = $wpdb->prepare($sql, $pp['txn_id']);
         $count = $wpdb->get_var($sql);
         if ($count < 1) {
             $hasDigital = false;
             // Calculate subtotal
             $subtotal = 0;
             $numCartItems = $pp['num_cart_items'] > 0 ? $pp['num_cart_items'] : 1;
             for ($i = 1; $i <= $numCartItems; $i++) {
                 // PayPal in not consistent in the way it passes back the item amounts
                 $amt = 0;
                 if (isset($pp['mc_gross' . $i])) {
                     $amt = $pp['mc_gross' . $i];
                 } elseif (isset($pp['mc_gross_' . $i])) {
                     $amt = $pp['mc_gross_' . $i];
                 }
                 $subtotal += $amt;
             }
             $statusOptions = Cart66Common::getOrderStatusOptions();
             $status = $statusOptions[0];
             $ouid = md5($pp['txn_id'] . $pp['address_street']);
             // Parse custom value
             $referrer = false;
             $deliveryMethod = $pp['custom'];
             if (strpos($deliveryMethod, '|') !== false) {
                 list($deliveryMethod, $referrer, $gfData, $coupon) = explode('|', $deliveryMethod);
             }
             // Parse Gravity Forms ids
             $gfIds = array();
             if (!empty($gfData)) {
                 $forms = explode(',', $gfData);
                 foreach ($forms as $f) {
                     list($itemId, $formEntryId) = explode(':', $f);
                     $gfIds[$itemId] = $formEntryId;
                 }
             }
             // Look for discount amount
             $discount = 0;
             if (isset($pp['discount'])) {
                 $discount = $pp['discount'];
             }
             // Look for coupon code
             $coupon_code = "none";
             if (isset($coupon) && $coupon != "") {
                 $coupon_code = $coupon;
             }
             $data = array('bill_first_name' => $pp['first_name'], 'bill_last_name' => $pp['last_name'], 'bill_address' => $pp['address_street'], 'bill_city' => $pp['address_city'], 'bill_state' => $pp['address_state'], 'bill_zip' => $pp['address_zip'], 'bill_country' => $pp['address_country'], 'ship_first_name' => $pp['address_name'], 'ship_address' => $pp['address_street'], 'ship_city' => $pp['address_city'], 'ship_state' => $pp['address_state'], 'ship_zip' => $pp['address_zip'], 'ship_country' => $pp['address_country'], 'shipping_method' => $deliveryMethod, 'email' => $pp['payer_email'], 'phone' => $pp['contact_phone'], 'shipping' => $pp['mc_handling'], 'tax' => $pp['tax'], 'subtotal' => $subtotal, 'total' => $pp['mc_gross'], 'coupon' => $coupon_code, 'discount_amount' => $discount, 'trans_id' => $pp['txn_id'], 'ordered_on' => date('Y-m-d H:i:s', Cart66Common::localTs()), 'status' => $status, 'ouid' => $ouid);
             $data = Cart66Common::deNullArrayValues($data);
             // Verify the first items in the IPN are for products managed by Cart66. It could be an IPN from some other type of transaction.
             $productsTable = Cart66Common::getTableName('products');
             $orderItemsTable = Cart66Common::getTableName('order_items');
             $sql = "SELECT id from {$productsTable} where item_number = '" . $pp['item_number1'] . "'";
             $productId = $wpdb->get_var($sql);
             if (!$productId) {
                 throw new Exception("This is not an IPN that should be managed by Cart66");
             }
             // Look for the 100% coupons shipping item and move it back to a shipping costs rather than a product
             if ($data['shipping'] == 0) {
                 for ($i = 1; $i <= $numCartItems; $i++) {
                     $itemNumber = strtoupper($pp['item_number' . $i]);
                     if ($itemNumber == 'SHIPPING') {
                         $data['shipping'] = isset($pp['mc_gross_' . $i]) ? $pp['mc_gross_' . $i] : $pp['mc_gross' . $i];
                     }
                 }
             }
             $wpdb->insert($orderTable, $data);
             $orderId = $wpdb->insert_id;
             $product = new Cart66Product();
             for ($i = 1; $i <= $numCartItems; $i++) {
                 $sql = "SELECT id from {$productsTable} where item_number = '" . $pp['item_number' . $i] . "'";
                 $productId = $wpdb->get_var($sql);
                 if ($productId > 0) {
                     $product->load($productId);
                     // Decrement inventory
                     $info = $pp['item_name' . $i];
                     if (strpos($info, '(') > 0) {
                         $info = strrchr($info, '(');
                         $start = strpos($info, '(');
                         $end = strpos($info, ')');
                         $length = $end - $start;
                         $variation = substr($info, $start + 1, $length - 1);
                         Cart66Common::log("PayPal Variation Information: {$variation}\n{$info}");
                     }
                     $qty = $pp['quantity' . $i];
                     Cart66Product::decrementInventory($productId, $variation, $qty);
                     if ($hasDigital == false) {
                         $hasDigital = $product->isDigital();
                     }
                     // PayPal is not consistent in the way it passes back the item amounts
                     $amt = 0;
                     if (isset($pp['mc_gross' . $i])) {
                         $amt = $pp['mc_gross' . $i];
                     } elseif (isset($pp['mc_gross_' . $i])) {
                         $amt = $pp['mc_gross_' . $i] / $pp['quantity' . $i];
                     }
                     // Look for Gravity Form Entry ID
                     $formEntryId = '';
                     if (is_array($gfIds) && !empty($gfIds) && isset($gfIds[$i])) {
                         $formEntryId = $gfIds[$i];
                         if (class_exists('RGFormsModel')) {
                             if ($lead = RGFormsModel::get_lead($formEntryId)) {
                                 $lead['status'] = 'active';
                                 RGFormsModel::update_lead($lead);
                             }
                         }
                     }
                     $duid = md5($pp['txn_id'] . '-' . $orderId . '-' . $productId);
                     $data = array('order_id' => $orderId, 'product_id' => $productId, 'item_number' => $pp['item_number' . $i], 'product_price' => $amt, 'description' => $pp['item_name' . $i], 'quantity' => $pp['quantity' . $i], 'duid' => $duid, 'form_entry_ids' => $formEntryId);
                     $wpdb->insert($orderItemsTable, $data);
                 }
             }
             // Handle email receipts
             if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) {
                 $notify = new Cart66AdvancedNotifications($orderId);
                 $notify->sendAdvancedEmailReceipts();
             } elseif (CART66_EMAILS) {
                 $notify = new Cart66Notifications($orderId);
                 $notify->sendEmailReceipts();
             }
             $promotion = new Cart66Promotion();
             $promotion->loadByCode($coupon_code);
             if ($promotion) {
                 $promotion->updateRedemptions();
             }
             // Process affiliate reward if necessary
             if ($referrer) {
                 Cart66Common::awardCommission($orderId, $referrer);
             }
         }
         // end transaction id check
     }
 }
Exemplo n.º 12
0
 public function checkCustomFieldsOnCheckout()
 {
     global $post;
     $checkoutPage = get_page_by_path('store/checkout');
     $cartPage = get_page_by_path('store/cart');
     $sendBack = false;
     if (isset($post) && is_object($post) && is_object($cartPage) && is_object($checkoutPage)) {
         if ($post->ID == $checkoutPage->ID || $post->ID == $cartPage->ID) {
             $items = Cart66Session::get('Cart66Cart')->getItems();
             $product = new Cart66Product();
             $requiredProducts = array();
             foreach ($items as $itemIndex => $item) {
                 $product->load($item->getProductId());
                 if ($post->ID == $checkoutPage->ID && $product->custom_required && !$item->getCustomFieldInfo()) {
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] required custom field is empty");
                     $requiredProducts[] = $product->name;
                     $link = get_permalink($cartPage->ID);
                     $sendBack = true;
                 }
             }
             if (!empty($requiredProducts)) {
                 Cart66Session::set('Cart66CustomFieldWarning', $requiredProducts);
             }
             if ($sendBack) {
                 wp_redirect($link);
                 exit;
             }
         }
     }
 }
 public function getProductsAndIds()
 {
     $product = new Cart66Product();
     $products = array();
     foreach ($this->_items as $item) {
         //needs to be changed because _items is a private cart function
         $product->load($item->getProductId());
         $products[] = $product->id;
     }
     return $products;
 }
Exemplo n.º 14
0
 public function defaultPlainEmailMessage($order)
 {
     $msg = __("ORDER NUMBER", "cart66") . ": " . $order->trans_id . "\n\n";
     $hasDigital = false;
     $product = new Cart66Product();
     foreach ($order->getItems() as $item) {
         $product->load($item->product_id);
         if ($hasDigital == false) {
             $hasDigital = $product->isDigital();
         }
         $price = $item->product_price * $item->quantity;
         // $msg .= "Item: " . $item->item_number . ' ' . $item->description . "\n";
         $msg .= __("Item", "cart66") . ": " . $item->description . "\n";
         if ($hasDigital) {
             $receiptPage = get_page_by_path('store/receipt');
             $receiptPageLink = get_permalink($receiptPage);
             $receiptPageLink .= strstr($receiptPageLink, '?') ? '&duid=' . $item->duid : '?duid=' . $item->duid;
             $msg .= "\n" . $receiptPageLink . "\n";
         }
         if ($item->quantity > 1) {
             $msg .= __("Quantity", "cart66") . ": " . $item->quantity . "\n";
         }
         $msg .= __("Item Price", "cart66") . ": " . Cart66Common::currency($item->product_price, false) . "\n";
         $msg .= __("Item Total", "cart66") . ": " . Cart66Common::currency($item->product_price * $item->quantity, false) . "\n\n";
         if ($product->isGravityProduct()) {
             $msg .= Cart66GravityReader::displayGravityForm($item->form_entry_ids, true);
         }
     }
     if ($order->shipping_method != 'None' && $order->shipping_method != 'Download') {
         $msg .= __("Shipping", "cart66") . ": " . Cart66Common::currency($order->shipping, false) . "\n";
     }
     if (!empty($order->coupon) && $order->coupon != 'none') {
         $msg .= __("Coupon", "cart66") . ": " . $order->coupon . "\n";
     }
     if ($order->tax > 0) {
         $msg .= __("Tax", "cart66") . ": " . Cart66Common::currency($order->tax, false) . "\n";
     }
     $msg .= "\n" . __("TOTAL", "cart66") . ": " . Cart66Common::currency($order->total, false) . "\n";
     if ($order->shipping_method != 'None' && $order->shipping_method != 'Download') {
         $msg .= "\n\n" . __("SHIPPING INFORMATION", "cart66") . "\n\n";
         $msg .= $order->ship_first_name . ' ' . $order->ship_last_name . "\n";
         $msg .= $order->ship_address . "\n";
         if (!empty($order->ship_address2)) {
             $msg .= $order->ship_address2 . "\n";
         }
         $msg .= $order->ship_city . ' ' . $order->ship_state . ' ' . $order->ship_zip . "\n" . $order->ship_country . "\n";
         if (is_array($additional_fields = maybe_unserialize($order->additional_fields)) && isset($additional_fields['shipping'])) {
             foreach ($additional_fields['shipping'] as $af) {
                 $msg .= html_entity_decode($af['label']) . ': ' . $af['value'] . "\n";
             }
         }
         $msg .= "\n" . __("Delivery via", "cart66") . ": " . $order->shipping_method . "\n";
     }
     $msg .= "\n\n" . __("BILLING INFORMATION", "cart66") . "\n\n";
     $msg .= $order->bill_first_name . ' ' . $order->bill_last_name . "\n";
     $msg .= $order->bill_address . "\n";
     if (!empty($order->bill_address2)) {
         $msg .= $order->bill_address2 . "\n";
     }
     $msg .= $order->bill_city . ' ' . $order->bill_state;
     $msg .= $order->bill_zip != null ? ', ' : ' ';
     $msg .= $order->bill_zip . "\n" . $order->bill_country . "\n";
     if (is_array($additional_fields = maybe_unserialize($order->additional_fields)) && isset($additional_fields['billing'])) {
         foreach ($additional_fields['billing'] as $af) {
             $msg .= html_entity_decode($af['label']) . ': ' . $af['value'] . "\n";
         }
     }
     if (!empty($order->phone)) {
         $phone = Cart66Common::formatPhone($order->phone);
         $msg .= "\n" . __("Phone", "cart66") . ": {$phone}\n";
     }
     if (!empty($order->email)) {
         $msg .= __("Email", "cart66") . ': ' . $order->email . "\n";
     }
     if (is_array($additional_fields = maybe_unserialize($order->additional_fields)) && isset($additional_fields['payment'])) {
         foreach ($additional_fields['payment'] as $af) {
             $msg .= html_entity_decode($af['label']) . ': ' . $af['value'] . "\n";
         }
     }
     if (isset($order->custom_field) && $order->custom_field != '') {
         if (Cart66Setting::getValue('checkout_custom_field_label')) {
             $msg .= "\n" . Cart66Setting::getValue('checkout_custom_field_label');
         } else {
             $msg .= "\n" . __('Enter any special instructions you have for this order:', 'cart66');
         }
         $msg .= "\n" . $order->custom_field . "\n";
     }
     $receiptPage = get_page_by_path('store/receipt');
     $link = get_permalink($receiptPage->ID);
     if (strstr($link, "?")) {
         $link .= '&ouid=' . $order->ouid;
     } else {
         $link .= '?ouid=' . $order->ouid;
     }
     if ($hasDigital) {
         $msg .= "\n" . __('DOWNLOAD LINK', 'cart66') . "\n" . __('Click the link below to download your order.', 'cart66') . "\n{$link}";
     } else {
         $msg .= "\n" . __('VIEW RECEIPT ONLINE', 'cart66') . "\n" . __('Click the link below to view your receipt online.', 'cart66') . "\n{$link}";
     }
     $msgIntro = Cart66Setting::getValue('receipt_intro') && !Cart66Setting::getValue('enable_advanced_notifications') ? Cart66Setting::getValue('receipt_intro') : '';
     $msgIntro .= Cart66Setting::getValue('receipt_message_intro') && Cart66Setting::getValue('enable_advanced_notifications') ? Cart66Setting::getValue('receipt_plain_email') : '';
     $msg = $msgIntro . " \n----------------------------------\n\n" . $msg;
     return $msg;
 }
 public function getDiscountAmount($cartObject = null, $taxed_products = false)
 {
     $p = new Cart66Product();
     //Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Running getDiscountAmount()");
     $discount = 0;
     if (!$cartObject) {
         $cartObject = Cart66Session::get('Cart66Cart');
     }
     if ($this->apply_to == "products" && !empty($cartObject)) {
         // coupon applies to products
         $products = explode(',', $this->products);
         $cartItems = $cartObject->getItems();
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] The number of items in the cart: " . count($cartItems));
         $usedThisOrder = 0;
         if (empty($this->products)) {
             // all products
             // apply coupon to every item in the cart
             $counter = 0;
             foreach ($cartItems as $item) {
                 $p->load($item->getProductId());
                 if (!$taxed_products || $taxed_products && $p->taxable == 1) {
                     $basePrice = $item->getBaseProductPrice();
                     $stayPositivePrice = $this->stayPositive($basePrice, $this->getAmount($basePrice));
                     $quantity = $item->getQuantity();
                     for ($i = 1; $i <= $quantity; $i++) {
                         if (empty($this->max_uses_per_order)) {
                             $discount += $stayPositivePrice;
                             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Max uses per order is empty. Discount: {$discount}");
                         } elseif ($counter < $this->max_uses_per_order) {
                             $discount += $stayPositivePrice;
                             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Max uses per order is NOT empty. Discount: {$discount} :: Stay Positive: {$stayPositivePrice}");
                         }
                         $counter++;
                     }
                 }
             }
         } else {
             // coupon applies to specific products
             foreach ($cartItems as $item) {
                 $p->load($item->getProductId());
                 if (!$taxed_products || $taxed_products && $p->taxable == 1) {
                     if ($this->exclude_from_products == 0) {
                         if (in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemQuantity = $item->getQuantity();
                             if ($this->max_uses_per_order > 0) {
                                 $usesRemaining = $this->max_uses_per_order - $usedThisOrder;
                                 $allowedQuantity = $usesRemaining <= $itemQuantity ? $usesRemaining : $itemQuantity;
                             } else {
                                 $allowedQuantity = $itemQuantity;
                             }
                             $productDiscount = $this->getAmount($item->getBaseProductPrice());
                             $discount += $allowedQuantity * $this->stayPositive($item->getBaseProductPrice(), $productDiscount);
                         }
                     } elseif ($this->exclude_from_products == 1) {
                         if (!in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemQuantity = $item->getQuantity();
                             if ($this->max_uses_per_order > 0) {
                                 $usesRemaining = $this->max_uses_per_order - $usedThisOrder;
                                 $allowedQuantity = $usesRemaining <= $itemQuantity ? $usesRemaining : $itemQuantity;
                             } else {
                                 $allowedQuantity = $itemQuantity;
                             }
                             $productDiscount = $this->getAmount($item->getBaseProductPrice());
                             $discount += $allowedQuantity * $this->stayPositive($item->getBaseProductPrice(), $productDiscount);
                         }
                     }
                 }
             }
         }
     }
     if ($this->apply_to == "shipping") {
         $shipping = $cartObject->getShippingCost();
         $discount = $shipping - $this->getAmount($shipping) < 0 ? $shipping : $this->getAmount($shipping);
     }
     if ($this->apply_to == "total") {
         $shipping = $cartObject->getShippingCost();
         $products = $cartObject->getSubTotal();
         $discount = $this->getAmount($shipping + $products, $shipping + $products);
     }
     if ($this->apply_to == "subtotal") {
         // coupon applies to subtotal
         $products = explode(',', $this->products);
         $cartItems = $cartObject->getItems();
         if (empty($this->products)) {
             $products = $cartObject->getSubTotal($taxed_products);
             $discount = $this->getAmount($products, $products);
         } else {
             $itemSubtotal = 0;
             // coupon applies to specific products
             foreach ($cartItems as $item) {
                 $p->load($item->getProductId());
                 if (!$taxed_products || $taxed_products && $p->taxable == 1) {
                     if ($this->exclude_from_products == 0) {
                         if (in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemSubtotal += $item->getProductPrice() * $item->getQuantity();
                         }
                     } elseif ($this->exclude_from_products == 1) {
                         if (!in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemSubtotal += $item->getProductPrice() * $item->getQuantity();
                         }
                     }
                 }
             }
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] item subtotal: {$itemSubtotal}");
             $discount = $this->getAmount($itemSubtotal, $itemSubtotal);
             $discount = $this->stayPositive($itemSubtotal, $discount);
         }
     }
     // format
     $discount = number_format($discount, 2, '.', '');
     return $discount;
 }
Exemplo n.º 16
0
 public function getDiscountAmount($cartObject = null, $taxed_products = false)
 {
     $p = new Cart66Product();
     //Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Running getDiscountAmount()");
     $discount = 0;
     if (!$cartObject) {
         $cartObject = Cart66Session::get('Cart66Cart');
     }
     // First, check to see if a membership group is excluded from using this coupon
     if ($this->membership_eligibility) {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] This coupon requires a membership to use:" . $this->membership_eligibility);
         if (Cart66Common::isLoggedIn()) {
             if ($this->membership_eligibility == "guest") {
                 // The user is logged in as a non-guest and this is a guest-only coupon. Return 0.00
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] The user is logged in as a non-guest and this is a guest-only coupon.");
                 return number_format($discount, 2, '.', '');
             }
             $account = new Cart66Account();
             if ($account->load(Cart66Session::get('Cart66AccountId'))) {
                 $userFeatureLevel = $account->getFeatureLevel();
                 $allowedLevels = Cart66Common::trimmedExplode(',', $this->membership_eligibility);
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] The user is logged in as " . $userFeatureLevel);
                 if (!in_array($userFeatureLevel, $allowedLevels)) {
                     // The user is logged in, but cannot use this coupon. Return 0.00
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] The user is logged in as " . $userFeatureLevel . " and is not eligible to use this coupon.");
                     return number_format($discount, 2, '.', '');
                 }
             }
         } else {
             // The user is not logged in...and this coupon requires a login to work, no discount
             if ($this->membership_eligibility && $this->membership_eligibility != "guest") {
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] The user is not logged in, cant use this coupon as guest.");
                 return number_format($discount, 2, '.', '');
             }
         }
     }
     if ($this->apply_to == "products" && !empty($cartObject)) {
         // coupon applies to products
         $products = explode(',', $this->products);
         $cartItems = $cartObject->getItems();
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] The number of items in the cart: " . count($cartItems));
         $usedThisOrder = 0;
         if (empty($this->products)) {
             // all products
             // apply coupon to every item in the cart
             $counter = 0;
             foreach ($cartItems as $item) {
                 $p->load($item->getProductId());
                 if (!$taxed_products || $taxed_products && $p->taxable == 1) {
                     $basePrice = $item->getBaseProductPrice();
                     $stayPositivePrice = $this->stayPositive($basePrice, $this->getAmount($basePrice));
                     $quantity = $item->getQuantity();
                     for ($i = 1; $i <= $quantity; $i++) {
                         if (empty($this->max_uses_per_order)) {
                             $discount += $stayPositivePrice;
                             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Max uses per order is empty. Discount: {$discount}");
                         } elseif ($counter < $this->max_uses_per_order) {
                             $discount += $stayPositivePrice;
                             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Max uses per order is NOT empty. Discount: {$discount} :: Stay Positive: {$stayPositivePrice}");
                         }
                         $counter++;
                     }
                 }
             }
         } else {
             // coupon applies to specific products
             foreach ($cartItems as $item) {
                 $p->load($item->getProductId());
                 if (!$taxed_products || $taxed_products && $p->taxable == 1) {
                     if ($this->exclude_from_products == 0) {
                         if (in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemQuantity = $item->getQuantity();
                             if ($this->max_uses_per_order > 0) {
                                 $usesRemaining = $this->max_uses_per_order - $usedThisOrder;
                                 $allowedQuantity = $usesRemaining <= $itemQuantity ? $usesRemaining : $itemQuantity;
                             } else {
                                 $allowedQuantity = $itemQuantity;
                             }
                             $productDiscount = $this->getAmount($item->getBaseProductPrice());
                             $discount += $allowedQuantity * $this->stayPositive($item->getBaseProductPrice(), $productDiscount);
                         }
                     } elseif ($this->exclude_from_products == 1) {
                         if (!in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemQuantity = $item->getQuantity();
                             if ($this->max_uses_per_order > 0) {
                                 $usesRemaining = $this->max_uses_per_order - $usedThisOrder;
                                 $allowedQuantity = $usesRemaining <= $itemQuantity ? $usesRemaining : $itemQuantity;
                             } else {
                                 $allowedQuantity = $itemQuantity;
                             }
                             $productDiscount = $this->getAmount($item->getBaseProductPrice());
                             $discount += $allowedQuantity * $this->stayPositive($item->getBaseProductPrice(), $productDiscount);
                         }
                     }
                 }
             }
         }
     }
     if ($this->apply_to == "shipping") {
         $shipping = $cartObject->getShippingCost();
         $discount = $shipping - $this->getAmount($shipping) < 0 ? $shipping : $this->getAmount($shipping);
     }
     if ($this->apply_to == "total") {
         $shipping = $cartObject->getShippingCost();
         $products = $cartObject->getSubTotal();
         $discount = $this->getAmount($shipping + $products, $shipping + $products);
     }
     if ($this->apply_to == "subtotal") {
         // coupon applies to subtotal
         $products = explode(',', $this->products);
         $cartItems = $cartObject->getItems();
         if (empty($this->products)) {
             $products = $cartObject->getSubTotal($taxed_products);
             $discount = $this->getAmount($products, $products);
         } else {
             $itemSubtotal = 0;
             // coupon applies to specific products
             foreach ($cartItems as $item) {
                 $p->load($item->getProductId());
                 if (!$taxed_products || $taxed_products && $p->taxable == 1) {
                     if ($this->exclude_from_products == 0) {
                         if (in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemSubtotal += $item->getProductPrice() * $item->getQuantity();
                         }
                     } elseif ($this->exclude_from_products == 1) {
                         if (!in_array($item->getProductId(), $products)) {
                             // add up discount
                             $itemSubtotal += $item->getProductPrice() * $item->getQuantity();
                         }
                     }
                 }
             }
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] item subtotal: {$itemSubtotal}");
             $discount = $this->getAmount($itemSubtotal, $itemSubtotal);
             $discount = $this->stayPositive($itemSubtotal, $discount);
         }
     }
     // format
     $discount = number_format($discount, 2, '.', '');
     return $discount;
 }