Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add digital stamp to te plugin #452

Merged
merged 13 commits into from
Feb 19, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function getIsDigitalStamp($items)
/** @var Mage_Sales_Model_Quote_Address_Item $item */
$id = $item->getProduct()->getId();
}
var_dump($item->getWeight());

$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($id);
if (empty($parentIds)) {
$itemWeight += $item->getWeight() * $qty;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graag op 1 plek berekenen wat het totaal gewicht is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the calculations done in a different way, because you are already in the order. It is therefore not possible to use the function getTotalWeight, for example. This calculation are also use different functions than the function getTotalWeight, this is necessary to make everything run smoothly

Expand All @@ -362,23 +362,22 @@ public function getIsDigitalStamp($items)
$itemWeight = $itemWeight * 1000;
if ($itemWeight <= 20){
$digitalStampUpTo = 20;
}else if ($itemWeight > 20 && $itemWeight <= 50){
} else if ($itemWeight <= 50){ // weight between 20 and 50 gram
$digitalStampUpTo = 50;
}else if ($itemWeight > 50 && $itemWeight <= 100){
} else if ($itemWeight <= 100){ // weight between 50 and 100 gram
$digitalStampUpTo = 100;
}else if ($itemWeight > 100 && $itemWeight <= 350){
} else if ($itemWeight <= 350){ // weight between 100 and 350 gram
$digitalStampUpTo = 350;
}else if ($itemWeight > 350 && $itemWeight <= 2000){
} else if ($itemWeight <= 2000){ // weight between 350 and 2000 gram
$digitalStampUpTo = 2000;
}

$selected = 'checked="checked"';
$returnArray = array(
$result = array(
'digitalStampUpTo' => $digitalStampUpTo,
'selected' => $selected,
'selected' => 'checked="checked"',
);

return $returnArray;
return $result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ protected function _addMassaction($block)
'type' => 'select',
'options' => array(
'default' => $helper->__('Accordance with type consignment'),
TIG_MyParcel2014_Model_Shipment::TYPE_NORMAL => $helper->__('Normal'),
TIG_MyParcel2014_Model_Shipment::TYPE_LETTER_BOX => $helper->__('Letterbox'),
TIG_MyParcel2014_Model_Shipment::TYPE_UNPAID => $helper->__('Unpaid'),
TIG_MyParcel2014_Model_Shipment::TYPE_DIGITAL_STAMP => $helper->__('Digital stamp'),
TIG_MyParcel2014_Model_Shipment::TYPE_NORMAL => $helper->__('Normal'),
TIG_MyParcel2014_Model_Shipment::TYPE_LETTER_BOX => $helper->__('Letterbox'),
TIG_MyParcel2014_Model_Shipment::TYPE_UNPAID => $helper->__('Unpaid'),
TIG_MyParcel2014_Model_Shipment::TYPE_DIGITAL_STAMP => $helper->__('Digital stamp'),
),
),
'create_consignment' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ protected function _addMassaction($block)
'name' => 'type_consignment',
'type' => 'select',
'options' => array(
TIG_MyParcel2014_Model_Shipment::TYPE_NORMAL => $helper->__('Normal'),
TIG_MyParcel2014_Model_Shipment::TYPE_LETTER_BOX => $helper->__('Letterbox'),
TIG_MyParcel2014_Model_Shipment::TYPE_UNPAID => $helper->__('Unpaid'),
TIG_MyParcel2014_Model_Shipment::TYPE_DIGITAL_STAMP => $helper->__('Digital stamp'),
TIG_MyParcel2014_Model_Shipment::TYPE_NORMAL => $helper->__('Normal'),
TIG_MyParcel2014_Model_Shipment::TYPE_LETTER_BOX => $helper->__('Letterbox'),
TIG_MyParcel2014_Model_Shipment::TYPE_UNPAID => $helper->__('Unpaid'),
TIG_MyParcel2014_Model_Shipment::TYPE_DIGITAL_STAMP => $helper->__('Digital stamp'),
),
),
'create_consignment' => array(
Expand Down
114 changes: 61 additions & 53 deletions app/code/community/TIG/MyParcel2014/Model/Api/MyParcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class TIG_MyParcel2014_Model_Api_MyParcel extends Varien_Object
const REQUEST_TYPE_RETRIEVE_V2_LABEL = 'pdfs';
const REQUEST_TYPE_GET_LOCATIONS = 'pickup';

/**
* Shipment types
*/
const PACKAGE = 1;
const MAILBOX = 2;
const LETTER = 3;
const DIGITAL_STAMP = 4;

/**
* Consignment types
*/
Expand All @@ -75,8 +83,6 @@ class TIG_MyParcel2014_Model_Api_MyParcel extends Varien_Object
const SHIPMENT_V2_ACTIVE_FROM = 25;
const MAX_STREET_LENGTH = 40;

const DIGITAL_STAMP = 4;

/**
* @var string
*/
Expand Down Expand Up @@ -720,6 +726,10 @@ protected function _getConsignmentData(TIG_MyParcel2014_Model_Shipment $myParcel
unset($data['recipient']['number_suffix']);
}

$totalWeight = 0;
$items = $myParcelShipment->getOrder()->getAllItems();
$i = 0;

// add customs data for EUR3 and World shipments
if($helper->countryNeedsCustoms($shippingAddress->getCountry()))
{
Expand All @@ -742,33 +752,11 @@ protected function _getConsignmentData(TIG_MyParcel2014_Model_Shipment $myParcel
$customType = (int)$helper->getConfig('customs_type', 'shipment', $storeId);
$data['customs_declaration']['contents'] = $customType == 0 ? 1 : $customType;

$totalWeight = 0;
$items = $myParcelShipment->getOrder()->getAllItems();
$i = 0;

foreach($items as $item) {
if($item->getProductType() == 'simple') {
$parentId = $item->getParentItemId();
$weight = floatval($item->getWeight());
$price = floatval($item->getPrice());
$qty = intval($item->getQtyOrdered());

if(!empty($parentId)) {
$parent = Mage::getModel('sales/order_item')->load($parentId);

if (empty($weight)) {
$weight = $parent->getWeight();
}

if (empty($price)) {
$price = $parent->getPrice();
}
}

$weight *= $qty;
$weight = max(array(1, $weight));
$totalWeight += $weight;

$price *= $qty;
$WeightData = $this->getTotalWeight($totalWeight, $item, true);

if(empty($customsContentType)){
$customsContentTypeItem = $helper->getHsCode($item, $storeId);
Expand All @@ -790,9 +778,9 @@ protected function _getConsignmentData(TIG_MyParcel2014_Model_Shipment $myParcel

$data['customs_declaration']['items'][] = array(
'description' => $itemDescription,
'amount' => $qty,
'weight' => (int)$weight * 1000,
'item_value' => array('amount' => $price * 100, 'currency' => 'EUR'),
'amount' => $WeightData[2],
'weight' => (int)$WeightData[0] * 1000,
'item_value' => array('amount' => $WeightData[3] * 100, 'currency' => 'EUR'),
'classification' => $customsContentTypeItem,
'country' => Mage::getStoreConfig('general/country/default', $storeId),

Expand All @@ -803,35 +791,23 @@ protected function _getConsignmentData(TIG_MyParcel2014_Model_Shipment $myParcel
}
}
}
$data['customs_declaration']['weight'] = (int)$totalWeight;
$data['physical_properties']['weight'] = (int)$totalWeight;
$data['customs_declaration']['weight'] = (int)$WeightData[1];

}

if($data['options']['package_type'] == self::DIGITAL_STAMP){
RichardPerdaan marked this conversation as resolved.
Show resolved Hide resolved
$totalWeight = 0;
$items = $myParcelShipment->getOrder()->getAllItems();
foreach($items as $item) {
RichardPerdaan marked this conversation as resolved.
Show resolved Hide resolved
if($item->getProductType() == 'simple') {
$parentId = $item->getParentItemId();
$weight = floatval($item->getWeight());
$qty = intval($item->getQtyOrdered());

if ( ! empty($parentId)) {
$parent = Mage::getModel('sales/order_item')->load($parentId);

if (empty($weight)) {
$weight = $parent->getWeight();
}
}
$weight *= $qty;
$totalWeight += $weight * 1000;
$WeightData = $this->getTotalWeight($totalWeight, $item);
RichardPerdaan marked this conversation as resolved.
Show resolved Hide resolved
}
}

$data['physical_properties']['weight'] = $totalWeight;
unset($data['options']['weight']);
}

if ($WeightData[1]){
$data['physical_properties']['weight'] = (int)$WeightData[1];
}

/**
* If the customer has chosen to pick up their order at a PakjeGemak location, add the PakjeGemak address.
*/
Expand Down Expand Up @@ -859,6 +835,38 @@ protected function _getConsignmentData(TIG_MyParcel2014_Model_Shipment $myParcel
return $data;
}

public function getTotalWeight($totalWeight, $item, $isWoldShipment = false) {
$parentId = $item->getParentItemId();
$weight = floatval($item->getWeight());
$price = floatval($item->getPrice());
$qty = intval($item->getQtyOrdered());

if ( ! empty($parentId)) {
$parent = Mage::getModel('sales/order_item')->load($parentId);

if (empty($weight)) {
$weight = $parent->getWeight();
}

if (empty($price)) {
$price = $parent->getPrice();
}
}

$weight *= $qty;
if ($isWoldShipment != false){
$weight = max(array(1, $weight));
}

$totalWeight += $weight * 1000;
$price *= $qty;


return [$weight, $totalWeight, $qty, $price];
RichardPerdaan marked this conversation as resolved.
Show resolved Hide resolved


}

/**
* Gets the product code parameters for this shipment.
*
Expand All @@ -881,20 +889,20 @@ protected function _getOptionsData(TIG_MyParcel2014_Model_Shipment $myParcelShip
case $myParcelShipment::TYPE_LETTER_BOX:
RichardPerdaan marked this conversation as resolved.
Show resolved Hide resolved
/* Use mailbox only if no option is selected */
if ($helper->shippingMethodIsPakjegemak($myParcelShipment->getOrder()->getShippingMethod())) {
$packageType = 1;
$packageType = self::PACKAGE;
} else {
$packageType = 2;
$packageType = self::MAILBOX;
}
break;
case $myParcelShipment::TYPE_UNPAID:
$packageType = 3;
$packageType = self::LETTER;
break;
case $myParcelShipment::TYPE_DIGITAL_STAMP:
$packageType = 4;
$packageType = self::DIGITAL_STAMP;
break;
case $myParcelShipment::TYPE_NORMAL:
default:
$packageType = 1;
$packageType = self::PACKAGE;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ if(true == $_isPakjegemak){
<p>
<label for="tig_myparcel_shipment_type" class="normal" ><?php echo $this->__('Shipment type');?></label>
<select id="tig_myparcel_shipment_type" name="tig_myparcel[shipment_type]">
<option value="normal" <?php echo $type == 1 ? 'selected="selected"' : '';?>><?php echo $this->__('Normal'); ?></option>
<option value="normal" <?php echo $type == TIG_MyParcel2014_Model_Api_MyParcel::PACKAGE ? 'selected="selected"' : '';?>><?php echo $this->__('Normal'); ?></option>
<?php if ($this->getDestinationCountry() == 'NL'): ?>
<option value="letter_box" <?php echo $_disabled;?> <?php echo $type == 2 ? 'selected="selected"' : '';?>><?php echo $this->__('Letter box'); ?></option>
<option value="digital_stamp" <?php echo $_disabled;?> <?php echo $type == 4 ? 'selected="selected"' : '';?>><?php echo $this->__('Digital Stamp'); ?></option>
<option value="letter_box" <?php echo $_disabled;?> <?php echo $type == TIG_MyParcel2014_Model_Api_MyParcel::MAILBOX ? 'selected="selected"' : '';?>><?php echo $this->__('Letter box'); ?></option>
<option value="digital_stamp" <?php echo $_disabled;?> <?php echo $type == TIG_MyParcel2014_Model_Api_MyParcel::DIGITAL_STAMP ? 'selected="selected"' : '';?>><?php echo $this->__('Digital Stamp'); ?></option>
<?php endif; ?>
<option value="unstamped" <?php echo $_disabled;?> ><?php echo $this->__('Unpaid'); ?></option>
</select>
Expand Down