本文整理汇总了PHP中waContact::getFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP waContact::getFirst方法的具体用法?PHP waContact::getFirst怎么用?PHP waContact::getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waContact
的用法示例。
在下文中一共展示了waContact::getFirst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createOrder
//.........这里部分代码省略.........
$order['params']['payment_params_' . $k] = $v;
}
unset($order['params']['payment']);
}
}
if ($skock_id = waRequest::post('stock_id')) {
$order['params']['stock_id'] = $skock_id;
}
$routing_url = wa()->getRouting()->getRootUrl();
$order['params']['storefront'] = wa()->getConfig()->getDomain() . ($routing_url ? '/' . $routing_url : '');
if ($ref = waRequest::cookie('referer')) {
$order['params']['referer'] = $ref;
$ref_parts = @parse_url($ref);
$order['params']['referer_host'] = $ref_parts['host'];
// try get search keywords
if (!empty($ref_parts['query'])) {
$search_engines = array('text' => 'yandex\\.|rambler\\.', 'q' => 'bing\\.com|mail\\.|google\\.', 's' => 'nigma\\.ru', 'p' => 'yahoo\\.com');
$q_var = false;
foreach ($search_engines as $q => $pattern) {
if (preg_match('/(' . $pattern . ')/si', $ref_parts['host'])) {
$q_var = $q;
break;
}
}
// default query var name
if (!$q_var) {
$q_var = 'q';
}
parse_str($ref_parts['query'], $query);
if (!empty($query[$q_var])) {
$order['params']['keyword'] = $query[$q_var];
}
}
}
if ($utm = waRequest::cookie('utm')) {
$utm = json_decode($utm, true);
if ($utm && is_array($utm)) {
foreach ($utm as $k => $v) {
$order['params']['utm_' . $k] = $v;
}
}
}
if (($landing = waRequest::cookie('landing')) && ($landing = @parse_url($landing))) {
if (!empty($landing['query'])) {
@parse_str($landing['query'], $arr);
if (!empty($arr['gclid']) && !empty($order['params']['referer_host']) && strpos($order['params']['referer_host'], 'google') !== false) {
$order['params']['referer_host'] .= ' (cpc)';
$order['params']['cpc'] = 1;
} else {
if (!empty($arr['_openstat']) && !empty($order['params']['referer_host']) && strpos($order['params']['referer_host'], 'yandex') !== false) {
$order['params']['referer_host'] .= ' (cpc)';
$order['params']['openstat'] = $arr['_openstat'];
$order['params']['cpc'] = 1;
}
}
}
$order['params']['landing'] = $landing['path'];
}
// A/B tests
/*
$abtest_variants_model = new shopAbtestVariantsModel();
foreach (waRequest::cookie() as $k => $v) {
if (substr($k, 0, 5) == 'waabt') {
$variant_id = $v;
$abtest_id = substr($k, 5);
if (wa_is_int($abtest_id) && wa_is_int($variant_id)) {
$row = $abtest_variants_model->getById($variant_id);
if ($row && $row['abtest_id'] == $abtest_id) {
$order['params']['abt' . $abtest_id] = $variant_id;
}
}
}
}
*/
$order['params']['ip'] = waRequest::getIp();
$order['params']['user_agent'] = waRequest::getUserAgent();
foreach (array('shipping', 'billing') as $ext) {
$address = $contact->getFirst('address.' . $ext);
if ($address) {
foreach ($address['data'] as $k => $v) {
$order['params'][$ext . '_address.' . $k] = $v;
}
}
}
if (isset($checkout_data['comment'])) {
$order['comment'] = $checkout_data['comment'];
}
$workflow = new shopWorkflow();
if ($order_id = $workflow->getActionById('create')->run($order)) {
$step_number = shopOnestepCheckout::getStepNumber();
$checkout_flow = new shopCheckoutFlowModel();
$checkout_flow->add(array('step' => $step_number));
$cart->clear();
wa()->getStorage()->remove('shop/checkout');
wa()->getStorage()->set('shop/order_id', $order_id);
return $order_id;
} else {
return false;
}
}
示例2: execute
public function execute($data = null)
{
$order_model = new shopOrderModel();
$order = $order_model->getById($data['id']);
$subtotal = 0;
$services = $products = array();
foreach ($data['items'] as $item) {
if ($item['service_id']) {
$services[] = $item['service_id'];
} else {
$products[] = $item['product_id'];
}
}
$service_model = new shopServiceModel();
$product_model = new shopProductModel();
$services = $service_model->getById($services);
$products = $product_model->getById($products);
foreach ($data['items'] as &$item) {
$item['currency'] = $order['currency'];
$item['price'] = $this->price($item['price']);
if ($item['service_id']) {
$item['service'] = $services[$item['service_id']];
} else {
$item['product'] = $products[$item['product_id']];
}
$subtotal += $item['price'] * $item['quantity'];
}
unset($item);
foreach (array('shipping', 'discount') as $k) {
if (!isset($data[$k])) {
$data[$k] = 0;
}
}
$contact = new waContact($order['contact_id']);
$shipping_address = $contact->getFirst('address.shipping');
if (!$shipping_address) {
$shipping_address = $contact->getFirst('address');
}
$shipping_address = $shipping_address ? $shipping_address['data'] : array();
$billing_address = $contact->getFirst('address.billing');
if (!$billing_address) {
$billing_address = $contact->getFirst('address');
}
$billing_address = $billing_address ? $billing_address['data'] : array();
$discount_rate = $subtotal ? $data['discount'] / $subtotal : 0;
$taxes = shopTaxes::apply($data['items'], array('shipping' => $shipping_address, 'billing' => $billing_address, 'discount_rate' => $discount_rate), $order['currency']);
$tax = $tax_included = 0;
foreach ($taxes as $t) {
if (isset($t['sum'])) {
$tax += $t['sum'];
}
if (isset($t['sum_included'])) {
$tax_included += $t['sum_included'];
}
}
$data['tax'] = $tax_included + $tax;
$data['total'] = $subtotal + $tax + $this->price($data['shipping']) - $this->price($data['discount']);
// for logging changes in stocks
shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was edited', array('order_id' => $data['id']));
// update
$order_model->update($data, $data['id']);
$log_model = new waLogModel();
$log_model->add('order_edit', $data['id']);
shopProductStocksLogModel::clearContext();
if (!empty($data['params'])) {
$params_model = new shopOrderParamsModel();
$params_model->set($data['id'], $data['params'], false);
}
return true;
}
示例3: getCustomerForm
/**
* Returns instance of class waContactForm.
*
* @param int|waContact|null $id Optional id of contact or contact object whose data must be pre-filled in contact form.
* @param bool $ensure_address Whether address fields must be included regardless of store's contact fields settings.
* @return waContactForm
*/
public static function getCustomerForm($id = null, $ensure_address = false)
{
$settings = wa('shop')->getConfig()->getCheckoutSettings();
if (!isset($settings['contactinfo'])) {
$settings = wa('shop')->getConfig()->getCheckoutSettings(true);
}
$fields_config = ifset($settings['contactinfo']['fields'], array());
$address_config = ifset($fields_config['address'], array());
unset($fields_config['address']);
if (wa()->getEnv() == 'backend') {
// new order
if (!isset($fields_config['address.shipping']) || !$id) {
$fields_config['address.shipping'] = array();
} elseif (!empty($fields_config['address.shipping']) && $id && $id instanceof waContact) {
$address = $id->getFirst('address.shipping');
if ($address && !empty($address['data'])) {
foreach ($address['data'] as $subfield => $v) {
if (!isset($fields_config['address.shipping']['fields'][$subfield])) {
$fields_config['address.shipping']['fields'][$subfield] = array();
}
}
}
}
}
if ($ensure_address && !isset($fields_config['address.billing']) && !isset($fields_config['address.shipping'])) {
$fields_config['address'] = $address_config;
}
$form = waContactForm::loadConfig($fields_config, array('namespace' => 'customer'));
if ($id) {
if (is_numeric($id)) {
$contact = new waContact($id);
$contact->getName();
// make sure contact exists; throws exception otherwise
} elseif ($id instanceof waContact) {
$contact = $id;
}
if (isset($contact)) {
$form->setValue($contact);
}
}
return $form;
}