Ejemplo n.º 1
0
function tags_meta_box($Product)
{
    $taglist = array();
    foreach ($Product->tags as $tag) {
        $taglist[] = $tag->name;
    }
    ?>
<input name="newtags" id="newtags" type="text" size="16" tabindex="4" autocomplete="off" value="<?php 
    _e('enter, new, tags', 'Shopp');
    ?>
…" title="<?php 
    _e('enter, new, tags', 'Shopp');
    ?>
…" class="form-input-tip" />
	<button type="button" name="addtags" id="add-tags" class="button-secondary" tabindex="5"><small><?php 
    _e('Add', 'Shopp');
    ?>
</small></button><input type="hidden" name="taglist" id="tags" value="<?php 
    echo join(",", attribute_escape_deep($taglist));
    ?>
"><br />
<label><?php 
    _e('Separate tags with commas', 'Shopp');
    ?>
</label>
<div id="taglist">
	<label><big><strong><?php 
    _e('Tags for this product:', 'Shopp');
    ?>
</strong></big></label><br />
	<div id="tagchecklist" class="tagchecklist"></div>
</div>
<?php 
}
 /**
  * checkout()
  * Handles checkout process */
 function checkout($wp)
 {
     $pages = $this->Settings->get('pages');
     // If checkout page requested
     // Note: we have to use custom detection here as
     // the wp->post vars are not available at this point
     // to make use of is_shopp_page()
     if ((SHOPP_PERMALINKS && isset($wp->query_vars['pagename']) && $wp->query_vars['pagename'] == $pages['checkout']['permalink'] || isset($wp->query_vars['page_id']) && $wp->query_vars['page_id'] == $pages['checkout']['id']) && $wp->query_vars['shopp_proc'] == "checkout") {
         $this->Cart->updated();
         $this->Cart->totals();
         if ($this->Cart->data->ShippingPostcodeError) {
             header('Location: ' . $this->link('cart'));
             exit;
         }
         // Force secure checkout page if its not already
         $secure = true;
         $gateway = $this->Settings->get('payment_gateway');
         if (strpos($gateway, "TestMode") !== false || isset($wp->query_vars['shopp_xco']) || $this->Cart->orderisfree()) {
             $secure = false;
         }
         if ($secure && !$this->secure && !SHOPP_NOSSL) {
             header('Location: ' . $this->link('checkout', $secure));
             exit;
         }
     }
     // Cancel this process if there is no order data
     if (!isset($this->Cart->data->Order)) {
         return;
     }
     $Order = $this->Cart->data->Order;
     // Intercept external checkout processing
     if (!empty($wp->query_vars['shopp_xco'])) {
         if ($this->gateway($wp->query_vars['shopp_xco'])) {
             if ($wp->query_vars['shopp_proc'] != "confirm-order" && !isset($_POST['checkout'])) {
                 $this->Gateway->checkout();
                 $this->Gateway->error();
             }
         }
     }
     // Cancel if no checkout process detected
     if (empty($_POST['checkout'])) {
         return true;
     }
     // Handoff to order processing
     if ($_POST['checkout'] == "confirmed") {
         return $this->Flow->order();
     }
     // Cancel if checkout process is not ready for processing
     if ($_POST['checkout'] != "process") {
         return true;
     }
     // Cancel if processing a login from the checkout form
     if (isset($_POST['process-login']) && $_POST['process-login'] == "true") {
         return true;
     }
     // Start processing the checkout form
     $_POST = attribute_escape_deep($_POST);
     $_POST['billing']['cardexpires'] = sprintf("%02d%02d", $_POST['billing']['cardexpires-mm'], $_POST['billing']['cardexpires-yy']);
     // If the card number is provided over a secure connection
     // Change the cart to operate in secure mode
     if (isset($_POST['billing']['card']) && is_shopp_secure()) {
         $this->Cart->secured(true);
     }
     // Sanitize the card number to ensure it only contains numbers
     $_POST['billing']['card'] = preg_replace('/[^\\d]/', '', $_POST['billing']['card']);
     if (isset($_POST['data'])) {
         $Order->data = stripslashes_deep($_POST['data']);
     }
     if (empty($Order->Customer)) {
         $Order->Customer = new Customer();
     }
     $Order->Customer->updates($_POST);
     if (isset($_POST['confirm-password'])) {
         $Order->Customer->confirm_password = $_POST['confirm-password'];
     }
     if (empty($Order->Billing)) {
         $Order->Billing = new Billing();
     }
     $Order->Billing->updates($_POST['billing']);
     if (!empty($_POST['billing']['cardexpires-mm']) && !empty($_POST['billing']['cardexpires-yy'])) {
         $Order->Billing->cardexpires = mktime(0, 0, 0, $_POST['billing']['cardexpires-mm'], 1, $_POST['billing']['cardexpires-yy'] + 2000);
     } else {
         $Order->Billing->cardexpires = 0;
     }
     $Order->Billing->cvv = preg_replace('/[^\\d]/', '', $_POST['billing']['cvv']);
     if (empty($Order->Shipping)) {
         $Order->Shipping = new Shipping();
     }
     if (isset($_POST['shipping'])) {
         $Order->Shipping->updates($_POST['shipping']);
     }
     if (!empty($_POST['shipmethod'])) {
         $Order->Shipping->method = $_POST['shipmethod'];
     } else {
         $Order->Shipping->method = key($this->Cart->data->ShipCosts);
     }
     // Override posted shipping updates with billing address
     if ($_POST['sameshipaddress'] == "on") {
         $Order->Shipping->updates($Order->Billing, array("_datatypes", "_table", "_key", "_lists", "id", "created", "modified"));
     }
     $estimatedTotal = $this->Cart->data->Totals->total;
     $this->Cart->updated();
     $this->Cart->totals();
     if ($this->Cart->validate() !== true) {
         return;
     } else {
         $Order->Customer->updates($_POST);
     }
     // Catch changes from validation
     // If the cart's total changes at all, confirm the order
     if ($estimatedTotal != $this->Cart->data->Totals->total || $this->Settings->get('order_confirmation') == "always") {
         $gateway = $this->Settings->get('payment_gateway');
         $secure = true;
         if (strpos($gateway, "TestMode") !== false || isset($wp->query_vars['shopp_xco']) || $this->Cart->orderisfree()) {
             $secure = false;
         }
         shopp_redirect($this->link('confirm-order', $secure));
     } else {
         $this->Flow->order();
     }
 }
 function Item($Product, $pricing, $category, $data = array())
 {
     global $Shopp;
     // To access settings
     $Product->load_data(array('prices', 'images'));
     // If product variations are enabled, disregard the first priceline
     if ($Product->variations == "on") {
         array_shift($Product->prices);
     }
     // If option ids are passed, lookup by option key, otherwise by id
     if (is_array($pricing)) {
         $Price = $Product->pricekey[$Product->optionkey($pricing)];
         if (empty($Price)) {
             $Price = $Product->pricekey[$Product->optionkey($pricing, true)];
         }
     } elseif ($pricing) {
         $Price = $Product->priceid[$pricing];
     } else {
         foreach ($Product->prices as &$Price) {
             if ($Price->type != "N/A" && (!$Price->stocked || $Price->stocked && $Price->stock > 0)) {
                 break;
             }
         }
     }
     if (isset($Product->id)) {
         $this->product = $Product->id;
     }
     if (isset($Price->id)) {
         $this->price = $Price->id;
     }
     $this->category = $category;
     $this->option = $Price;
     $this->name = $Product->name;
     $this->slug = $Product->slug;
     $this->description = $Product->summary;
     if (isset($Product->thumbnail)) {
         $this->thumbnail = $Product->thumbnail;
     }
     $this->menus = $Product->options;
     if ($Product->variations == "on") {
         $this->options = $Product->prices;
     }
     $this->sku = $Price->sku;
     $this->type = $Price->type;
     $this->sale = $Price->onsale;
     $this->freeshipping = $Price->freeshipping;
     $this->saved = $Price->price - $Price->promoprice;
     $this->savings = $Price->price > 0 ? percentage($this->saved / $Price->price) * 100 : 0;
     $this->unitprice = $Price->onsale ? $Price->promoprice : $Price->price;
     $this->optionlabel = count($Product->prices) > 1 ? $Price->label : '';
     $this->donation = $Price->donation;
     $this->data = stripslashes_deep(attribute_escape_deep($data));
     // Map out the selected menu name and option
     if ($Product->variations == "on") {
         $selected = explode(",", $this->option->options);
         $s = 0;
         foreach ($this->menus as $i => $menu) {
             foreach ($menu['options'] as $option) {
                 if ($option['id'] == $selected[$s]) {
                     $this->variation[$menu['name']] = $option['name'];
                     break;
                 }
             }
             $s++;
         }
     }
     if (!empty($Price->download)) {
         $this->download = $Price->download;
     }
     if ($Price->type == "Shipped") {
         $this->shipping = true;
         if ($Price->shipping == "on") {
             $this->weight = $Price->weight;
             $this->shipfee = $Price->shipfee;
         } else {
             $this->freeshipping = true;
         }
     }
     $this->inventory = $Price->inventory == "on" ? true : false;
     $this->taxable = $Price->tax == "on" && $Shopp->Settings->get('taxes') == "on" ? true : false;
 }