Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

an order with cod payment and free shipping bug #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions app/code/local/Zasilkovna/Checkout/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ public function updateRules($observer){
* Neni uplne idealni, mit tu validaci takto, ale ponechavam zatim toto reseni.
**/
private function validateRules(){
$groups = Mage::app()->getRequest()->getPost('groups');

$groups = Mage::app()->getRequest()->getPost('groups');

foreach ($groups as $key => $group)
{
if(empty($group['fields']['price_rules']['value']))
{
if(empty($group['fields']['default_price']['value']))
{
$message = Mage::helper('zasilkovna')->__('Some prices are not filled');
throw new Exception($message);
throw new Exception($message);
}
continue;
}
$params = $group['fields']['price_rules']['value'];
$groupNameParts = explode(self::CONFIGURATION_KEY, $key);
$groupName = end($groupNameParts);
$groupName = end($groupNameParts);
// jen pro kody zemi
$groupName = (!empty($groupName) && strlen($groupName) == 2 ? sprintf("[%s]: ", strtoupper($groupName)) : "");
$weightMax = 0;
$weightMax = 0;

foreach ($params as $key => $line)
{
if($key == "__empty")
Expand Down Expand Up @@ -103,9 +103,9 @@ public function updatePacketeryData(Varien_Event_Observer $observer){
$orderId = $orderEvent->getIncrementId();
$parentOrderNumber = $orderEvent->getRelationParentRealId();

$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$shippingMethod = $order->getShippingMethod();

// RUN ONLY IF ZASILKOVNA CARRIER IS SELECTED
if($shippingMethod != self::SHIPPING_CODE)
{
Expand Down Expand Up @@ -153,7 +153,7 @@ private function parseOrderAddres($shippingAddress)
}

/**
* Overeni podle nastaveni modulu, jestli je pro zasilkovnu
* Overeni podle nastaveni modulu, jestli je pro zasilkovnu
* dobirka nebo ne.
*/
private function isCod($methodCode)
Expand All @@ -168,7 +168,7 @@ private function isCod($methodCode)
private function getLabel()
{
$store = Mage::app()->getStore();

if($store)
{
return $store ->getFrontendName();
Expand Down Expand Up @@ -200,7 +200,7 @@ private function prepareData($order, $packetaId, $packetaName)
list($street, $houseNumber) = $this->parseOrderAddres($shippingAddress);

return array(
'order_number' => $order->getIncrementId(),
'order_number' => $order->getIncrementId(),
'recipient_firstname' => $shippingAddress->getFirstname(),
'recipient_lastname' => $shippingAddress->getLastname(),
'recipient_phone' => $shippingAddress->getTelephone(),
Expand All @@ -210,7 +210,7 @@ private function prepareData($order, $packetaId, $packetaName)
'value' => $order->getGrandTotal(),
'branch_id' => ($packetaId ? $packetaId : (isset($fictiveBranches[$country]) ? $fictiveBranches[$country]['id'] : self::CZ_FICTIVE_BRANCH['id'])),
'point_name' => ($packetaId ? $packetaName : (isset($fictiveBranches[$country]) ? $fictiveBranches[$country]['name'] : self::CZ_FICTIVE_BRANCH['name'])),
'cod' => ($this->isCod($paymentMethod) ? $order->getShippingAmount() : 0),
'cod' => ($this->isCod($paymentMethod) ? $order->getGrandTotal() : 0),
'recipient_company' => $shippingAddress->getCompany(),
'recipient_street' => $street,
'recipient_house_number' => $houseNumber,
Expand All @@ -227,11 +227,11 @@ private function prepareData($order, $packetaId, $packetaName)
private function saveData($data)
{
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$query = "INSERT INTO packetery_order
(`order_number`, `recipient_firstname`, `recipient_lastname`, `recipient_phone`, `recipient_company`, `recipient_email`, `cod` ,`currency`,`value`, `weight`,`branch_id`,`point_name`,`recipient_street`,`recipient_house_number`,`recipient_city`,`recipient_zip`, `store_label`)

$query = "INSERT INTO packetery_order
(`order_number`, `recipient_firstname`, `recipient_lastname`, `recipient_phone`, `recipient_company`, `recipient_email`, `cod` ,`currency`,`value`, `weight`,`branch_id`,`point_name`,`recipient_street`,`recipient_house_number`,`recipient_city`,`recipient_zip`, `store_label`)
VALUES (:order_number, :recipient_firstname, :recipient_lastname, :recipient_phone, :recipient_company,:recipient_email, :cod, :currency, :value, :weight, :branch_id, :point_name, :recipient_street, :recipient_house_number, :recipient_city, :recipient_zip, :store_label)";

$connection->query($query, $data);
$connection->query($query, $data);
}
}
}