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 @@ -332,6 +332,54 @@ public function getIsInsured()
return $returnArray;
}


/**
* @param $items
*
* @return array
*/
public function getIsDigitalStamp($items)
{
$itemWeight = 0;
foreach ($items as $item) {
$qty = $item->getQty();
$qty = $qty == null ? $item->getData('qty_ordered') : $qty;
if ($item instanceof Mage_Sales_Model_Order_Shipment_Item) {
/** @var Mage_Sales_Model_Order_Item $item */
$id = $item->getProductId();
} else {
/** @var Mage_Sales_Model_Quote_Address_Item $item */
$id = $item->getProduct()->getId();
}

$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

}
}

// check in which category the weight is and calculate it in grams
$itemWeight = $itemWeight * 1000;
if ($itemWeight <= 20){
$digitalStampUpTo = 20;
} else if ($itemWeight <= 50){ // weight between 20 and 50 gram
$digitalStampUpTo = 50;
} else if ($itemWeight <= 100){ // weight between 50 and 100 gram
$digitalStampUpTo = 100;
} else if ($itemWeight <= 350){ // weight between 100 and 350 gram
$digitalStampUpTo = 350;
} else if ($itemWeight <= 2000){ // weight between 350 and 2000 gram
$digitalStampUpTo = 2000;
}

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

return $result;
}

/**
* Check if the shipment is placed using Pakjegemak
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +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_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,9 +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_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
97 changes: 64 additions & 33 deletions app/code/community/TIG/MyParcel2014/Model/Api/MyParcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,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 @@ -740,33 +744,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 @@ -788,9 +770,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['qty'],
'weight' => (int)$WeightData['weight'] * 1000,
'item_value' => array('amount' => $WeightData['price'] * 100, 'currency' => 'EUR'),
'classification' => $customsContentTypeItem,
'country' => Mage::getStoreConfig('general/country/default', $storeId),

Expand All @@ -801,8 +783,21 @@ 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['total_weight'];

}

if($data['options']['package_type'] == TIG_MyParcel2014_Model_Shipment::TYPE_DIGITAL_STAMP_NUMBER){
foreach($items as $item) {
RichardPerdaan marked this conversation as resolved.
Show resolved Hide resolved
if($item->getProductType() == 'simple') {
$WeightData = $this->getTotalWeight($totalWeight, $item);
RichardPerdaan marked this conversation as resolved.
Show resolved Hide resolved
}
}
unset($data['options']['weight']);
}

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

/**
Expand Down Expand Up @@ -832,6 +827,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' => $weight, 'total_weight' => $totalWeight, 'qty' => $qty, 'price' => $price];


}

/**
* Gets the product code parameters for this shipment.
*
Expand All @@ -854,17 +881,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 = $myParcelShipment::TYPE_PACKAGE_NUMBER;
} else {
$packageType = 2;
$packageType = $myParcelShipment::TYPE_MAILBOX_NUMBER;
}
break;
case $myParcelShipment::TYPE_UNPAID:
$packageType = 3;
$packageType = $myParcelShipment::TYPE_LETTER_NUMBER;
break;
case $myParcelShipment::TYPE_DIGITAL_STAMP:
$packageType = $myParcelShipment::TYPE_DIGITAL_STAMP_NUMBER;
break;
case $myParcelShipment::TYPE_NORMAL:
default:
$packageType = 1;
$packageType = $myParcelShipment::TYPE_PACKAGE_NUMBER;
break;
}

Expand Down Expand Up @@ -921,6 +951,7 @@ protected function _getOptionsData(TIG_MyParcel2014_Model_Shipment $myParcelShip
$data['label_description'] = $data['label_description'] . ' (' . $dateTime['day'] . '-' . $dateTime['month'] . ')';
}
}

}

if ((int)$myParcelShipment->getInsured() === 1 && $data['package_type'] != 2) {
Expand Down
22 changes: 18 additions & 4 deletions app/code/community/TIG/MyParcel2014/Model/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,18 @@ class TIG_MyParcel2014_Model_Shipment extends Mage_Core_Model_Abstract
/**
* Supported shipment types.
*/
const TYPE_LETTER_BOX = 'letter_box';
const TYPE_NORMAL = 'normal';
const TYPE_UNPAID = 'unstamped';
const TYPE_LETTER_BOX = 'letter_box';
const TYPE_NORMAL = 'normal';
const TYPE_UNPAID = 'unstamped';
const TYPE_DIGITAL_STAMP = 'digital_stamp';

/**
* Shipment types
*/
const TYPE_PACKAGE_NUMBER = 1;
const TYPE_MAILBOX_NUMBER = 2;
const TYPE_LETTER_NUMBER = 3;
const TYPE_DIGITAL_STAMP_NUMBER = 4;

/** @var TIG_MyParcel2014_Helper_Data $helper */
public $helper;
Expand Down Expand Up @@ -807,7 +816,12 @@ protected function _isValidType($type)
case self::TYPE_UNPAID:
$isValid = true;
break;
case self::TYPE_LETTER_BOX:
case self::TYPE_DIGITAL_STAMP:
if ($this->isDutchShipment()) {
$isValid = true;
}
break;
case self::TYPE_LETTER_BOX:
if ($this->isDutchShipment()) {
$isValid = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
var myParcelSelector = document.getElementById('sales_order_grid_massaction-select');
if (myParcelSelector) {
myParcelSelector.value = 'myparcel_print_labels';
$('sales_order_grid_massaction-form-additional').update('<div class="entry-edit"><span class="field-row"><select id="type_consignment" name="type_consignment" class="absolute-advice select"><option value="default"><?php echo $helper->__('Accordance with type consignment');?></option><option value="normal"><?php echo $helper->__('Normal');?></option><option value="letter_box"><?php echo $helper->__('Letterbox'); ?></option><option value="unstamped"><?php echo $helper->__('Unpaid'); ?></option></select></span><span class="field-row"><input id="create_consignment" name="create_consignment" value="1" type="hidden" class="absolute-advice"></span></div>');
$('sales_order_grid_massaction-form-additional').update('<div class="entry-edit"><span class="field-row"><select id="type_consignment" name="type_consignment" class="absolute-advice select"><option value="default"><?php echo $helper->__('Accordance with type consignment');?></option><option value="normal"><?php echo $helper->__('Normal');?></option><option value="letter_box"><?php echo $helper->__('Letterbox'); ?></option><option value="unstamped"><?php echo $helper->__('Unpaid'); ?></option><option value="digital_stamp"><?php echo $helper->__('Digital stamp'); ?></option></select></span><span class="field-row"><input id="create_consignment" name="create_consignment" value="1" type="hidden" class="absolute-advice"></span></div>');
}
}
selectMyparcel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $_returnNoAnswerSelected = $this->getIsReturnOnNoAnswer();
$_isXlSelected = $this->getIsXl();
$_insured = $this->getIsInsured();
$_isPakjegemak = $this->getIsPakjeGemak();
$_digitalStamp = $this->getIsDigitalStamp($this->getShipment()->getItemsCollection());
$_insuredSelected = '';
$_insuredUpTo = '';
$_insuredAmount = 0;
Expand All @@ -66,6 +67,10 @@ if(is_array($_insured)){
$_insuredUpTo = $_insured['insuredUpTo'];
}

if(is_array($_digitalStamp)){
$_digitalStampUpTo = $_digitalStamp['digitalStampUpTo'];
}

$_disabled = '';
if(true == $_isPakjegemak){
$_disabled= 'disabled';
Expand All @@ -82,9 +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_Shipment::TYPE_PACKAGE_NUMBER ? '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="letter_box" <?php echo $_disabled;?> <?php echo $type == TIG_MyParcel2014_Model_Shipment::TYPE_MAILBOX_NUMBER ? 'selected="selected"' : '';?>><?php echo $this->__('Letter box'); ?></option>
<option value="digital_stamp" <?php echo $_disabled;?> <?php echo $type == TIG_MyParcel2014_Model_Shipment::TYPE_DIGITAL_STAMP_NUMBER ? 'selected="selected"' : '';?>><?php echo $this->__('Digital Stamp'); ?></option>
<?php endif; ?>
<option value="unstamped" <?php echo $_disabled;?> ><?php echo $this->__('Unpaid'); ?></option>
</select>
Expand Down Expand Up @@ -158,6 +164,20 @@ if(true == $_isPakjegemak){
</p>
<?php endif;?>
</div>
<div id="myparcel_digital_stamp_options">
<?php if ($this->getDestinationCountry() == 'NL'): ?>
<p>
<label for="tig_myparcel_insured" class="normal">(<?php echo $this->__('Total order weight: ',$this->getOrderTotal());?>) <?php echo $this->__('Weight up to:');?> </label>
<select id="tig_myparcel_insured_amount" name="tig_myparcel[insured_amount]" >
<option value="20" <?php echo $_digitalStampUpTo == 20 ? 'selected="selected"' : '';?>>0 - 20 gram</option>
<option value="50" <?php echo $_digitalStampUpTo == 50 ? 'selected="selected"' : '';?>>20 - 50 gram</option>
<option value="100" <?php echo $_digitalStampUpTo == 100 ? 'selected="selected"' : '';?>>50 - 100 gram</option>
<option value="350" <?php echo $_digitalStampUpTo == 350 ? 'selected="selected"' : '';?>>100 - 350 gram</option>
<option value="2000" <?php echo $_digitalStampUpTo == 2000 ? 'selected="selected"' : '';?>>350 - 2000 gram</option>
</select>
</p>
<?php endif;?>
</div>
</div>
<p><?php echo $this->__('By creating this shipment, you create a concept in MyParcel.<br>In the backoffice you can further customize the options.');?></p>
</div>
Expand Down Expand Up @@ -203,10 +223,15 @@ if(true == $_isPakjegemak){
function checkConsignment(){
var value = shipmentTypeSelect.getValue();
var consignmentOptionFields = $('myparcel_consignment_options');
var digitalStampOptionFields = $('myparcel_digital_stamp_options');

digitalStampOptionFields.hide();
consignmentOptionFields.hide();
if (value == 'normal') {
consignmentOptionFields.show();
} else {
consignmentOptionFields.hide();
}
if (value == 'digital_stamp'){
digitalStampOptionFields.show();
}
}
checkConsignment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ if(true == $_hasExtraOptions){
<option value="normal" selected="selected"><?php echo $this->__('Normal'); ?></option>
<option value="letter_box" <?php echo $_disabled;?> ><?php echo $this->__('Letter box'); ?></option>
<option value="unstamped" <?php echo $_disabled;?> ><?php echo $this->__('Unpaid'); ?></option>
<option value="digital_stamp" <?php echo $_disabled;?> ><?php echo $this->__('Digital stamp'); ?></option>
</select>
</p>
<?php endif; ?>
Expand Down
1 change: 1 addition & 0 deletions app/locale/en_US/TIG_MyParcel2014.csv
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ TIG_MyParcel2014::status_10,Delivered - Return shipment
TIG_MyParcel2014::status_11,Delivered - Return shipment pickup location
TIG_MyParcel2014::status_12,Unrelated label printed
TIG_MyParcel2014::status_13,Credited
TIG_MyParcel2014::status_14,Digital stamp printed
TIG_MyParcel2014::status_30,Inactive - Concept
TIG_MyParcel2014::status_31,Inactive - Registered
TIG_MyParcel2014::status_32,Inactive - Enroute - Handed to carrier
Expand Down
1 change: 1 addition & 0 deletions app/locale/nl_NL/TIG_MyParcel2014.csv
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ TIG_MyParcel2014::status_10,Retourzending afgeleverd
TIG_MyParcel2014::status_11,Retourzending op afhaallocatie
TIG_MyParcel2014::status_12,Ongefrankeerd label geprint
TIG_MyParcel2014::status_13,Gecrediteerd
TIG_MyParcel2014::status_14,Digitale postzegel geprint
TIG_MyParcel2014::status_30,Inactief - Concept
TIG_MyParcel2014::status_31,Inactief - Voorgemeld
TIG_MyParcel2014::status_32,Inactief - Aangeboden bij PostNL
Expand Down