Post by nyltak » Sat Jul 30, 2011 3:02 am

ver. 1.5

shouldn't the dimensions that are sent to UPS for rate information be the sum of the dimensions set for each product? Instead of guessing at the product dimension and putting it in the UPS module beforehand?

I would prefer to figure the shipping individually, since I sell furniture, and it only takes a couple products to max out the allowed box size. (even though in reality items are shipped seperately)

I noticed Q has a mod for ver.1.4 are there any solutions for 1.5?
Last edited by nyltak on Sat Jul 30, 2011 2:15 pm, edited 1 time in total.

New member

Posts

Joined
Wed Jul 20, 2011 9:56 am

Post by nyltak » Sat Jul 30, 2011 8:56 am

I don't suppose someone would be so kind as to give me the file map for the shipping process?

I think I could mod most of what I need to get my site the way I want it, except for the small problem of not being able to trace what file is at the top and which is at the bottom.

Could someone tell me the specific file that interacts with the UPS.com database?

New member

Posts

Joined
Wed Jul 20, 2011 9:56 am

Post by nyltak » Sat Jul 30, 2011 11:02 am

so... I have catalog>model>shipping>ups.php. I need to alter the xml to add each product weight, instead of the sum of the weights.

for each product this code needs to be duplicated into ups.php somehow with $weight equaling the series of weights. But how do I do that... can someone tell me how to get the weights as an array, instead of the sum?

Code: Select all

$xml .= '		<Package>';
			$xml .= '			<PackagingType>';
			$xml .= '				<Code>' . $this-

>config->get('ups_packaging') . '</Code>';
			$xml .= '			</PackagingType>';

			$xml .= '		    <Dimensions>';
    		$xml .= '				<UnitOfMeasurement>';
    		$xml .= '					<Code>' . $this-

>config->get('ups_length_code') . '</Code>';
    		$xml .= '				</UnitOfMeasurement>';
    		$xml .= '				<Length>' . $length . 

'</Length>';
    		$xml .= '				<Width>' . $width . 

'</Width>';
    		$xml .= '				<Height>' . $height . 

'</Height>';
    		$xml .= '			</Dimensions>';
			
			$xml .= '			<PackageWeight>';
			$xml .= '				

<UnitOfMeasurement>';
			$xml .= '					

<Code>' . $this->config->get('ups_weight_code') . '</Code>';
			$xml .= '				

</UnitOfMeasurement>';
			$xml .= '				

<Weight>'.$weight.'</Weight>';
			$xml .= '			</PackageWeight>';
			
			if ($this->config->get('ups_insurance')) {
				$xml .= '           <PackageServiceOptions>';
				$xml .= '               <InsuredValue>';
				$xml .= '                   <CurrencyCode>' . $this-

>currency->getCode() . '</CurrencyCode>';
				$xml .= '                   <MonetaryValue>' . $this-

>currency->format($this->cart->getTotal(), false, false, false) . '</MonetaryValue>';
				$xml .= '               </InsuredValue>';
				$xml .= '           </PackageServiceOptions>';
			}
			
			$xml .= '		</Package>';

New member

Posts

Joined
Wed Jul 20, 2011 9:56 am

Post by bitsmobile » Thu Aug 02, 2012 10:27 am

Custom Array Via System/Library/Cart.php

<?php
final class Cart {
public function __construct($registry) {
$this->config = $registry->get('config');
$this->customer = $registry->get('customer');
$this->session = $registry->get('session');
$this->db = $registry->get('db');
$this->tax = $registry->get('tax');
$this->weight = $registry->get('weight');

if (!isset($this->session->data['cart']) || !is_array($this->session->data['cart'])) {
$this->session->data['cart'] = array();
}
}

public function getProducts() {
$product_data = array();

foreach ($this->session->data['cart'] as $key => $value) {
$array = explode(':', $key);
$product_id = $array[0];
$quantity = $value;
$stock = TRUE;

if (isset($array[1])) {
$options = explode('.', $array[1]);
} else {
$options = array();
}

$product_query = $this->db->query("SELECT *, wcd.unit AS weight_class, mcd.unit AS length_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "weight_class wc ON (p.weight_class_id = wc.weight_class_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (wc.weight_class_id = wcd.weight_class_id) LEFT JOIN " . DB_PREFIX . "length_class mc ON (p.length_class_id = mc.length_class_id) LEFT JOIN " . DB_PREFIX . "length_class_description mcd ON (mc.length_class_id = mcd.length_class_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

if ($product_query->num_rows) {
$option_price = 0;
$left = 0;
$right = 0;

$option_data = array();

// Verify existing options are valid and that product in cart has options if they exist. Otherwise remove the product from cart
// Do not push this code into OC 1.5.x as the new global options is different.
$product_option_value_query = $this->db->query("SELECT product_option_value_id FROM " . DB_PREFIX . "product_option_value WHERE product_id = '". (int)$product_id ."'");
if ($product_option_value_query->num_rows) {
if (empty($options)) {
$this->remove($key); //remove product if it should have options but doesn't
} else {
$product_option_values = array();

foreach ($product_option_value_query->rows as $product_option_value) {
$product_option_values[] = $product_option_value['product_option_value_id'];
}

foreach ($options as $option) {
if (!in_array($option, $product_option_values)) {
$this->remove($key); //remove product if it has options but they are not current
break;
}
}
}
}

foreach ($options as $product_option_value_id) {

$option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "product_option_value_description povd ON (pov.product_option_value_id = povd.product_option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_id = '" . (int)$product_id . "' AND povd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY pov.sort_order");

if ($option_value_query->num_rows) {
$option_query = $this->db->query("SELECT pod.name FROM " . DB_PREFIX . "product_option po LEFT JOIN " . DB_PREFIX . "product_option_description pod ON (po.product_option_id = pod.product_option_id) WHERE po.product_option_id = '" . (int)$option_value_query->row['product_option_id'] . "' AND po.product_id = '" . (int)$product_id . "' AND pod.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY po.sort_order");

# do not include if option is 'None'
if ($option_value_query->row['name'] == 'None') continue;

if ($option_value_query->row['name'] == 'Whole Pizza') {
$option_price=$option_price+$option_value_query->row['price'];
}
else if ($option_value_query->row['name'] == 'Left Side') {
$left=$left+$option_value_query->row['price'];
}
else if ($option_value_query->row['name'] == 'Right Side') {
$right=$right+$option_value_query->row['price'];
}
else if ($option_value_query->row['prefix'] == '+') {
$option_price = $option_price + $option_value_query->row['price'];
} elseif ($option_value_query->row['prefix'] == '-') {
$option_price = $option_price - $option_value_query->row['price'];
}
$option_data[] = array(
'product_option_value_id' => $product_option_value_id,
'name' => $option_query->row['name'],
'value' => $option_value_query->row['name'],
'prefix' => $option_value_query->row['prefix'],
'price' => $option_value_query->row['price']
);

if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $quantity))) {
$stock = FALSE;
}
}
}

if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getCustomerGroupId();
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}

$discount_quantity = 0;
foreach ($this->session->data['cart'] as $k => $v) {
$array2 = explode(':', $k);
if ($array2[0] == $product_id) {
$discount_quantity += $v;
}
}

$product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");

if ($product_discount_query->num_rows) {
$price = $product_discount_query->row['price'];
} else {
$product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1");

if ($product_special_query->num_rows) {
$price = $product_special_query->row['price'];
} else {
$price = $product_query->row['price'];
}
}

$download_data = array();

$download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download p2d LEFT JOIN " . DB_PREFIX . "download d ON (p2d.download_id = d.download_id) LEFT JOIN " . DB_PREFIX . "download_description dd ON (d.download_id = dd.download_id) WHERE p2d.product_id = '" . (int)$product_id . "' AND dd.language_id = '" . (int)$this->config->get('config_language_id') . "'");

foreach ($download_query->rows as $download) {
$download_data[] = array(
'download_id' => $download['download_id'],
'name' => $download['name'],
'filename' => $download['filename'],
'mask' => $download['mask'],
'remaining' => $download['remaining']
);
}

if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $quantity)) {
$stock = FALSE;
}

$quantity = max($quantity, $product_query->row['minimum']);

if ($product_query->row['maximum'] != '0') {
$quantity = min($quantity, $product_query->row['maximum']);
}
if($left<$right)
$option_price=$option_price+$right;
else
$option_price=$option_price+$left;

$product_data[$key] = array(
'key' => $key,
'product_id' => $product_query->row['product_id'],
'name' => $product_query->row['name'],
'model' => $product_query->row['model'],
'shipping' => $product_query->row['shipping'],
'image' => $product_query->row['image'],
'option' => $option_data,
'download' => $download_data,
'quantity' => $quantity,
'minimum' => $product_query->row['minimum'],
'maximum' => $product_query->row['maximum'],
'subtract' => $product_query->row['subtract'],
'stock' => $stock,
'price' => ($price + $option_price),
'total' => ($price + $option_price) * $quantity,
'tax_class_id' => $product_query->row['tax_class_id'],
'weight' => $product_query->row['weight'],
'weight_class' => $product_query->row['weight_class'],
'length' => $product_query->row['length'],
'width' => $product_query->row['width'],
'height' => $product_query->row['height'],
'length_class' => $product_query->row['length_class']
);
} else {
$this->remove($key);
}
}

return $product_data;
}

public function add($product_id, $qty = 1, $options = array()) {
if (!$options) {
$key = $product_id;
} else {
$key = $product_id . ':' . implode('.', $options);
}

if ((int)$qty && ((int)$qty > 0)) {
if (!isset($this->session->data['cart'][$key])) {
$this->session->data['cart'][$key] = (int)$qty;
} else {
$this->session->data['cart'][$key] += (int)$qty;
}
}
}

public function update($key, $qty) {
if ((int)$qty && ((int)$qty > 0)) {
$this->session->data['cart'][$key] = (int)$qty;
} else {
$this->remove($key);
}
}

public function remove($key) {
if (isset($this->session->data['cart'][$key])) {
unset($this->session->data['cart'][$key]);
}
}

public function clear() {
$this->session->data['cart'] = array();
}

public function getWeight() {
$weight = 0;$x=array();
$x[0]=7;$x[1]=2.5;$x[2]=2.5;$x[3]=2.5;

$z=0;
foreach ($this->getProducts() as $product) {
$z=$z+$product['quantity'];
}
for($weigh=0,$j=1,$k=0; $j<=$z;$j++)
{
$weigh=$weigh+$x[$k];
$k=($k+1)%4;
}

$weight = $this->weight->convert($weigh, $product['weight_class'], $this->config->get('config_weight_class'));



return $weight;
}


public function getSubTotal() {
$total = 0;

foreach ($this->getProducts() as $product) {
$total += $product['total'];
}

return $total;
}

public function getTaxes() {
$taxes = array();

foreach ($this->getProducts() as $product) {
if ($product['tax_class_id']) {
if (!isset($taxes[$product['tax_class_id']])) {
$taxes[$product['tax_class_id']] = $product['total'] / 100 * $this->tax->getRate($product['tax_class_id']);
} else {
$taxes[$product['tax_class_id']] += $product['total'] / 100 * $this->tax->getRate($product['tax_class_id']);
}
}
}

return $taxes;
}

public function getTotal() {
$total = 0;

foreach ($this->getProducts() as $product) {
$total += $this->tax->calculate($product['total'], $product['tax_class_id'], $this->config->get('config_tax'));
}

return $total;
}

public function countProducts() {
return array_sum($this->session->data['cart']);
}

public function hasProducts() {
return count($this->session->data['cart']);
}

public function hasStock() {
$stock = TRUE;

foreach ($this->getProducts() as $product) {
if (!$product['stock']) {
$stock = FALSE;
}
}

return $stock;
}

public function hasShipping() {
$shipping = FALSE;

foreach ($this->getProducts() as $product) {
if ($product['shipping']) {
$shipping = TRUE;

break;
}
}

return $shipping;
}

public function hasDownload() {
$download = FALSE;

foreach ($this->getProducts() as $product) {
if ($product['download']) {
$download = TRUE;

break;
}
}

return $download;
}
}
?>

New member

Posts

Joined
Sun Jun 24, 2012 5:32 pm
Who is online

Users browsing this forum: No registered users and 2 guests