本文整理汇总了PHP中ShopFunctions::convertWeigthUnit方法的典型用法代码示例。如果您正苦于以下问题:PHP ShopFunctions::convertWeigthUnit方法的具体用法?PHP ShopFunctions::convertWeigthUnit怎么用?PHP ShopFunctions::convertWeigthUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShopFunctions
的用法示例。
在下文中一共展示了ShopFunctions::convertWeigthUnit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOrderWeight
/**
* Get the total weight for the order, based on which the proper shipping rate
* can be selected.
*
* @param object $cart Cart object
* @return float Total weight for the order
* @author Oscar van Eijk
*/
protected function getOrderWeight(VirtueMartCart $cart, $to_weight_unit)
{
static $weight = 0.0;
if (count($cart->products) > 0 and empty($weight)) {
foreach ($cart->products as $product) {
$weight += ShopFunctions::convertWeigthUnit($product->product_weight, $product->product_weight_uom, $to_weight_unit) * $product->quantity;
}
}
return $weight;
}
示例2: _generateProductsData
/**
* Generates products data to PagSeguro transaction
* @param VirtueMartCart $cart
* @return array
*/
private function _generateProductsData(VirtueMartCart $cart)
{
$pagSeguroItems = array();
$cont = 1;
foreach ($cart->products as $key => $product) {
$pagSeguroItem = new PagSeguroItem();
$pagSeguroItem->setId($cont++);
$pagSeguroItem->setDescription($product->product_name);
$pagSeguroItem->setQuantity($product->quantity);
$pagSeguroItem->setAmount(number_format($this->calculePrice($cart, $key), 2));
$pagSeguroItem->setWeight((int) ShopFunctions::convertWeigthUnit($product->product_weight, $product->product_weight_uom, 'G'));
// defines weight in gramas
array_push($pagSeguroItems, $pagSeguroItem);
}
return $pagSeguroItems;
}
示例3: _getPreco_site_correios
function _getPreco_site_correios($cart, $method, $cart_prices)
{
//Define medidas e formato da embalagem
//Usei os valores mínimos (16x11x2 Cm) para todas as medidas a seguir:
//Comprimento médio dos pacotes utilizados para envio pelos Correios(Cm)
$this->Order_Length = $method->Comprimento_SN;
//Largura/Diâmetro médio dos pacotes utilizados para envio pelos Correios(Cm)
$this->Order_Width = $method->Larg_Diam_SN;
//Altura média dos pacotes utilizados para envio pelos Correios(Cm)
$this->Order_Height = $method->Altura_SN;
//Tipo de embrulho dos Correios
$this->Order_Formatos = $method->Formatos_SN;
//Taxa de empacotamento e manuseio, e será acrescida aos custos de envio retornados pelos Correios
$this->Order_Handling_Fee = $method->Handling_Fee_SN;
$this->Order_Handling_Fee = floatval(str_replace(",", ".", $this->Order_Handling_Fee));
//Serviço Mão Própria dos Correios
$this->Order_MaoPropria = $method->MaoPropria_SN;
//Aviso de Recebimento dos Correios
$this->Order_Aviso = $method->AvisoReceb_SN ? "S" : "N";
$this->correios_total = 0;
$this->correios_prazo = 0;
if ($method->FreteProduto_SN == 1) {
$product_length = 0;
$product_width = 0;
$product_height = 0;
foreach ($cart->products as $k => $product) {
// converte pra centímetros
if ($product->product_lwh_uom != 'CM') {
$product_length = ShopFunctions::convertDimensionUnit($product->product_length, $product->product_lwh_uom, "CM");
$product_width = ShopFunctions::convertDimensionUnit($product->product_width, $product->product_lwh_uom, "CM");
$product_height = ShopFunctions::convertDimensionUnit($product->product_height, $product->product_lwh_uom, "CM");
} else {
$product_height = $product->product_height;
$product_width = $product->product_width;
$product_length = $product->product_length;
}
if ($product_length < 16) {
$product_length = "16";
}
if ($product_width < 11) {
$product_width = "11";
}
if ($product_height < 2) {
$product_height = "2";
}
$this->Order_Length = round($product_length, 2);
$this->Order_Width = round($product_width, 2);
// $this->Order_Height = round($product_height * $product->quantity,2);
$this->Order_Height = round($product_height, 2);
// converte para kilos
$product_weight = ShopFunctions::convertWeigthUnit($product->product_weight, $product->product_weight_uom, "KG");
// $peso = $product_weight * $product->quantity;
$peso = $product_weight;
//$total_preco = $product->product_price * $product->quantity;
$total_preco = $product->product_price;
// sempre pega o maior prazo
$dados_frete = $this->_parametrosCorreios($total_preco, $method, $peso);
// pra cada produto, faz a soma de cada produto em separado
$dados_frete['valor'] = str_replace(",", ".", $dados_frete['valor']);
$this->correios_total = $dados_frete['valor'] * $product->quantity;
//$this->correios_total = $dados_frete['valor'];
// for ($i=0; $i < $product->quantity; $i++) {
// $this->correios_total += $dados_frete['valor'];
// }
if ($this->correios_prazo < $dados_frete['prazo']) {
$this->correios_prazo = $dados_frete['prazo'];
}
}
} else {
// calcular o volume total do pedido ( um cálculo por pedido )
foreach ($cart->products as $k => $product) {
//Define medidas minimas
// converte pra centímetros
$this->Order_Height = 0;
if (strtoupper($product->product_lwh_uom) != 'CM') {
$product_length = ShopFunctions::convertDimensionUnit($product->product_length, $product->product_lwh_uom, "CM");
$product_width = ShopFunctions::convertDimensionUnit($product->product_width, $product->product_lwh_uom, "CM");
$product_height = ShopFunctions::convertDimensionUnit($product->product_height, $product->product_lwh_uom, "CM");
} else {
$product_height = $product->product_height;
$product_width = $product->product_width;
$product_length = $product->product_length;
}
if ($method->debug) {
vmdebug('<b>Dimension Unit - ' . $product->virtuemart_product_id . '</b>:', $product->product_lwh_uom);
vmdebug('<b>Height - ' . $product->virtuemart_product_id . '</b>:', $product_height);
vmdebug('<b>Width - ' . $product->virtuemart_product_id . '</b>:', $product_width);
vmdebug('<b>Length - ' . $product->virtuemart_product_id . '</b>:', $product_length);
}
if ($method->VolumeProduto_SN == '1') {
$product_height = round($product_height * $product->quantity, 2);
if ($product_height > $this->Order_Height) {
$this->Order_Height += $product_height;
}
if ($product_width > $this->Order_Width) {
$this->Order_Width = $product_width;
}
if ($product_length > $this->Order_Length) {
$this->Order_Length = $product_length;
}
//.........这里部分代码省略.........
示例4: getUPSresponse
public function getUPSresponse($cart, $method)
{
$vendorId = $this->vendor;
$vendorModel = VmModel::getModel('vendor');
$vendorFields = $vendorModel->getVendorAddressFields();
$weight = 0;
foreach ($cart->products as $product) {
(double) ($product_weight = ShopFunctions::convertWeigthUnit($product->product_weight, $product->product_weight_uom, "LB"));
$weight += $product_weight * $product->quantity;
}
if ($weight == 0) {
JFactory::getApplication()->enqueueMessage("UPS Error: Product Weight not found", "error");
$this->clear();
$mainframe = JFactory::getApplication();
$redirectMsg = "UPS Error: Product Weight not found";
$mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT'), $redirectMsg);
return FALSE;
}
$accessNumber = trim($method->api);
$username = trim($method->username);
$password = trim($method->password);
$upsConnect = new ups($accessNumber, $username, $password);
$upsConnect->setTemplatePath(JPATH_ROOT . '/plugins/vmshipment/jibon_ups/ups/xml/');
$upsConnect->setTestingMode($method->mood);
// Change this to 0 for production
$upsRate = new upsRate($upsConnect);
$upsRate->request(array('Shop' => true));
$upsRate->shipper(array('name' => $vendorFields['fields']['first_name']['value'] . " " . $vendorFields['fields']['last_name']['value'], 'phone' => $vendorFields['fields']['phone_1']['value'], 'shipperNumber' => '', 'address1' => $vendorFields['fields']['address_1']['value'], 'address2' => '', 'address3' => '', 'city' => $vendorFields['fields']['city']['value'], 'state' => $vendorFields['fields']['virtuemart_state_id']['state_2_code'], 'postalCode' => $vendorFields['fields']['zip']['value'], 'country' => $vendorFields['fields']['virtuemart_country_id']['country_2_code']));
if (!is_array($cart->BT)) {
JFactory::getApplication()->enqueueMessage("UPS Error: Please put valid shipping information !!", "error");
return false;
}
if (is_array($cart->ST)) {
$upsRate->shipTo(array('companyName' => $cart->ST['company'], 'attentionName' => $cart->ST['first_name'] . " " . $cart->ST['last_name'], 'phone' => $cart->ST['phone_1'], 'address1' => $cart->ST['address_1'], 'address2' => '', 'address3' => '', 'city' => $cart->ST['city'], 'state' => ShopFunctions::getStateByID($cart->ST['virtuemart_state_id'], "state_2_code"), 'postalCode' => $cart->ST['zip'], 'countryCode' => ShopFunctions::getCountryByID($cart->ST['virtuemart_country_id'], "country_2_code")));
} else {
$upsRate->shipTo(array('companyName' => $cart->BT['company'], 'attentionName' => $cart->BT['first_name'] . " " . $cart->BT['last_name'], 'phone' => $cart->BT['phone_1'], 'address1' => $cart->BT['address_1'], 'address2' => '', 'address3' => '', 'city' => $cart->BT['city'], 'state' => ShopFunctions::getStateByID($cart->BT['virtuemart_state_id'], "state_2_code"), 'postalCode' => $cart->BT['zip'], 'countryCode' => ShopFunctions::getCountryByID($cart->BT['virtuemart_country_id'], "country_2_code")));
}
$upsRate->package(array('description' => 'my description', 'weight' => $weight, 'code' => '02', 'length' => 0, 'width' => 0, 'height' => 0));
$upsRate->shipment(array('description' => 'my description', 'serviceType' => '03'));
//service type
$upsRate->sendRateRequest();
$this->UPSresponse = $upsRate->returnResponseArray();
if (!empty($this->UPSresponse["RatingServiceSelectionResponse"]["Response"]["Error"]["ErrorCode"]) or empty($this->UPSresponse)) {
$this->ups_rate = "";
$this->ups_service_name = "";
$this->ups_service_id = "";
$this->status = 0;
$this->loadPost($method->virtuemart_shipmentmethod_id);
JFactory::getApplication()->enqueueMessage("UPS Error: " . $this->UPSresponse["RatingServiceSelectionResponse"]["Response"]["Error"]["ErrorDescription"]["VALUE"], "error");
}
$currency = CurrencyDisplay::getInstance();
if ($this->UPSresponse['RatingServiceSelectionResponse']['RatedShipment']) {
foreach ($this->UPSresponse['RatingServiceSelectionResponse']['RatedShipment'] as $rate) {
if ($this->ups_service_id === $rate["Service"]["Code"]["VALUE"]) {
$this->ups_rate = $currency->convertCurrencyTo("USD", $rate["TotalCharges"]["MonetaryValue"]["VALUE"]);
$this->ups_service_name = $this->getServiceName($rate["Service"]["Code"]["VALUE"]);
$this->ups_service_id = $rate["Service"]["Code"]["VALUE"];
$this->save();
break;
}
}
}
return $this->UPSresponse;
}
示例5: getOrderWeight
/**
* Get the total weight for the order, based on which the proper shipping rate
* can be selected.
*
* @param object $cart Cart object
* @return float Total weight for the order
* @author Oscar van Eijk
*/
protected function getOrderWeight(VirtueMartCart $cart, $to_weight_unit)
{
$weight = 0;
foreach ($cart->products as $product) {
$weight += ShopFunctions::convertWeigthUnit($product->product_weight, $product->product_weight_uom, $to_weight_unit) * $product->quantity;
}
return $weight;
}
示例6: array
$cat->setId($categoryId);
$categoryDetails = $cat->getCategory();
$parents = $categoryDetails->parents;
$CATEGORIES_ARR = array();
while (count($parents) > 0) {
$CATEGORIES_ARR[] = array_shift($parents)->category_name;
}
$categoryName = join(" > ", $CATEGORIES_ARR);
// Currency
$currency->setId($productItem->product_currency);
$prod_currency = $currency->getCurrency();
if ($on_stock_only == "on" && $productItem->product_in_stock > 0 || (VmConfig::get('check_stock') && $productItem->product_in_stock > 0 || VmConfig::get('show_out_of_stock_products') && ($productItem->product_in_stock = 0) || !VmConfig::get('check_stock'))) {
$shippingPrice = null;
if ($hasShipping && is_array($availableShippingMethods) && sizeof($availableShippingMethods) > 0) {
foreach ($availableShippingMethods as $shipping) {
$normalizedWeight = ShopFunctions::convertWeigthUnit($productItem->product_weight, $productItem->product_weight_uom, $shipping->weight_unit);
$weight_check = $normalizedWeight >= $shipping->weight_start && $normalizedWeight <= $shipping->weight_stop || $shipping->weight_start == '' && $normalizedWeight <= $shipping->weight_stop || $shipping->weight_stop == '' && $normalizedWeight >= $shipping->weight_start || $shipping->weight_start == '' && $shipping->weight_stop == '';
$price_check = $productItem->prices['salesPrice'] >= $shipping->orderamount_start && $productItem->prices['salesPrice'] <= $shipping->orderamount_stop || $shipping->orderamount_start == '' && $productItem->prices['salesPrice'] <= $shipping->orderamount_stop || $productItem->prices['salesPrice'] >= $shipping->orderamount_start && $shipping->orderamount_stop == '' || $shipping->orderamount_start == '' && $shipping->orderamount_stop == '';
$num_check = $shipping->nbproducts_start <= 1 && $shipping->nbproducts_stop >= 1 || $shipping->nbproducts_start <= 1 && $shipping->nbproducts_stop == '' || $shipping->nbproducts_start == '' && $shipping->nbproducts_stop >= 1 || $shipping->nbproducts_start == '' && $shipping->nbproducts_stop == '';
if ($weight_check && $price_check && $num_check) {
if ($shipping->free_shipment <= $productItem->prices['salesPrice'] && is_numeric($shipping->free_shipment)) {
$shippingPrice = "0";
break;
} elseif ($shipping->price > 0) {
if (isset($shipping->tax_data->calc_value_mathop)) {
switch ($shipping->tax_data->calc_value_mathop) {
case "+":
$shippingPriceWithVAT = $shipping->price + $shipping->tax_data->calc_value;
break;
case "-":
$shippingPriceWithVAT = $shipping->price - $shipping->tax_data->calc_value;