init(self::$table); if (!$id) return true; if ($this->load($id,$key)) return true; else return false; } function load_purchased () { $db = DB::get(); $table = DatabaseObject::tablename(Purchased::$table); if (empty($this->id)) return false; $this->purchased = $db->query("SELECT * FROM $table WHERE purchase=$this->id",AS_ARRAY); foreach ($this->purchased as &$purchase) $purchase->data = unserialize($purchase->data); return true; } function notification ($addressee,$address,$subject,$template="order.html",$receipt="receipt.php") { global $Shopp; global $is_IIS; $template = trailingslashit(SHOPP_TEMPLATES).$template; if (!file_exists($template)) return new ShoppError(__('A purchase notification could not be sent because the template for it does not exist.','purchase_notification_template',SHOPP_ADMIN_ERR)); // // Send the e-mail receipt $email = array(); $email['from'] = '"'.get_bloginfo("name").'"'; if ($Shopp->Settings->get('merchant_email')) $email['from'] .= ' <'.$Shopp->Settings->get('merchant_email').'>'; if($is_IIS) $email['to'] = $address; else $email['to'] = '"'.html_entity_decode($addressee,ENT_QUOTES).'" <'.$address.'>'; $email['subject'] = $subject; $email['receipt'] = $Shopp->Flow->order_receipt($receipt); $email['url'] = get_bloginfo('siteurl'); $email['sitename'] = get_bloginfo('name'); $email['orderid'] = $this->id; $email = apply_filters('shopp_email_receipt_data',$email); if (shopp_email($template,$email)) { if (SHOPP_DEBUG) new ShoppError('A purchase notification was sent to "'.$addressee.'" <'.$address.'>',false,SHOPP_DEBUG_ERR); return true; } if (SHOPP_DEBUG) new ShoppError('A purchase notification FAILED to be sent to "'.$addressee.'" <'.$address.'>',false,SHOPP_DEBUG_ERR); return false; } function copydata ($Object,$prefix="") { $ignores = array("_datatypes","_table","_key","_lists","id","created","modified"); foreach(get_object_vars($Object) as $property => $value) { $property = $prefix.$property; if (property_exists($this,$property) && !in_array($property,$ignores)) $this->{$property} = $value; } } function exportcolumns () { $prefix = "o."; return array( $prefix.'id' => __('Order ID','Shopp'), $prefix.'ip' => __('Customer\'s IP Address','Shopp'), $prefix.'firstname' => __('Customer\'s First Name','Shopp'), $prefix.'lastname' => __('Customer\'s Last Name','Shopp'), $prefix.'email' => __('Customer\'s Email Address','Shopp'), $prefix.'phone' => __('Customer\'s Phone Number','Shopp'), $prefix.'company' => __('Customer\'s Company','Shopp'), $prefix.'card' => __('Credit Card Number','Shopp'), $prefix.'cardtype' => __('Credit Card Type','Shopp'), $prefix.'cardexpires' => __('Credit Card Expiration Date','Shopp'), $prefix.'cardholder' => __('Credit Card Holder\'s Name','Shopp'), $prefix.'address' => __('Billing Street Address','Shopp'), $prefix.'xaddress' => __('Billing Street Address 2','Shopp'), $prefix.'city' => __('Billing City','Shopp'), $prefix.'state' => __('Billing State/Province','Shopp'), $prefix.'country' => __('Billing Country','Shopp'), $prefix.'postcode' => __('Billing Postal Code','Shopp'), $prefix.'shipaddress' => __('Shipping Street Address','Shopp'), $prefix.'shipxaddress' => __('Shipping Street Address 2','Shopp'), $prefix.'shipcity' => __('Shipping City','Shopp'), $prefix.'shipstate' => __('Shipping State/Province','Shopp'), $prefix.'shipcountry' => __('Shipping Country','Shopp'), $prefix.'shippostcode' => __('Shipping Postal Code','Shopp'), $prefix.'shipmethod' => __('Shipping Method','Shopp'), $prefix.'promos' => __('Promotions Applied','Shopp'), $prefix.'subtotal' => __('Order Subtotal','Shopp'), $prefix.'discount' => __('Order Discount','Shopp'), $prefix.'freight' => __('Order Shipping Fees','Shopp'), $prefix.'tax' => __('Order Taxes','Shopp'), $prefix.'total' => __('Order Total','Shopp'), $prefix.'fees' => __('Transaction Fees','Shopp'), $prefix.'transactionid' => __('Transaction ID','Shopp'), $prefix.'transtatus' => __('Transaction Status','Shopp'), $prefix.'gateway' => __('Payment Gateway','Shopp'), $prefix.'status' => __('Order Status','Shopp'), $prefix.'data' => __('Order Data','Shopp'), $prefix.'created' => __('Order Date','Shopp'), $prefix.'modified' => __('Order Last Updated','Shopp') ); } function tag ($property,$options=array()) { global $Shopp; if ($property == "item-unitprice" || $property == "item-total") $taxrate = shopp_taxrate($options['taxes']); // Return strings with no options switch ($property) { case "url": return $Shopp->link('cart'); break; case "id": return $this->id; break; case "date": if (empty($options['format'])) $options['format'] = get_option('date_format'); return _d($options['format'],((is_int($this->created))?$this->created:mktimestamp($this->created))); break; case "card": return (!empty($this->card))?sprintf("%'X16d",$this->card):''; break; case "cardtype": return $this->cardtype; break; case "transactionid": return $this->transactionid; break; case "firstname": return $this->firstname; break; case "lastname": return $this->lastname; break; case "company": return $this->company; break; case "email": return $this->email; break; case "phone": return $this->phone; break; case "address": return $this->address; break; case "xaddress": return $this->xaddress; break; case "city": return $this->city; break; case "state": if (strlen($this->state > 2)) return $this->state; $regions = $Shopp->Settings->get('zones'); $states = $regions[$this->country]; return $states[$this->state]; break; case "postcode": return $this->postcode; break; case "country": $countries = $Shopp->Settings->get('target_markets'); return $countries[$this->country]; break; case "shipaddress": return $this->shipaddress; break; case "shipxaddress": return $this->shipxaddress; break; case "shipcity": return $this->shipcity; break; case "shipstate": if (strlen($this->shipstate > 2)) return $this->shipstate; $regions = $Shopp->Settings->get('zones'); $states = $regions[$this->country]; return $states[$this->shipstate]; break; case "shippostcode": return $this->shippostcode; break; case "shipcountry": $countries = $Shopp->Settings->get('target_markets'); return $countries[$this->shipcountry]; break; case "shipmethod": return $this->shipmethod; break; case "totalitems": return count($this->purchased); break; case "hasitems": if (count($this->purchased) > 0) return true; else return false; break; case "items": if (!$this->looping) { reset($this->purchased); $this->looping = true; } else next($this->purchased); if (current($this->purchased)) return true; else { $this->looping = false; reset($this->purchased); return false; } case "item-id": $item = current($this->purchased); return $item->id; break; case "item-product": $item = current($this->purchased); return $item->product; break; case "item-price": $item = current($this->purchased); return $item->price; break; case "item-name": $item = current($this->purchased); return $item->name; break; case "item-description": $item = current($this->purchased); return $item->description; break; case "item-options": $item = current($this->purchased); return (!empty($item->optionlabel))?$options['before'].$item->optionlabel.$options['after']:''; break; case "item-sku": $item = current($this->purchased); return $item->sku; break; case "item-download": $item = current($this->purchased); if (empty($item->download)) return ""; if (!isset($options['label'])) $options['label'] = __('Download','Shopp'); $classes = ""; if (isset($options['class'])) $classes = ' class="'.$options['class'].'"'; if (SHOPP_PERMALINKS) $url = $Shopp->shopuri."download/".$item->dkey; else $url = add_query_arg('shopp_download',$item->dkey,$Shopp->link('account')); return ''.$options['label'].''; break; case "item-quantity": $item = current($this->purchased); return $item->quantity; break; case "item-unitprice": $item = current($this->purchased); return money($item->unitprice+($item->unitprice*$taxrate)); break; case "item-total": $item = current($this->purchased); return money($item->total+($item->total*$taxrate)); break; case "item-has-inputs": case "item-hasinputs": $item = current($this->purchased); return (count($item->data) > 0); break; case "item-inputs": $item = current($this->purchased); if (!$this->itemdataloop) { reset($item->data); $this->itemdataloop = true; } else next($item->data); if (current($item->data)) return true; else { $this->itemdataloop = false; return false; } break; case "item-input": $item = current($this->purchased); $data = current($item->data); $name = key($item->data); if (isset($options['name'])) return $name; return $data; break; case "item-inputs-list": case "item-inputslist": case "item-inputs-list": case "iteminputslist": $item = current($this->purchased); if (empty($item->data)) return false; $before = ""; $after = ""; $classes = ""; $excludes = array(); if (!empty($options['class'])) $classes = ' class="'.$options['class'].'"'; if (!empty($options['exclude'])) $excludes = explode(",",$options['exclude']); if (!empty($options['before'])) $before = $options['before']; if (!empty($options['after'])) $after = $options['after']; $result .= $before.'