diff --git a/.gitignore b/.gitignore index cb281fd6..aebec7d9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /.well-known/ /local/session/ /stats/ +/core/vendor/composer/ diff --git a/local/colissimo-label/ORD000000008739.pdf b/local/colissimo-label/ORD000000008739.pdf new file mode 100644 index 00000000..3af5d5bf Binary files /dev/null and b/local/colissimo-label/ORD000000008739.pdf differ diff --git a/local/modules/ColissimoPickupPoint/AdminIncludes/order-edit.html b/local/modules/ColissimoPickupPoint/AdminIncludes/order-edit.html new file mode 100755 index 00000000..0f706ca2 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/AdminIncludes/order-edit.html @@ -0,0 +1,31 @@ +{loop name="check.module.colissimo.pickup.point.order.edit" type="order" id=$ID status="2,3"} +{loop name="check.module.colissimo.pickup.point.id" type="colissimo.pickup.point.id"} + {if $MODULE_ID == $DELIVERY_MODULE} +
+
+
+ {intl l="Export Coliship file" d='colissimo.pickup.point.ai'} +
+
+ + {form name="colissimo.pickup.point.export"} +
+ {form_hidden_fields form=$form} + {form_field form=$form field="new_status_id"} + + {/form_field} + + {form_field form=$form field="order_"|cat:$ID} + + {/form_field} + +
+ {/form} +
+ + Suivi du colis: ici +
+
+ {/if} +{/loop} +{/loop} diff --git a/local/modules/ColissimoPickupPoint/ColissimoPickupPoint.php b/local/modules/ColissimoPickupPoint/ColissimoPickupPoint.php new file mode 100755 index 00000000..6cae6beb --- /dev/null +++ b/local/modules/ColissimoPickupPoint/ColissimoPickupPoint.php @@ -0,0 +1,342 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint; + +use ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshippingQuery; +use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshippingQuery; +use PDO; +use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\Exception\PropelException; +use Propel\Runtime\Propel; +use ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlicesQuery; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; +use Thelia\Model\Country; +use Thelia\Model\ModuleImageQuery; +use Thelia\Model\ModuleQuery; +use Propel\Runtime\Connection\ConnectionInterface; +use Thelia\Install\Database; +use Thelia\Module\AbstractDeliveryModule; +use Thelia\Module\Exception\DeliveryException; +use Thelia\Tools\Version\Version; + +class ColissimoPickupPoint extends AbstractDeliveryModule +{ + protected $request; + protected $dispatcher; + + private static $prices = null; + + const DOMAIN = 'colissimopickuppoint'; + + const COLISSIMO_USERNAME = 'colissimo_pickup_point_username'; + + const COLISSIMO_PASSWORD = 'colissimo_pickup_point_password'; + + const COLISSIMO_GOOGLE_KEY = 'colissimo_pickup_point_google_map_key'; + + const COLISSIMO_ENDPOINT = 'colissimo_pickup_point_endpoint_url'; + + /** + * These constants refer to the imported CSV file. + * IMPORT_NB_COLS: file's number of columns (begin at 1) + * IMPORT_DELIVERY_REF_COL: file's column where delivery reference is set (begin at 0) + * IMPORT_ORDER_REF_COL: file's column where order reference is set (begin at 0) + */ + const IMPORT_NB_COLS = 2; + const IMPORT_DELIVERY_REF_COL = 0; + const IMPORT_ORDER_REF_COL = 1; + + /** + * This method is called by the Delivery loop, to check if the current module has to be displayed to the customer. + * Override it to implements your delivery rules/ + * + * If you return true, the delivery method will de displayed to the customer + * If you return false, the delivery method will not be displayed + * + * @param Country $country the country to deliver to. + * + * @return boolean + * @throws PropelException + */ + public function isValidDelivery(Country $country) + { + $cartWeight = $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getWeight(); + + $areaId = $country->getAreaId(); + + $prices = ColissimoPickupPointPriceSlicesQuery::create() + ->filterByAreaId($areaId) + ->findOne(); + + $freeShipping = ColissimoPickupPointFreeshippingQuery::create() + ->findOneByActive(1); + + /* check if Colissimo delivers the asked area*/ + if (null !== $prices || null !== $freeShipping) { + return true; + } + return false; + } + + /** + * @param $areaId + * @param $weight + * @param $cartAmount + * + * @return mixed + * @throws DeliveryException + */ + public static function getPostageAmount($areaId, $weight, $cartAmount = 0) + { + $freeshipping = ColissimoPickupPointFreeshippingQuery::create() + ->findOneById(1) + ->getActive() + ; + + $freeshippingFrom = ColissimoPickupPointFreeshippingQuery::create() + ->findOneById(1) + ->getFreeshippingFrom() + ; + + $postage = 0; + + if (!$freeshipping) { + $areaPrices = ColissimoPickupPointPriceSlicesQuery::create() + ->filterByAreaId($areaId) + ->filterByWeightMax($weight, Criteria::GREATER_EQUAL) + ->_or() + ->filterByWeightMax(null) + ->filterByPriceMax($cartAmount, Criteria::GREATER_EQUAL) + ->_or() + ->filterByPriceMax(null) + ->orderByWeightMax() + ->orderByPriceMax(); + + $firstPrice = $areaPrices->find() + ->getFirst(); + + if (null === $firstPrice) { + throw new DeliveryException('Colissimo delivery unavailable for your cart weight or delivery country'); + } + + /** If a min price for general freeshipping is defined and the cart reach this amount, return a postage of 0 */ + if (null !== $freeshippingFrom && $freeshippingFrom <= $cartAmount) { + $postage = 0; + return $postage; + } + + $areaFreeshipping = ColissimoPickupPointAreaFreeshippingQuery::create() + ->filterByAreaId($areaId) + ->findOne(); + + if ($areaFreeshipping) { + $areaFreeshipping = $areaFreeshipping->getCartAmount(); + } + + /** If a min price for area freeshipping is defined and the cart reach this amount, return a postage of 0 */ + if (null !== $areaFreeshipping && $areaFreeshipping <= $cartAmount) { + $postage = 0; + return $postage; + } + + $postage = $firstPrice->getPrice(); + } + return $postage; + } + + /** + * Calculate and return delivery price + * + * @param Country $country + * @return mixed + * @throws DeliveryException + * @throws PropelException + */ + public function getPostage(Country $country) + { + $request = $this->getRequest(); + + $cartWeight = $request->getSession()->getSessionCart($this->getDispatcher())->getWeight(); + $cartAmount = $request->getSession()->getSessionCart($this->getDispatcher())->getTaxedAmount($country); + + $areaIdArray = $this->getAllAreasForCountry($country); + if (empty($areaIdArray)) { + throw new DeliveryException('Your delivery country is not covered by Colissimo.'); + } + $postage = null; + + if (null === $postage = $this->getMinPostage($areaIdArray, $cartWeight, $cartAmount)) { + $postage = $this->getMinPostage($areaIdArray, $cartWeight, $cartAmount); + if (null === $postage) { + throw new DeliveryException('Colissimo delivery unavailable for your cart weight or delivery country'); + } + } + return $postage; + } + + + private function getMinPostage($areaIdArray, $cartWeight, $cartAmount) + { + $minPostage = null; + + foreach ($areaIdArray as $areaId) { + try { + $postage = self::getPostageAmount($areaId, $cartWeight, $cartAmount); + if ($minPostage === null || $postage < $minPostage) { + $minPostage = $postage; + if ($minPostage == 0) { + break; + } + } + } catch (\Exception $ex) { + } + } + + return $minPostage; + } + + /** + * Returns ids of area containing this country and covers by this module + * @param Country $country + * @return array Area ids + */ + private function getAllAreasForCountry(Country $country) + { + $areaArray = []; + + $sql = 'SELECT ca.area_id as area_id FROM country_area ca + INNER JOIN area_delivery_module adm ON (ca.area_id = adm.area_id AND adm.delivery_module_id = :p0) + WHERE ca.country_id = :p1'; + + $con = Propel::getConnection(); + + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $this->getModuleModel()->getId(), PDO::PARAM_INT); + $stmt->bindValue(':p1', $country->getId(), PDO::PARAM_INT); + $stmt->execute(); + + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $areaArray[] = $row['area_id']; + } + + return $areaArray; + } + + /** Return the module code */ + public function getCode() + { + return 'ColissimoPickupPoint'; + } + + /** + * Check if the config values exist, and creates them otherwise + */ + protected function checkModuleConfig() { + /** Colissimo Username / Account number */ + if (null === self::getConfigValue(self::COLISSIMO_USERNAME)) { + self::setConfigValue(self::COLISSIMO_USERNAME, ''); + } + + /** Colissimo password */ + if (null === self::getConfigValue(self::COLISSIMO_PASSWORD)) { + self::setConfigValue(self::COLISSIMO_PASSWORD, ''); + } + + /** Colissimo Google Map key */ + if (null === self::getConfigValue(self::COLISSIMO_GOOGLE_KEY)) { + self::setConfigValue(self::COLISSIMO_GOOGLE_KEY, ''); + } + + /** Colissimo Endpoint url for pickup point */ + if (null === self::getConfigValue(self::COLISSIMO_ENDPOINT)) { + self::setConfigValue(self::COLISSIMO_ENDPOINT, 'https://ws.colissimo.fr/pointretrait-ws-cxf/PointRetraitServiceWS/2.0?wsdl'); + } + } + + + public function postActivation(ConnectionInterface $con = null) + { + try { + // Security to not erase user config on reactivation + ColissimoPickupPointPriceSlicesQuery::create()->findOne(); + ColissimoPickupPointAreaFreeshippingQuery::create()->findOne(); + ColissimoPickupPointFreeshippingQuery::create()->findOne(); + } catch (\Exception $e) { + $database = new Database($con->getWrappedConnection()); + $database->insertSql(null, [__DIR__ . '/Config/thelia.sql', __DIR__ . '/Config/insert.sql']); + } + + if (!ColissimoPickupPointFreeshippingQuery::create()->filterById(1)->findOne()) { + ColissimoPickupPointFreeshippingQuery::create()->filterById(1)->findOneOrCreate()->setActive(0)->save(); + } + + $this->checkModuleConfig(); + + /** Insert the images from image folder if first module activation */ + $module = $this->getModuleModel(); + if (ModuleImageQuery::create()->filterByModule($module)->count() === 0) { + $this->deployImageFolder($module, sprintf('%s/images', __DIR__), $con); + } + } + + /** Return the module ID */ + public static function getModCode() + { + return ModuleQuery::create()->findOneByCode('ColissimoPickupPoint')->getId(); + } + + /** + * @inheritDoc + */ + public function update($currentVersion, $newVersion, ConnectionInterface $con = null) + { + $this->checkModuleConfig(); + + $finder = (new Finder) + ->files() + ->name('#.*?\.sql#') + ->sortByName() + ->in(__DIR__ . DS . 'Config' . DS . 'update'); + + $database = new Database($con); + + /** @var SplFileInfo $updateSQLFile */ + foreach ($finder as $updateSQLFile) { + if (version_compare($currentVersion, str_replace('.sql', '', $updateSQLFile->getFilename()), '<')) { + $database->insertSql( + null, + [ + $updateSQLFile->getPathname() + ] + ); + } + } + } + + public function getDeliveryMode() + { + return "pickup"; + } +} diff --git a/local/modules/ColissimoPickupPoint/Config/config.xml b/local/modules/ColissimoPickupPoint/Config/config.xml new file mode 100755 index 00000000..4b719487 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Config/config.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/local/modules/ColissimoPickupPoint/Config/insert.sql b/local/modules/ColissimoPickupPoint/Config/insert.sql new file mode 100644 index 00000000..da4a6891 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Config/insert.sql @@ -0,0 +1,30 @@ +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +-- --------------------------------------------------------------------- +-- Mail templates for colissimo pickup point +-- --------------------------------------------------------------------- +-- First, delete existing entries +SET @var := 0; +SELECT @var := `id` FROM `message` WHERE name="mail_colissimo_pickup_point"; +DELETE FROM `message` WHERE `id`=@var; +-- Try if ON DELETE constraint isn't set +DELETE FROM `message_i18n` WHERE `id`=@var; + +-- Then add new entries +SELECT @max := MAX(`id`) FROM `message`; +SET @max := @max+1; +-- insert message +INSERT INTO `message` (`id`, `name`, `secured`) VALUES + (@max, + 'mail_colissimo_pickup_point', + '0' + ); + +-- and template fr_FR +INSERT INTO `message_i18n` (`id`, `locale`, `title`, `subject`, `text_message`, `html_message`) VALUES + (@max, 'fr_FR', 'Mail livraison Colissimo Point Relais', 'Suivi Colissimo Point Relais commande : {$order_ref}', '{loop type="customer" name="customer.order" current="false" id="$customer_id" backend_context="1"}\r\n{$LASTNAME} {$FIRSTNAME},\r\n{/loop}\r\nNous vous remercions de votre commande sur notre site {config key="store_name"}\r\nUn colis concernant votre commande {$order_ref} du {format_date date=$order_date} a quitté nos entrepôts pour être pris en charge par La Poste le {format_date date=$update_date}.\r\nSon numéro de suivi est le suivant : {$package}\r\nIl vous permet de suivre votre colis en ligne sur le site de La Poste : www.coliposte.net\r\nNous restons à votre disposition pour toute information complémentaire.\r\nCordialement', '{loop type="customer" name="customer.order" current="false" id="$customer_id" backend_context="1"}\r\n{$LASTNAME} {$FIRSTNAME},\r\n{/loop}\r\nNous vous remercions de votre commande sur notre site {config key="store_name"}\r\nUn colis concernant votre commande {$order_ref} du {format_date date=$order_date} a quitté nos entrepôts pour être pris en charge par La Poste le {format_date date=$update_date}.\r\nSon numéro de suivi est le suivant : {$package}\r\nIl vous permet de suivre votre colis en ligne sur le site de La Poste : www.coliposte.net\r\nIl vous sera, par ailleurs, très utile si vous étiez absent au moment de la livraison de votre colis : en fournissant ce numéro de Colissimo Suivi, vous pourrez retirer votre colis dans le bureau de Poste le plus proche.\r\nATTENTION ! Si vous ne trouvez pas l''avis de passage normalement déposé dans votre boîte aux lettres au bout de 48 Heures jours ouvrables, n''hésitez pas à aller le réclamer à votre bureau de Poste, muni de votre numéro de Colissimo Suivi.\r\nNous restons à votre disposition pour toute information complémentaire.\r\nCordialement'); + +# This restores the fkey checks, after having unset them earlier +SET FOREIGN_KEY_CHECKS = 1; diff --git a/local/modules/ColissimoPickupPoint/Config/module.xml b/local/modules/ColissimoPickupPoint/Config/module.xml new file mode 100755 index 00000000..80ab1e6f --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Config/module.xml @@ -0,0 +1,18 @@ + + + ColissimoPickupPoint\ColissimoPickupPoint + + Colissimo Pickup Point Delivery + + + Livraison Colissimo en Point Retrait + + 1.0.2 + + Thelia + info@thelia.net + + delivery + 2.3.3 + other + diff --git a/local/modules/ColissimoPickupPoint/Config/routing.xml b/local/modules/ColissimoPickupPoint/Config/routing.xml new file mode 100755 index 00000000..fd379beb --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Config/routing.xml @@ -0,0 +1,46 @@ + + + + + ColissimoPickupPoint\Controller\SliceController::saveSliceAction + + + ColissimoPickupPoint\Controller\SliceController::deleteSliceAction + + + + ColissimoPickupPoint\Controller\FreeShipping::toggleFreeShippingActivation + + + + ColissimoPickupPoint\Controller\FreeShipping::setAreaFreeShipping + + + + ColissimoPickupPoint\Controller\SaveConfig::save + + + + ColissimoPickupPoint\Controller\GetSpecificLocation::get + + [a-zA-Z\- ]+ + + + + ColissimoPickupPoint\Controller\GetSpecificLocation::getPointInfo + + + + ColissimoPickupPoint\Controller\GetSpecificLocation::search + + + + ColissimoPickupPoint\Controller\Export::export + + + + ColissimoPickupPoint:Import:import + + diff --git a/local/modules/ColissimoPickupPoint/Config/schema.xml b/local/modules/ColissimoPickupPoint/Config/schema.xml new file mode 100755 index 00000000..39eeed70 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Config/schema.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + +
+ + + + + +
+ + + + + + + + +
+ + +
diff --git a/local/modules/ColissimoPickupPoint/Config/sqldb.map b/local/modules/ColissimoPickupPoint/Config/sqldb.map new file mode 100644 index 00000000..63a93baa --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Config/sqldb.map @@ -0,0 +1,2 @@ +# Sqlfile -> Database map +thelia.sql=thelia diff --git a/local/modules/ColissimoPickupPoint/Config/thelia.sql b/local/modules/ColissimoPickupPoint/Config/thelia.sql new file mode 100644 index 00000000..ad870c65 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Config/thelia.sql @@ -0,0 +1,120 @@ + +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +-- --------------------------------------------------------------------- +-- address_colissimo_pickup_point +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `address_colissimo_pickup_point`; + +CREATE TABLE `address_colissimo_pickup_point` +( + `id` INTEGER NOT NULL, + `title_id` INTEGER NOT NULL, + `company` VARCHAR(255), + `firstname` VARCHAR(255) NOT NULL, + `lastname` VARCHAR(255) NOT NULL, + `address1` VARCHAR(255) NOT NULL, + `address2` VARCHAR(255) NOT NULL, + `address3` VARCHAR(255) NOT NULL, + `zipcode` VARCHAR(10) NOT NULL, + `city` VARCHAR(255) NOT NULL, + `country_id` INTEGER NOT NULL, + `code` VARCHAR(10) NOT NULL, + `type` VARCHAR(10) NOT NULL, + `cellphone` VARCHAR(20), + PRIMARY KEY (`id`), + INDEX `FI_address_colissimo_pickup_point_customer_title_id` (`title_id`), + INDEX `FI_address_colissimo_pickup_point_country_id` (`country_id`), + CONSTRAINT `fk_address_colissimo_pickup_point_customer_title_id` + FOREIGN KEY (`title_id`) + REFERENCES `customer_title` (`id`) + ON UPDATE RESTRICT + ON DELETE RESTRICT, + CONSTRAINT `fk_address_colissimo_pickup_point_country_id` + FOREIGN KEY (`country_id`) + REFERENCES `country` (`id`) + ON UPDATE RESTRICT + ON DELETE RESTRICT +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- order_address_colissimo_pickup_point +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `order_address_colissimo_pickup_point`; + +CREATE TABLE `order_address_colissimo_pickup_point` +( + `id` INTEGER NOT NULL, + `code` VARCHAR(10) NOT NULL, + `type` VARCHAR(10) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `fk_order_address_colissimo_pickup_point_order_address_id` + FOREIGN KEY (`id`) + REFERENCES `order_address` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- colissimo_pickup_point_price_slices +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `colissimo_pickup_point_price_slices`; + +CREATE TABLE `colissimo_pickup_point_price_slices` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `area_id` INTEGER NOT NULL, + `weight_max` FLOAT, + `price_max` FLOAT, + `franco_min_price` FLOAT, + `price` FLOAT NOT NULL, + PRIMARY KEY (`id`), + INDEX `FI_colissimo_pickup_point_price_slices_area_id` (`area_id`), + CONSTRAINT `fk_colissimo_pickup_point_price_slices_area_id` + FOREIGN KEY (`area_id`) + REFERENCES `area` (`id`) + ON UPDATE RESTRICT + ON DELETE RESTRICT +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- colissimo_pickup_point_freeshipping +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `colissimo_pickup_point_freeshipping`; + +CREATE TABLE `colissimo_pickup_point_freeshipping` +( + `id` INTEGER NOT NULL, + `active` TINYINT(1) DEFAULT 0, + `freeshipping_from` DECIMAL(18,2), + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- colissimo_pickup_point_area_freeshipping +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `colissimo_pickup_point_area_freeshipping`; + +CREATE TABLE `colissimo_pickup_point_area_freeshipping` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `area_id` INTEGER NOT NULL, + `cart_amount` DECIMAL(18,2) DEFAULT 0.00, + PRIMARY KEY (`id`), + INDEX `FI_colissimo_pickup_point_area_freeshipping_pr_area_id` (`area_id`), + CONSTRAINT `fk_colissimo_pickup_point_area_freeshipping_pr_area_id` + FOREIGN KEY (`area_id`) + REFERENCES `area` (`id`) + ON UPDATE RESTRICT + ON DELETE RESTRICT +) ENGINE=InnoDB; + +# This restores the fkey checks, after having unset them earlier +SET FOREIGN_KEY_CHECKS = 1; diff --git a/local/modules/ColissimoPickupPoint/Config/update/1.0.1.sql b/local/modules/ColissimoPickupPoint/Config/update/1.0.1.sql new file mode 100644 index 00000000..e69de29b diff --git a/local/modules/ColissimoPickupPoint/Controller/Export.php b/local/modules/ColissimoPickupPoint/Controller/Export.php new file mode 100755 index 00000000..6324562f --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Controller/Export.php @@ -0,0 +1,249 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Controller; + +use Propel\Runtime\ActiveQuery\Criteria; +use ColissimoPickupPoint\Form\ExportOrder; +use ColissimoPickupPoint\Format\CSV; +use ColissimoPickupPoint\Format\CSVLine; +use ColissimoPickupPoint\Model\OrderAddressColissimoPickupPointQuery; +use ColissimoPickupPoint\ColissimoPickupPoint; +use Symfony\Component\Config\Definition\Exception\Exception; +use Thelia\Controller\Admin\BaseAdminController; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\HttpFoundation\Response; +use Thelia\Model\Base\CountryQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Model\CustomerTitleI18nQuery; +use Thelia\Model\OrderAddressQuery; +use Thelia\Model\OrderQuery; +use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Model\OrderStatus; +use Thelia\Model\OrderStatusQuery; +use Thelia\Core\Security\Resource\AdminResources; +use Thelia\Core\Security\AccessManager; + +/** + * Class Export + * @package ColissimoPickupPoint\Controller + * @author Thelia + */ +class Export extends BaseAdminController +{ + const CSV_SEPARATOR = ';'; + + const DEFAULT_PHONE = '0100000000'; + const DEFAULT_CELLPHONE = '0600000000'; + + public function export() + { + if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) { + return $response; + } + + $csv = new CSV(self::CSV_SEPARATOR); + + try { + $form = new ExportOrder($this->getRequest()); + $vform = $this->validateForm($form); + + // Check status_id + $status_id = $vform->get('new_status_id')->getData(); + if (!preg_match('#^nochange|processing|sent$#',$status_id)) { + throw new Exception('Bad value for new_status_id field'); + } + + $status = OrderStatusQuery::create() + ->filterByCode( + array( + OrderStatus::CODE_PAID, + OrderStatus::CODE_PROCESSING, + OrderStatus::CODE_SENT + ), + Criteria::IN + ) + ->find() + ->toArray('code') + ; + + $query = OrderQuery::create() + ->filterByDeliveryModuleId(ColissimoPickupPoint::getModCode()) + ->filterByStatusId( + array( + $status[OrderStatus::CODE_PAID]['Id'], + $status[OrderStatus::CODE_PROCESSING]['Id']), + Criteria::IN + ) + ->find(); + + // check form && exec csv + /** @var \Thelia\Model\Order $order */ + foreach ($query as $order) { + $value = $vform->get('order_'.$order->getId())->getData(); + + // If checkbox is checked + if ($value) { + /** + * Retrieve user with the order + */ + $customer = $order->getCustomer(); + + /** + * Retrieve address with the order + */ + $address = OrderAddressQuery::create() + ->findPk($order->getDeliveryOrderAddressId()); + + if ($address === null) { + throw new Exception("Could not find the order's invoice address"); + } + + /** + * Retrieve country with the address + */ + $country = CountryQuery::create() + ->findPk($address->getCountryId()); + + if ($country === null) { + throw new Exception("Could not find the order's country"); + } + + /** + * Retrieve Title + */ + $title = CustomerTitleI18nQuery::create() + ->filterById($customer->getTitleId()) + ->findOneByLocale( + $this->getSession() + ->getAdminEditionLang() + ->getLocale() + ); + + /** + * Get user's phone & cellphone + * First get invoice address phone, + * If empty, try to get default address' phone. + * If still empty, set default value + */ + $phone = $address->getPhone(); + if (empty($phone)) { + $phone = $customer->getDefaultAddress()->getPhone(); + + if (empty($phone)) { + $phone = self::DEFAULT_PHONE; + } + } + + /** + * Cellphone + */ + $cellphone = $customer->getDefaultAddress()->getCellphone(); + + if (empty($cellphone)) { + $cellphone = self::DEFAULT_CELLPHONE; + } + + /** + * Compute package weight + */ + $weight = 0; + if ($vform->get('order_weight_'.$order->getId())->getData() == 0) { + /** @var \Thelia\Model\OrderProduct $product */ + foreach ($order->getOrderProducts() as $product) { + $weight+=(double) $product->getWeight() * $product->getQuantity(); + } + } else { + $weight = $vform->get('order_weight_'.$order->getId())->getData(); + } + + /** + * Get relay ID + */ + $relay_id = OrderAddressColissimoPickupPointQuery::create() + ->findPk($order->getDeliveryOrderAddressId()); + + /** + * Get store's name + */ + $store_name = ConfigQuery::read('store_name'); + /** + * Write CSV line + */ + $csv->addLine( + CSVLine::create( + array( + $address->getFirstname(), + $address->getLastname(), + $address->getCompany(), + $address->getAddress1(), + $address->getAddress2(), + $address->getAddress3(), + $address->getZipcode(), + $address->getCity(), + $country->getIsoalpha2(), + $phone, + $cellphone, + $order->getRef(), + $title->getShort(), + // the Expeditor software used to accept a relay id of 0, but no longer does + ($relay_id !== null) ? ($relay_id->getCode() == 0) ? '' : $relay_id->getCode() : 0, + $customer->getEmail(), + $weight, + $store_name, + ($relay_id !== null) ? $relay_id->getType() : 0 + ) + ) + ); + + /** + * Then update order's status if necessary + */ + if ($status_id === 'processing') { + $event = new OrderEvent($order); + $event->setStatus($status[OrderStatus::CODE_PROCESSING]['Id']); + $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + } elseif ($status_id === 'sent') { + $event = new OrderEvent($order); + $event->setStatus($status[OrderStatus::CODE_SENT]['Id']); + $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + } + + } + } + + } catch (\Exception $e) { + return Response::create($e->getMessage(),500); + } + + return Response::create( + utf8_decode($csv->parse()), + 200, + array( + 'Content-Encoding' => 'ISO-8889-1', + 'Content-Type' => 'application/csv-tab-delimited-table', + 'Content-disposition' => 'filename=expeditor_thelia.csv' + ) + ); + } +} diff --git a/local/modules/ColissimoPickupPoint/Controller/FreeShipping.php b/local/modules/ColissimoPickupPoint/Controller/FreeShipping.php new file mode 100755 index 00000000..0a81da5b --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Controller/FreeShipping.php @@ -0,0 +1,150 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Controller; + +use ColissimoPickupPoint\Form\FreeShippingForm; +use ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping; +use ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshippingQuery; +use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping; +use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshippingQuery; +use Symfony\Component\HttpFoundation\JsonResponse; +use Thelia\Controller\Admin\BaseAdminController; +use Thelia\Core\HttpFoundation\Response; + +use Thelia\Core\Security\Resource\AdminResources; +use Thelia\Core\Security\AccessManager; +use Thelia\Model\AreaQuery; + +class FreeShipping extends BaseAdminController +{ + /** + * Toggle on or off free shipping for all areas without minimum cart amount, or set the minimum cart amount to reach for all areas to get free shipping + * + * @return mixed|JsonResponse|Response|null + */ + public function toggleFreeShippingActivation() + { + if (null !== $response = $this + ->checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) { + return $response; + } + + $form = new FreeShippingForm($this->getRequest()); + $response=null; + + try { + $vform = $this->validateForm($form); + $freeshipping = $vform->get('freeshipping')->getData(); + $freeshippingFrom = $vform->get('freeshipping_from')->getData(); + + if (null === $deliveryFreeshipping = ColissimoPickupPointFreeshippingQuery::create()->findOneById(1)){ + $deliveryFreeshipping = new ColissimoPickupPointFreeshipping(); + } + + $deliveryFreeshipping + ->setActive($freeshipping) + ->setFreeshippingFrom($freeshippingFrom) + ->save() + ; + + $response = $this->generateRedirectFromRoute( + 'admin.module.configure', + array(), + array ( + 'current_tab'=> 'prices_slices_tab', + 'module_code'=> 'ColissimoPickupPoint', + '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction', + 'price_error_id' => null, + 'price_error' => null + ) + ); + } catch (\Exception $e) { + $response = JsonResponse::create(array('error' => $e->getMessage()), 500); + } + + return $response; + } + + /** + * @return mixed|null|\Symfony\Component\HttpFoundation\Response + */ + public function setAreaFreeShipping() + { + if (null !== $response = $this + ->checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) { + return $response; + } + + $data = $this->getRequest()->request; + + try { + $data = $this->getRequest()->request; + + $colissimo_pickup_area_id = $data->get('area-id'); + $cartAmount = $data->get('cart-amount'); + + if ($cartAmount < 0 || $cartAmount === '') { + $cartAmount = null; + } + + $aeraQuery = AreaQuery::create()->findOneById($colissimo_pickup_area_id); + if (null === $aeraQuery) { + return null; + } + + $colissimoPickupPointAreaFreeshippingQuery = ColissimoPickupPointAreaFreeshippingQuery::create() + ->filterByAreaId($colissimo_pickup_area_id) + ->findOne(); + + if (null === $colissimoPickupPointAreaFreeshippingQuery) { + $colissimoPickupPointFreeShipping = new ColissimoPickupPointAreaFreeshipping(); + + $colissimoPickupPointFreeShipping + ->setAreaId($colissimo_pickup_area_id) + ->setCartAmount($cartAmount) + ->save(); + } + + $cartAmountQuery = ColissimoPickupPointAreaFreeshippingQuery::create() + ->filterByAreaId($colissimo_pickup_area_id) + ->findOneOrCreate() + ->setCartAmount($cartAmount) + ->save(); + + } catch (\Exception $e) { + } + + return $this->generateRedirectFromRoute( + 'admin.module.configure', + array(), + array( + 'current_tab' => 'prices_slices_tab', + 'module_code' => 'ColissimoPickupPoint', + '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction', + 'price_error_id' => null, + 'price_error' => null + ) + ); + } +} diff --git a/local/modules/ColissimoPickupPoint/Controller/GetSpecificLocation.php b/local/modules/ColissimoPickupPoint/Controller/GetSpecificLocation.php new file mode 100755 index 00000000..2b38ac51 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Controller/GetSpecificLocation.php @@ -0,0 +1,106 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Controller; + +use ColissimoPickupPoint\ColissimoPickupPoint; +use ColissimoPickupPoint\WebService\FindById; +use Exception; +use Symfony\Component\HttpFoundation\JsonResponse; +use Thelia\Controller\Front\BaseFrontController; +use Thelia\Core\HttpFoundation\Response; +use Thelia\Core\Template\ParserInterface; +use Thelia\Core\Template\TemplateDefinition; +use Thelia\Model\ConfigQuery; + +/** + * Class SearchCityController + * @package IciRelais\Controller + * @author Thelia + */ +class GetSpecificLocation extends BaseFrontController +{ + public function get($countryid, $zipcode, $city, $address="") + { + $content = $this->renderRaw( + 'getSpecificLocationColissimoPickupPoint', + array( + '_countryid_' => $countryid, + '_zipcode_' => $zipcode, + '_city_' => $city, + '_address_' => $address + ) + ); + $response = new Response($content, 200, $headers = array('Content-Type' => 'application/json')); + + return $response; + } + + public function getPointInfo($point_id) + { + $req = new FindById(); + + $req->setId($point_id) + ->setLangue('FR') + ->setDate(date('d/m/Y')) + ->setAccountNumber(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME)) + ->setPassword(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD)) + ; + + $response = $req->exec(); + + $response = new JsonResponse($response); + + return $response; + } + + public function search() + { + $countryid = $this->getRequest()->query->get('countryid'); + $zipcode = $this->getRequest()->query->get('zipcode'); + $city = $this->getRequest()->query->get('city'); + $addressId = $this->getRequest()->query->get('address'); + + return $this->get($countryid, $zipcode, $city, $addressId); + } + + /** + * @param null $template + * @return ParserInterface instance parser + * @throws Exception + */ + protected function getParser($template = null) + { + $parser = $this->container->get('thelia.parser'); + + // Define the template that should be used + $parser->setTemplateDefinition( + new TemplateDefinition( + 'default', + TemplateDefinition::FRONT_OFFICE + ) + ); + + return $parser; + } +} diff --git a/local/modules/ColissimoPickupPoint/Controller/ImportController.php b/local/modules/ColissimoPickupPoint/Controller/ImportController.php new file mode 100644 index 00000000..9781d8da --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Controller/ImportController.php @@ -0,0 +1,129 @@ + + */ +class ImportController extends BaseAdminController +{ + public function importAction() + { + $i = 0; + + $con = Propel::getWriteConnection(OrderTableMap::DATABASE_NAME); + $con->beginTransaction(); + + $form = $this->createForm('colissimo.pickup.point.import'); + + try { + $vForm = $this->validateForm($form); + + // Get file + $importedFile = $vForm->getData()['import_file']; + + // Check extension + if (strtolower($importedFile->getClientOriginalExtension()) !='csv') { + throw new FormValidationException( + Translator::getInstance()->trans('Bad file format. CSV expected.', + [], + ColissimoPickupPoint::DOMAIN) + ); + } + + $csvData = file_get_contents($importedFile); + $lines = explode(PHP_EOL, $csvData); + + // For each line, parse columns + foreach ($lines as $line) { + $parsedLine = str_getcsv($line, ";"); + + // Get delivery and order ref + $deliveryRef = $parsedLine[ColissimoPickupPoint::IMPORT_DELIVERY_REF_COL]; + $orderRef = $parsedLine[ColissimoPickupPoint::IMPORT_ORDER_REF_COL]; + + // Save delivery ref if there is one + if (!empty($deliveryRef)) { + $this->importDeliveryRef($deliveryRef, $orderRef, $i); + } + } + + $con->commit(); + + // Get number of affected rows to display + $this->getSession()->getFlashBag()->add( + 'import-result', + Translator::getInstance()->trans( + 'Operation successful. %i orders affected.', + ['%i' => $i], + ColissimoPickupPoint::DOMAIN + ) + ); + + // Redirect + return $this->generateRedirect(URL::getInstance()->absoluteUrl($form->getSuccessUrl(), ['current_tab' => 'import'])); + } catch (FormValidationException $e) { + $con->rollback(); + + $this->setupFormErrorContext(null, $e->getMessage(), $form); + + return $this->render( + 'module-configure', + [ + 'module_code' => ColissimoPickupPoint::getModuleCode(), + 'current_tab' => 'import' + ] + ); + } + } + + /** + * Update order's delivery ref + * + * @param string $deliveryRef + * @param string $orderRef + * @param int $i + * @throws PropelException + */ + public function importDeliveryRef($deliveryRef, $orderRef, &$i) + { + // Check if the order exists + if (null !== $order = OrderQuery::create()->findOneByRef($orderRef)) { + $event = new OrderEvent($order); + + // Check if delivery refs are different + if ($order->getDeliveryRef() != $deliveryRef) { + $event->setDeliveryRef($deliveryRef); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_DELIVERY_REF, $event); + + $sentStatusId = OrderStatusQuery::create() + ->filterByCode('sent') + ->select('ID') + ->findOne(); + + // Set 'sent' order status if not already sent + if ($sentStatusId != null && $order->getStatusId() != $sentStatusId) { + $event->setStatus($sentStatusId); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); + } + + $i++; + } + } + } +} diff --git a/local/modules/ColissimoPickupPoint/Controller/SaveConfig.php b/local/modules/ColissimoPickupPoint/Controller/SaveConfig.php new file mode 100755 index 00000000..db5d1839 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Controller/SaveConfig.php @@ -0,0 +1,51 @@ +checkAuth(array(AdminResources::MODULE), array('ColissimoPickupPoint'), AccessManager::UPDATE)) { + return $response; + } + + $form = new ConfigureColissimoPickupPoint($this->getRequest()); + try { + $vform = $this->validateForm($form); + + ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME, $vform->get(ColissimoPickupPoint::COLISSIMO_USERNAME)->getData()); + ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD, $vform->get(ColissimoPickupPoint::COLISSIMO_PASSWORD)->getData()); + ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY, $vform->get(ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY)->getData()); + ColissimoPickupPoint::setConfigValue(ColissimoPickupPoint::COLISSIMO_ENDPOINT, $vform->get(ColissimoPickupPoint::COLISSIMO_ENDPOINT)->getData()); + + return $this->generateRedirect( + URL::getInstance()->absoluteUrl('/admin/module/ColissimoPickupPoint', ['current_tab' => 'configure']) + ); + } catch (\Exception $e) { + $this->setupFormErrorContext( + Translator::getInstance()->trans('Colissimo Pickup Point update config'), + $e->getMessage(), + $form, + $e + ); + + return $this->render( + 'module-configure', + [ + 'module_code' => 'ColissimoPickupPoint', + 'current_tab' => 'configure', + ] + ); + } + } +} diff --git a/local/modules/ColissimoPickupPoint/Controller/SliceController.php b/local/modules/ColissimoPickupPoint/Controller/SliceController.php new file mode 100644 index 00000000..dd7ca419 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Controller/SliceController.php @@ -0,0 +1,180 @@ +checkAuth(array(AdminResources::MODULE), ['ColissimoPickupPoint'], AccessManager::UPDATE)) { + return $response; + } + + $this->checkXmlHttpRequest(); + + $responseData = [ + 'success' => false, + 'message' => '', + 'slice' => null + ]; + + $messages = []; + $response = null; + + try { + $requestData = $this->getRequest()->request; + + if (0 !== $id = (int)$requestData->get('id', 0)) { + $slice = ColissimoPickupPointPriceSlicesQuery::create()->findPk($id); + } else { + $slice = new ColissimoPickupPointPriceSlices(); + } + + + if (0 !== $areaId = (int)$requestData->get('area', 0)) { + $slice->setAreaId($areaId); + } else { + $messages[] = $this->getTranslator()->trans( + 'The area is not valid', + [], + ColissimoPickupPoint::DOMAIN + ); + } + + $requestPriceMax = $requestData->get('priceMax', null); + $requestWeightMax = $requestData->get('weightMax', null); + + if (empty($requestPriceMax) && empty($requestWeightMax)) { + $messages[] = $this->getTranslator()->trans( + 'You must specify at least a price max or a weight max value.', + [], + ColissimoPickupPoint::DOMAIN + ); + } else { + if (!empty($requestPriceMax)) { + $priceMax = $this->getFloatVal($requestPriceMax); + if (0 < $priceMax) { + $slice->setPriceMax($priceMax); + } else { + $messages[] = $this->getTranslator()->trans( + 'The price max value is not valid', + [], + ColissimoPickupPoint::DOMAIN + ); + } + } else { + $slice->setPriceMax(null); + } + + if (!empty($requestWeightMax)) { + $weightMax = $this->getFloatVal($requestWeightMax); + if (0 < $weightMax) { + $slice->setWeightMax($weightMax); + } else { + $messages[] = $this->getTranslator()->trans( + 'The weight max value is not valid', + [], + ColissimoPickupPoint::DOMAIN + ); + } + } else { + $slice->setWeightMax(null); + } + } + + + + $price = $this->getFloatVal($requestData->get('price', 0)); + if (0 <= $price) { + $slice->setPrice($price); + } else { + $messages[] = $this->getTranslator()->trans( + 'The price value is not valid', + [], + ColissimoPickupPoint::DOMAIN + ); + } + + if (0 === count($messages)) { + $slice->save(); + $messages[] = $this->getTranslator()->trans( + 'Your slice has been saved', + [], + ColissimoPickupPoint::DOMAIN + ); + + $responseData['success'] = true; + $responseData['slice'] = $slice->toArray(TableMap::TYPE_STUDLYPHPNAME); + } + } catch (\Exception $e) { + $message[] = $e->getMessage(); + } + + $responseData['message'] = $messages; + + return $this->jsonResponse(json_encode($responseData)); + } + + protected function getFloatVal($val, $default = -1) + { + if (preg_match("#^([0-9\.,]+)$#", $val, $match)) { + $val = $match[0]; + if (strstr($val, ",")) { + $val = str_replace(".", "", $val); + $val = str_replace(",", ".", $val); + } + $val = (float)$val; + + return $val; + } + + return $default; + } + + public function deleteSliceAction() + { + $response = $this->checkAuth([], ['ColissimoPickupPoint'], AccessManager::DELETE); + + if (null !== $response) { + return $response; + } + + $this->checkXmlHttpRequest(); + + $responseData = [ + 'success' => false, + 'message' => '', + 'slice' => null + ]; + + $response = null; + + try { + $requestData = $this->getRequest()->request; + + if (0 !== $id = (int)$requestData->get('id', 0)) { + $slice = ColissimoPickupPointPriceSlicesQuery::create()->findPk($id); + $slice->delete(); + $responseData['success'] = true; + } else { + $responseData['message'] = $this->getTranslator()->trans( + 'The slice has not been deleted', + [], + ColissimoPickupPoint::DOMAIN + ); + } + } catch (\Exception $e) { + $responseData['message'] = $e->getMessage(); + } + + return $this->jsonResponse(json_encode($responseData)); + } +} diff --git a/local/modules/ColissimoPickupPoint/Form/AddPriceForm.php b/local/modules/ColissimoPickupPoint/Form/AddPriceForm.php new file mode 100644 index 00000000..0a7d3d51 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Form/AddPriceForm.php @@ -0,0 +1,85 @@ +formBuilder + ->add('area', 'integer', array( + 'constraints' => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + 'methods' => array( + array($this, + 'verifyAreaExist') + ) + )) + ) + )) + ->add('weight', 'number', array( + 'constraints' => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + 'methods' => array( + array($this, + 'verifyValidWeight') + ) + )) + ) + )) + ->add('price', 'number', array( + 'constraints' => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + 'methods' => array( + array($this, + 'verifyValidPrice') + ) + )) + ) + )) + ->add('franco', 'number', array()) + ; + } + + public function verifyAreaExist($value, ExecutionContextInterface $context) + { + $area = AreaQuery::create()->findPk($value); + if (null === $area) { + $context->addViolation(Translator::getInstance()->trans("This area doesn't exists.", [], ColissimoPickupPoint::DOMAIN)); + } + } + + public function verifyValidWeight($value, ExecutionContextInterface $context) + { + if (!preg_match("#^\d+\.?\d*$#", $value)) { + $context->addViolation(Translator::getInstance()->trans("The weight value is not valid.", [], ColissimoPickupPoint::DOMAIN)); + } + + if ($value < 0) { + $context->addViolation(Translator::getInstance()->trans("The weight value must be superior to 0.", [], ColissimoPickupPoint::DOMAIN)); + } + } + + public function verifyValidPrice($value, ExecutionContextInterface $context) + { + if (!preg_match("#^\d+\.?\d*$#", $value)) { + $context->addViolation(Translator::getInstance()->trans("The price value is not valid.", [], ColissimoPickupPoint::DOMAIN)); + } + } + + public function getName() + { + return 'colissimo_pickup_point_price_slices_create'; + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Form/ConfigureColissimoPickupPoint.php b/local/modules/ColissimoPickupPoint/Form/ConfigureColissimoPickupPoint.php new file mode 100755 index 00000000..b759f881 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Form/ConfigureColissimoPickupPoint.php @@ -0,0 +1,121 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Form; + +use ColissimoPickupPoint\ColissimoPickupPoint; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\Url; +use Thelia\Core\Translation\Translator; +use Thelia\Form\BaseForm; +use Thelia\Model\ConfigQuery; + +/** + * Class ConfigureColissimoPickupPoint + * @package ColissimoPickupPoint\Form + * @author Thelia + */ +class ConfigureColissimoPickupPoint extends BaseForm +{ + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $translator = Translator::getInstance(); + $this->formBuilder + ->add( + ColissimoPickupPoint::COLISSIMO_USERNAME, + TextType::class, + [ + 'constraints' => [new NotBlank()], + 'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME), + 'label' => $translator->trans('Account number', [], ColissimoPickupPoint::DOMAIN), + 'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_USERNAME] + ] + ) + ->add( + ColissimoPickupPoint::COLISSIMO_PASSWORD, + TextType::class, + [ + 'constraints' => [new NotBlank()], + 'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD), + 'label' => $translator->trans('Password', [], ColissimoPickupPoint::DOMAIN), + 'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_PASSWORD] + ] + ) + ->add( + ColissimoPickupPoint::COLISSIMO_ENDPOINT, + TextType::class, + [ + 'constraints' => [ + new NotBlank(), + new Url([ + 'protocols' => ['https', 'http'] + ]) + ], + 'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_ENDPOINT), + 'label' => $translator->trans('Colissimo URL prod', [], ColissimoPickupPoint::DOMAIN), + 'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_ENDPOINT] + ] + ) + ->add( + ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY, + TextType::class, + [ + 'constraints' => [], + 'data' => ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY), + 'label' => $translator->trans('Google map API key', [], ColissimoPickupPoint::DOMAIN), + 'label_attr' => ['for' => ColissimoPickupPoint::COLISSIMO_GOOGLE_KEY] + ] + ) + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'configurecolissimopickuppoint'; + } +} diff --git a/local/modules/ColissimoPickupPoint/Form/ExportOrder.php b/local/modules/ColissimoPickupPoint/Form/ExportOrder.php new file mode 100755 index 00000000..46ec31f9 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Form/ExportOrder.php @@ -0,0 +1,121 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Form; +use Propel\Runtime\ActiveQuery\Criteria; +use ColissimoPickupPoint\ColissimoPickupPoint; +use Thelia\Form\BaseForm; +use Thelia\Model\Base\OrderQuery; +use Thelia\Core\Translation\Translator; +use Thelia\Model\Order; +use Thelia\Model\OrderStatusQuery; +use Thelia\Model\OrderStatus; + +/** + * Class ExportOrder + * @package ColissimoPickupPoint\Form + * @author Thelia + */ +class ExportOrder extends BaseForm +{ + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $status = OrderStatusQuery::create() + ->filterByCode( + array( + OrderStatus::CODE_PAID, + OrderStatus::CODE_PROCESSING, + OrderStatus::CODE_SENT + ), + Criteria::IN + ) + ->find() + ->toArray('code') + ; + $query = OrderQuery::create() + ->filterByDeliveryModuleId(ColissimoPickupPoint::getModCode()) + ->filterByStatusId(array($status['paid']['Id'], $status['processing']['Id']), Criteria::IN) + ->find(); + + $this->formBuilder + ->add('new_status_id', 'choice',array( + 'label' => Translator::getInstance()->trans('server'), + 'choices' => array( + 'nochange' => Translator::getInstance()->trans('Do not change'), + 'processing' => Translator::getInstance()->trans('Set orders status as processing'), + 'sent' => Translator::getInstance()->trans('Set orders status as sent') + ), + 'required' => 'true', + 'expanded' => true, + 'multiple' => false, + 'data' => 'nochange' + ) + ); + /** @var Order $order */ + foreach ($query as $order) { + $this->formBuilder + ->add( + 'order_' . $order->getId(), + 'checkbox', + [ + 'label' => $order->getRef(), + 'label_attr' => ['for' => 'export_' . $order->getId()] + ] + ) + ->add( + 'order_weight_' . $order->getId(), + 'number' + ) + ; + } + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'exportcolissimopickuppointorder'; + } + +} diff --git a/local/modules/ColissimoPickupPoint/Form/FreeShippingForm.php b/local/modules/ColissimoPickupPoint/Form/FreeShippingForm.php new file mode 100755 index 00000000..d7821b7d --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Form/FreeShippingForm.php @@ -0,0 +1,88 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Form; + +use ColissimoPickupPoint\ColissimoPickupPoint; +use ColissimoPickupPoint\Model\ColissimoPickupPointFreeshippingQuery; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; +use Symfony\Component\Form\Extension\Core\Type\NumberType; +use Thelia\Core\Translation\Translator; +use Thelia\Form\BaseForm; + +class FreeShippingForm extends BaseForm +{ + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder + ->add( + 'freeshipping', + CheckboxType::class, + [ + 'label' => Translator::getInstance()->trans('Activate free shipping: ', [], ColissimoPickupPoint::DOMAIN) + ] + ) + ->add( + 'freeshipping_from', + NumberType::class, + [ + 'required' => false, + 'label' => Translator::getInstance()->trans("Free shipping from: ", [], ColissimoPickupPoint::DOMAIN), + 'data' => ColissimoPickupPointFreeshippingQuery::create()->findOneById(1)->getFreeshippingFrom(), + 'scale' => 2, + ] + ) + + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'colissimopickuppointfreeshipping'; + } + +} diff --git a/local/modules/ColissimoPickupPoint/Form/ImportForm.php b/local/modules/ColissimoPickupPoint/Form/ImportForm.php new file mode 100644 index 00000000..cf0c02d9 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Form/ImportForm.php @@ -0,0 +1,37 @@ + + */ +class ImportForm extends BaseForm +{ + public function getName() + { + return 'import_form'; + } + + protected function buildForm() + { + $this->formBuilder + ->add( + 'import_file', 'file', + [ + 'label' => Translator::getInstance()->trans('Select file to import', [], ColissimoPickupPoint::DOMAIN), + 'constraints' => [ + new Constraints\NotBlank(), + new Constraints\File(['mimeTypes' => ['text/csv', 'text/plain']]) + ], + 'label_attr' => ['for' => 'import_file'] + ] + ); + } +} diff --git a/local/modules/ColissimoPickupPoint/Form/UpdatePriceForm.php b/local/modules/ColissimoPickupPoint/Form/UpdatePriceForm.php new file mode 100644 index 00000000..b50398e5 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Form/UpdatePriceForm.php @@ -0,0 +1,68 @@ +formBuilder + ->add('area', 'integer', array( + 'constraints' => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + 'methods' => array( + array($this, + 'verifyAreaExist') + ) + )) + ) + )) + ->add('weight', 'number', array( + 'constraints' => array( + new Constraints\NotBlank(), + ) + )) + ->add('price', 'number', array( + 'constraints' => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + 'methods' => array( + array($this, + 'verifyValidPrice') + ) + )) + ) + )) + ->add('franco', 'number', array()) + ; + } + + public function verifyAreaExist($value, ExecutionContextInterface $context) + { + $area = AreaQuery::create()->findPk($value); + if (null === $area) { + $context->addViolation(Translator::getInstance()->trans("This area doesn't exists.", [], ColissimoPickupPoint::DOMAIN)); + } + } + + public function verifyValidPrice($value, ExecutionContextInterface $context) + { + if (!preg_match("#^\d+\.?\d*$#", $value)) { + $context->addViolation(Translator::getInstance()->trans('The price value is not valid.', [], ColissimoPickupPoint::DOMAIN)); + } + } + + public function getName() + { + return 'colissimo_pickup_point_price_slices_create'; + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Format/CSV.php b/local/modules/ColissimoPickupPoint/Format/CSV.php new file mode 100755 index 00000000..a54adf6f --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Format/CSV.php @@ -0,0 +1,99 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Format; + +/** + * Class CSV + * @package ColissimoPickupPoint\Format + * @author Thelia + */ +class CSV +{ + protected $separator; + protected $lines=array(); + + const CRLF = "\r\n"; + /** + * @param $separator + * @param array $lines + */ + public function __construct($separator, array $lines=array()) + { + $this->separator = $separator; + + foreach ($lines as $line) { + if ($line instanceof CSVLine) { + $this->addLine($line); + } + } + } + + /** + * @param $separator + * @param array $lines + * @return CSV + */ + public static function create($separator, array $lines=array()) + { + return new static($separator, $lines); + } + + /** + * @param CSVLine $line + * @return $this + */ + public function addLine(CSVLine $line) + { + $this->lines[] = $line; + + return $this; + } + + /** + * @return string parsed CSV + */ + public function parse() + { + $buffer = ''; + + for ($j=0; $j < ($lineslen = count($this->lines)); ++$j) { + /** @var CSVLine $line */ + $line = $this->lines[$j]; + $aline = $line->getValues(); + + for ($i=0; $i < ($linelen = count($aline)); ++$i) { + $buffer .= '"' . $aline[$i] . '"'; + + if ($i !== $linelen-1) { + $buffer .= $this->separator; + } + } + if ($j !== $lineslen - 1) { + $buffer .= self::CRLF; + } + } + + return $buffer; + } +} diff --git a/local/modules/ColissimoPickupPoint/Format/CSVLine.php b/local/modules/ColissimoPickupPoint/Format/CSVLine.php new file mode 100755 index 00000000..90754347 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Format/CSVLine.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Format; + +/** + * Class CSVLine + * @package ColissimoPickupPoint\Format + * @author Thelia + */ +class CSVLine +{ + protected $values = array(); + + public function __construct(array $values) + { + $this->values = $values; + } + + /** + * @param array $values + * @return CSVLine + */ + public static function create(array $values) + { + return new static($values); + } + + /** + * @return array + */ + public function getValues() + { + return $this->values; + } + + /** + * @param $value + * @return $this + */ + public function addValue($value) + { + $this->values[] = $value; + + return $this; + } +} diff --git a/local/modules/ColissimoPickupPoint/Hook/BackHook.php b/local/modules/ColissimoPickupPoint/Hook/BackHook.php new file mode 100644 index 00000000..3533cb35 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Hook/BackHook.php @@ -0,0 +1,23 @@ +add($this->render('module_configuration.html')); + } + + public function onModuleConfigJs(HookRenderEvent $event) + { + $event->add($this->render('module-config-js.html')); + } +} diff --git a/local/modules/ColissimoPickupPoint/Hook/FrontHook.php b/local/modules/ColissimoPickupPoint/Hook/FrontHook.php new file mode 100644 index 00000000..0676db0d --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Hook/FrontHook.php @@ -0,0 +1,41 @@ + + */ +class FrontHook extends BaseHook { + public function onOrderDeliveryExtra(HookRenderEvent $event) + { + $content = $this->render('colissimo-pickup-point.html', $event->getArguments()); + $event->add($content); + } + + public function onOrderInvoiceDeliveryAddress(HookRenderEvent $event) + { + $content = $this->render('delivery-address.html', $event->getArguments()); + $event->add($content); + } + + public function onMainHeadBottom(HookRenderEvent $event) + { + $content = $this->addCSS('assets/css/styles.css'); + $event->add($content); + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Hook/PdfHook.php b/local/modules/ColissimoPickupPoint/Hook/PdfHook.php new file mode 100644 index 00000000..3361707b --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Hook/PdfHook.php @@ -0,0 +1,38 @@ +getArgument('module_id')) { + return; + } + + $order = OrderQuery::create()->findOneById($event->getArgument('order')); + + if (!is_null($order)) { + $event->add($this->render( + 'delivery_mode_infos.html', + ['delivery_address_id' => $order->getDeliveryOrderAddressId()] + )); + } + } +} diff --git a/local/modules/ColissimoPickupPoint/I18n/AdminIncludes/en_US.php b/local/modules/ColissimoPickupPoint/I18n/AdminIncludes/en_US.php new file mode 100644 index 00000000..9944984f --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/AdminIncludes/en_US.php @@ -0,0 +1,6 @@ + 'Export', + 'Export Coliship file' => 'Export Coliship file', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/AdminIncludes/fr_FR.php b/local/modules/ColissimoPickupPoint/I18n/AdminIncludes/fr_FR.php new file mode 100755 index 00000000..fd8ed53b --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/AdminIncludes/fr_FR.php @@ -0,0 +1,6 @@ + 'Export', + 'Export Coliship file' => 'Export de fichier Coliship', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/backOffice/default/en_US.php b/local/modules/ColissimoPickupPoint/I18n/backOffice/default/en_US.php new file mode 100644 index 00000000..44e8f8d7 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/backOffice/default/en_US.php @@ -0,0 +1,51 @@ + '*If you choose this option, the exported orders would not be available on this page anymore', + 'Actions' => 'Actions', + 'Activate free shipping from (€) :' => 'Activate free shipping from (€) :', + 'Activate total free shipping ' => 'Activate total free shipping ', + 'Add this price slice' => 'Add this price slice', + 'Advanced configuration' => 'Advanced configuration', + 'An error occured' => 'An error occured', + 'Area : ' => 'Area : ', + 'Change orders status after export' => 'Change orders status after export', + 'Check all' => 'Check all', + 'Customer' => 'Customer', + 'Date' => 'Date', + 'Delete this price slice' => 'Delete this price slice', + 'Do not change' => 'Do not change', + 'Export' => 'Export', + 'Export Coliship file' => 'Export Coliship file', + 'If a cart matches multiple slices, it will take the last slice following that order.' => 'If a cart matches multiple slices, it will take the last slice following that order.', + 'If you don\'t specify a cart price in a slice, it will have priority over the other slices with the same weight.' => 'If you don\'t specify a cart price in a slice, it will have priority over the other slices with the same weight.', + 'If you don\'t specify a cart weight in a slice, it will have priority over the slices with weight.' => 'If you don\'t specify a cart weight in a slice, it will have priority over the slices with weight.', + 'If you specify both, the cart will require to have a lower weight AND a lower price in order to match the slice.' => 'If you specify both, the cart will require to have a lower weight AND a lower price in order to match the slice.', + 'Import Coliship file' => 'Import Coliship file', + 'Message' => 'Message', + 'Only use this for compatibility reason or if you have no other choice. For domicile delivery, you should use ColissimoWs instead.' => 'Only use this for compatibility reason or if you have no other choice. For domicile delivery, you should use ColissimoWs instead.', + 'Or activate free shipping from (€) :' => 'Or activate free shipping from (€) :', + 'Package weight' => 'Package weight', + 'Please change the access rights' => 'Please change the access rights', + 'Price (%symbol)' => 'Price (%symbol)', + 'Price slices for "%mode"' => 'Price slices for "%mode"', + 'Processing' => 'Processing', + 'REF' => 'REF', + 'Reverse selection' => 'Reverse selection', + 'Save' => 'Save', + 'Save changes' => 'Save changes', + 'Save this price slice' => 'Save this price slice', + 'Sent' => 'Sent', + 'The file has to be a CSV with 2 columns. The first contains the delivery reference, the second the order reference.' => 'The file has to be a CSV with 2 columns. The first contains the delivery reference, the second the order reference.', + 'The slices are ordered by maximum cart weight then by maximum cart price.' => 'The slices are ordered by maximum cart weight then by maximum cart price.', + 'Total taxed amount' => 'Total taxed amount', + 'Uncheck all' => 'Uncheck all', + 'Unknown customer' => 'Unknown customer', + 'Untaxed Price up to ... %symbol' => 'Untaxed Price up to ... %symbol', + 'Upload' => 'Upload', + 'Weight up to ... kg' => 'Weight up to ... kg', + 'You can create price slices by specifying a maximum cart weight and/or a maximum cart price.' => 'You can create price slices by specifying a maximum cart weight and/or a maximum cart price.', + 'You should first attribute shipping zones to the modules: ' => 'You should first attribute shipping zones to the modules: ', + 'manage shipping zones' => 'manage shipping zones', + 'operations' => 'operations', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/backOffice/default/fr_FR.php b/local/modules/ColissimoPickupPoint/I18n/backOffice/default/fr_FR.php new file mode 100644 index 00000000..8b65f350 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/backOffice/default/fr_FR.php @@ -0,0 +1,51 @@ + '* Si vous choisissez cette option, les commandes exportées n\'apparaitront plus dans cette page', + 'Actions' => 'Actions', + 'Activate free shipping from (€) :' => 'Activer les frais de port gratuits à partir de (€)', + 'Activate total free shipping ' => 'Activer les frais de port gratuits', + 'Add this price slice' => 'Ajouter cette tranche de prix', + 'Advanced configuration' => 'Configuration avancée', + 'An error occured' => 'Une erreur est survenue', + 'Area : ' => 'Zone :', + 'Change orders status after export' => 'Modifier le statut des commandes après l\'export', + 'Check all' => 'Tout cocher', + 'Customer' => 'Client', + 'Date' => 'Date', + 'Delete this price slice' => 'Supprimer cette tranche de prix', + 'Do not change' => 'Ne pas modifier', + 'Export' => 'Export', + 'Export Coliship file' => 'Export de fichier Coliship', + 'If a cart matches multiple slices, it will take the last slice following that order.' => 'Si un panier correspond à plusieurs tranches, la dernière tranche sera prise en compte selon cet ordre.', + 'If you don\'t specify a cart price in a slice, it will have priority over the other slices with the same weight.' => 'Si vous ne renseignez pas de prix de panier max dans une tranche, elle aura la priorité sur les autres tranches ayant le même poids.', + 'If you don\'t specify a cart weight in a slice, it will have priority over the slices with weight.' => 'Si vous ne renseignez pas de poids max dans une tranche, elle aura la priorité sur les tranches ayant un poids.', + 'If you specify both, the cart will require to have a lower weight AND a lower price in order to match the slice.' => 'Si vous renseignez les deux, le panier devra avoir à la fois un poids inférieur ET un prix inférieur pour correspondre à cette tranche.', + 'Import Coliship file' => 'Import de fichier Coliship', + 'Message' => 'Message', + 'Only use this for compatibility reason or if you have no other choice. For domicile delivery, you should use ColissimoWs instead.' => 'N\'utilisez ceci que pour des raisons de compatibilité ou si vous n\'avez pas d\'autres choix. Pour la livraison à domicile, utilisez plutôt désormais le module ColissimoWs', + 'Or activate free shipping from (€) :' => 'Ou activer les frais de port gratuits à partir de (€)', + 'Package weight' => 'Poids des colis (kg)', + 'Please change the access rights' => 'Merci de modifier les droits d\'accès', + 'Price (%symbol)' => 'Frais de livraison (%symbol)', + 'Price slices for "%mode"' => 'Tranche de prix pour "%mode"', + 'Processing' => 'En cours', + 'REF' => 'REF', + 'Reverse selection' => 'Inverser la sélection', + 'Save' => 'Sauvegarder', + 'Save changes' => 'Enregistrer les modifications', + 'Save this price slice' => 'Enregistrer cette tranche de prix', + 'Sent' => 'Envoyé', + 'The file has to be a CSV with 2 columns. The first contains the delivery reference, the second the order reference.' => 'Le fichier doit être au format CSV et contenir 2 colonnes. La première indique les références colis, la seconde les références des commandes.', + 'The slices are ordered by maximum cart weight then by maximum cart price.' => 'Les tranches sont triés pour poids de panier max puis par prix de panier max.', + 'Total taxed amount' => 'Montant total (avec taxes)', + 'Uncheck all' => 'Tout décocher', + 'Unknown customer' => 'Client inconnu', + 'Untaxed Price up to ... %symbol' => 'Prix HT max du panier (%symbol)', + 'Upload' => 'Charger le fichier', + 'Weight up to ... kg' => 'Poids maximum (kg)', + 'You can create price slices by specifying a maximum cart weight and/or a maximum cart price.' => 'Vous pouvez créer des tranches de prix pour les frais de port en spécifiant un poids de panier maximum et/ou un prix de panier maximum.', + 'You should first attribute shipping zones to the modules: ' => 'Vous devez d\'abord attribuer des zones de livraison à ce module :', + 'manage shipping zones' => 'Configurer les zones de livraison', + 'operations' => 'Opérations', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/en_US.php b/local/modules/ColissimoPickupPoint/I18n/en_US.php new file mode 100644 index 00000000..2204e8c3 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/en_US.php @@ -0,0 +1,34 @@ + 'Account number', + 'Activate free shipping: ' => 'Activate free shipping: ', + 'Bad file format. CSV expected.' => 'Bad file format. CSV expected.', + 'Can\'t read Config directory' => 'Can\'t read Config directory', + 'Can\'t read file' => 'Can\'t read file', + 'Colissimo URL prod' => 'Colissimo URL prod', + 'Do not change' => 'Do not change', + 'Google map API key' => 'Google map API key', + 'No relay points were selected' => 'No relay points were selected', + 'Operation successful. %i orders affected.' => 'Operation successful. %i orders affected.', + 'Password' => 'Password', + 'Select file to import' => 'Select file to import', + 'Set orders status as processing' => 'Set orders status as processing', + 'Set orders status as sent' => 'Set orders status as sent', + 'So Colissimo update config' => 'So Colissimo update config', + 'The area is not valid' => 'The area is not valid', + 'The delivery mode is not valid' => 'The delivery mode is not valid', + 'The price max value is not valid' => 'The price max value is not valid', + 'The price value is not valid' => 'The price value is not valid', + 'The price value is not valid.' => 'The price value is not valid.', + 'The slice has not been deleted' => 'The slice has not been deleted', + 'The weight max value is not valid' => 'The weight max value is not valid', + 'The weight value is not valid.' => 'The weight value is not valid.', + 'The weight value must be superior to 0.' => 'The weight value must be superior to 0.', + 'This area doesn\'t exists.' => 'This area doesn\'t exists.', + 'This delivery mode doesn\'t exists.' => 'This delivery mode doesn\'t exists.', + 'You must specify at least a price max or a weight max value.' => 'You must specify at least a price max or a weight max value.', + 'Your slice has been saved' => 'Your slice has been saved', + '[DEPRECATED] Activate Dom delivery' => '[DEPRECATED] Activate Dom delivery', + 'server' => 'server', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/fr_FR.php b/local/modules/ColissimoPickupPoint/I18n/fr_FR.php new file mode 100755 index 00000000..db0c01fe --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/fr_FR.php @@ -0,0 +1,34 @@ + 'Numéro de compte', + 'Activate free shipping: ' => 'Livraison offerte: ', + 'Bad file format. CSV expected.' => 'Mauvais format de fichier. CSV attendu.', + 'Can\'t read Config directory' => 'Le dossier Config ne peut être lu', + 'Can\'t read file' => 'Le fichier suivant ne peut être lu', + 'Colissimo URL prod' => 'URL de Colissimo en production', + 'Do not change' => 'Ne pas changer', + 'Google map API key' => 'Clé API Google map', + 'No relay points were selected' => 'Aucun point relais n\'a été sélectionné', + 'Operation successful. %i orders affected.' => 'Opération effectuée avec succès. %i commandes affectées.', + 'Password' => 'Mot de passe', + 'Select file to import' => 'Sélectionner un fichier à importer', + 'Set orders status as processing' => 'En traitement', + 'Set orders status as sent' => 'Envoyée', + 'So Colissimo update config' => 'Mise à jour de la configuration de So Colissimo ', + 'The area is not valid' => 'La zone de livraison n\'est pas valide.', + 'The delivery mode is not valid' => 'Le mode de livraison n\'est pas valide.', + 'The price max value is not valid' => 'Le prix maximum n\'est pas valide.', + 'The price value is not valid' => 'Les frais de livraison ne sont pas valides.', + 'The price value is not valid.' => 'Le prix n\'est pas valide.', + 'The slice has not been deleted' => 'La tranche n\'a pas été supprimée.', + 'The weight max value is not valid' => 'Le poids maximum n\'est pas valide.', + 'The weight value is not valid.' => 'Le poids n\'est pas valide.', + 'The weight value must be superior to 0.' => 'Le poids doit être supérieur à 0.', + 'This area doesn\'t exists.' => 'Cette zone n\'existe pas.', + 'This delivery mode doesn\'t exists.' => 'Ce mode de livraison n\'existe pas.', + 'You must specify at least a price max or a weight max value.' => 'Vous devez spécifier au moins un prix maximum ou un poids maximum.', + 'Your slice has been saved' => 'Votre tranche a été enregistrée.', + '[DEPRECATED] Activate Dom delivery' => '[DEPRECIE] Activer la livraison à domicile', + 'server' => 'Serveur', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/frontOffice/default/en_US.php b/local/modules/ColissimoPickupPoint/I18n/frontOffice/default/en_US.php new file mode 100644 index 00000000..1cef33ba --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/frontOffice/default/en_US.php @@ -0,0 +1,33 @@ + 'Actual address can\'t be geolocated', + 'Automatic pickup point' => 'Automatic pickup point', + 'Choose this delivery mode' => 'Choose this delivery mode', + 'Colissimo is unavailable. Please choose another delivery method' => 'Colissimo is unavailable. Please choose another delivery method', + 'Delivery address' => 'Delivery address', + 'Delivery in France in one of the 500 automatic instructions 7/7 and 24h/24.' => 'Delivery in France in one of the 500 automatic instructions 7/7 and 24h/24.', + 'Delivery in one of the 10,000 collection points La Poste in France or in a post office in Europe.' => 'Delivery in one of the 10,000 collection points La Poste in France or in a post office in Europe.', + 'Delivery in one of the 7,500 shops in the PICKUP network.' => 'Delivery in one of the 7,500 shops in the PICKUP network.', + 'Delivery to you or a personal address of your choice.' => 'Delivery to you or a personal address of your choice.', + 'Friday' => 'Friday', + 'Monday' => 'Monday', + 'My home' => 'My home', + 'Near you' => 'Near you', + 'No relay points were selected' => 'No relay points were selected', + 'Pickup shop' => 'Pickup shop', + 'Please enter a city and a zipcode' => 'Please enter a city and a zipcode', + 'Post office' => 'Post office', + 'Saturday' => 'Saturday', + 'Search' => 'Search', + 'Search Colissimo relay in a city' => 'Search Colissimo relay in a city', + 'Sunday' => 'Sunday', + 'Thursday' => 'Thursday', + 'Tuesday' => 'Tuesday', + 'Wednesday' => 'Wednesday', + 'address' => 'address', + 'city' => 'city', + 'home delivery' => 'home delivery', + 'include in results' => 'include in results', + 'zipcode' => 'zipcode', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/frontOffice/default/fr_FR.php b/local/modules/ColissimoPickupPoint/I18n/frontOffice/default/fr_FR.php new file mode 100755 index 00000000..6b0699e0 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/frontOffice/default/fr_FR.php @@ -0,0 +1,33 @@ + 'Actual address can\'t be geolocated ', + 'Automatic pickup point' => 'En consigne Pickup Station', + 'Choose this delivery mode' => 'Choisir ce mode de livraison', + 'Colissimo is unavailable. Please choose another delivery method' => 'Colissimo est indisponible. Merci de choisir un autre moyen de livraison.', + 'Delivery address' => 'Adresse de livraison', + 'Delivery in France in one of the 500 automatic instructions 7/7 and 24h/24.' => 'Livraison en France dans l’une des 500 consignes automatiques de retrait accessibles 7j/7 et 24h/24 (sauf consignes soumises aux horaires des galeries marchandes et zones de transports).', + 'Delivery in one of the 10,000 collection points La Poste in France or in a post office in Europe.' => 'Livraison dans l\'un des 10 000 points de retrait La Poste en France ou dans un bureau de poste à l\'étranger.', + 'Delivery in one of the 7,500 shops in the PICKUP network.' => 'Livraison dans l’un des 7500 commerçants de proximité du réseau Pickup.', + 'Delivery to you or a personal address of your choice.' => '

Livraison chez vous ou à une adresse personnelle de votre choix avec tentative de remise en mains propres ou en boîte aux lettres.

En cas d\'absence, remise en bureau de poste.

', + 'Friday' => 'Jeudi', + 'Monday' => 'Lundi', + 'My home' => 'Mon domicile', + 'Near you' => 'A proximité de chez vous', + 'No relay points were selected' => 'Aucun point relais n\'a été sélectionné', + 'Pickup shop' => 'En relais Pickup', + 'Please enter a city and a zipcode' => 'Merci de renseigner le code postal et la ville', + 'Post office' => 'En bureau de poste', + 'Saturday' => 'Samedi', + 'Search' => 'Rechercher', + 'Search Colissimo relay in a city' => 'Rechercher un point de retrait Colissimo dans une ville', + 'Sunday' => 'Dimanche', + 'Thursday' => 'Vendredi', + 'Tuesday' => 'Mardi', + 'Wednesday' => 'Mercredi', + 'address' => 'adresse', + 'city' => 'ville', + 'home delivery' => 'Livraison à domicile', + 'include in results' => 'inclure dans la recherche', + 'zipcode' => 'code postal', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/pdf/default/en_US.php b/local/modules/ColissimoPickupPoint/I18n/pdf/default/en_US.php new file mode 100644 index 00000000..75d92322 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/pdf/default/en_US.php @@ -0,0 +1,8 @@ + 'Delivered at a relay.', + 'Delivered at home.' => 'Delivered at home.', + 'Relay address:' => 'Relay address:', + 'no address' => 'no address', +); diff --git a/local/modules/ColissimoPickupPoint/I18n/pdf/default/fr_FR.php b/local/modules/ColissimoPickupPoint/I18n/pdf/default/fr_FR.php new file mode 100644 index 00000000..4e71ca3e --- /dev/null +++ b/local/modules/ColissimoPickupPoint/I18n/pdf/default/fr_FR.php @@ -0,0 +1,8 @@ + 'Livré en point relais.', + 'Delivered at home.' => 'Livré à domicile.', + 'Relay address:' => 'Adresse du point relais :', + 'no address' => 'Aucune adresse', +); diff --git a/local/modules/ColissimoPickupPoint/LICENSE.txt b/local/modules/ColissimoPickupPoint/LICENSE.txt new file mode 100644 index 00000000..65c5ca88 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/local/modules/ColissimoPickupPoint/Listener/APIListener.php b/local/modules/ColissimoPickupPoint/Listener/APIListener.php new file mode 100644 index 00000000..5ee4865f --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Listener/APIListener.php @@ -0,0 +1,162 @@ +getCountry()) { + $countryCode = $country->getIsoalpha2(); + } + + // Then ask the Web Service + $request = new FindByAddress(); + $request + ->setAddress($pickupLocationEvent->getAddress()) + ->setZipCode($pickupLocationEvent->getZipCode()) + ->setCity($pickupLocationEvent->getCity()) + ->setCountryCode($countryCode) + ->setFilterRelay('1') + ->setRequestId(md5(microtime())) + ->setLang('FR') + ->setOptionInter('1') + ->setShippingDate(date('d/m/Y')) + ->setAccountNumber(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME)) + ->setPassword(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD)) + ; + + try { + $responses = $request->exec(); + } catch (InvalidArgumentException $e) { + $responses = array(); + } catch (\SoapFault $e) { + $responses = array(); + } + + if (!is_array($responses) && $responses !== null) { + $newResponse[] = $responses; + $responses = $newResponse; + } + + return $responses; + } + + /** + * Creates and returns a new location address + * + * @param $response + * @return PickupLocationAddress + */ + protected function createPickupLocationAddressFromResponse($response) + { + /** We create the new location address */ + $pickupLocationAddress = new PickupLocationAddress(); + + /** We set the differents properties of the location address */ + $pickupLocationAddress + ->setId($response->identifiant) + ->setTitle($response->nom) + ->setAddress1($response->adresse1) + ->setAddress2($response->adresse2) + ->setAddress3($response->adresse3) + ->setCity($response->localite) + ->setZipCode($response->codePostal) + ->setPhoneNumber('') + ->setCellphoneNumber('') + ->setCompany('') + ->setCountryCode($response->codePays) + ->setFirstName('') + ->setLastName('') + ->setIsDefault(0) + ->setLabel('') + ->setAdditionalData([]) + ; + + return $pickupLocationAddress; + } + + /** + * Creates then returns a location from a response of the WebService + * + * @param $response + * @return PickupLocation + * @throws \Exception + */ + protected function createPickupLocationFromResponse($response) + { + /** We create the new location */ + $pickupLocation = new PickupLocation(); + + /** We set the differents properties of the location */ + $pickupLocation + ->setId($response->identifiant) + ->setTitle($response->nom) + ->setAddress($this->createPickupLocationAddressFromResponse($response)) + ->setLatitude($response->coordGeolocalisationLatitude) + ->setLongitude($response->coordGeolocalisationLongitude) + ->setOpeningHours(PickupLocation::MONDAY_OPENING_HOURS_KEY, $response->horairesOuvertureLundi) + ->setOpeningHours(PickupLocation::TUESDAY_OPENING_HOURS_KEY, $response->horairesOuvertureMardi) + ->setOpeningHours(PickupLocation::WEDNESDAY_OPENING_HOURS_KEY, $response->horairesOuvertureMercredi) + ->setOpeningHours(PickupLocation::THURSDAY_OPENING_HOURS_KEY, $response->horairesOuvertureJeudi) + ->setOpeningHours(PickupLocation::FRIDAY_OPENING_HOURS_KEY, $response->horairesOuvertureVendredi) + ->setOpeningHours(PickupLocation::SATURDAY_OPENING_HOURS_KEY, $response->horairesOuvertureSamedi) + ->setOpeningHours(PickupLocation::SUNDAY_OPENING_HOURS_KEY, $response->horairesOuvertureDimanche) + ->setModuleId(ColissimoPickupPoint::getModuleId()) + ; + + return $pickupLocation; + } + + /** + * Get the list of locations (relay points) + * + * @param PickupLocationEvent $pickupLocationEvent + * @throws \Exception + */ + public function getPickupLocations(PickupLocationEvent $pickupLocationEvent) + { + if (null !== $moduleIds = $pickupLocationEvent->getModuleIds()) { + if (!in_array(ColissimoPickupPoint::getModuleId(), $moduleIds)) { + return ; + } + } + + $responses = $this->callWebService($pickupLocationEvent); + + foreach ($responses as $response) { + $pickupLocationEvent->appendLocation($this->createPickupLocationFromResponse($response)); + } + } + + public static function getSubscribedEvents() + { + $listenedEvents = []; + + /** Check for old versions of Thelia where the events used by the API didn't exists */ + if (class_exists(PickupLocation::class)) { + $listenedEvents[TheliaEvents::MODULE_DELIVERY_GET_PICKUP_LOCATIONS] = array("getPickupLocations", 128); + } + + return $listenedEvents; + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Listener/SendMail.php b/local/modules/ColissimoPickupPoint/Listener/SendMail.php new file mode 100755 index 00000000..b19d9483 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Listener/SendMail.php @@ -0,0 +1,123 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Listener; + +use ColissimoPickupPoint\ColissimoPickupPoint; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Template\ParserInterface; +use Thelia\Mailer\MailerFactory; +use Thelia\Model\ConfigQuery; +use Thelia\Model\MessageQuery; + +/** + * Class SendMail + * @package Colissimo\Listener + * @author Manuel Raynaud + */ +class SendMail implements EventSubscriberInterface +{ + + protected $parser; + + protected $mailer; + + public function __construct(ParserInterface $parser, MailerFactory $mailer) + { + $this->parser = $parser; + $this->mailer = $mailer; + } + + public function updateStatus(OrderEvent $event) + { + $order = $event->getOrder(); + $colissimoPickupPoint = new ColissimoPickupPoint(); + + if ($order->isSent() && $order->getDeliveryModuleId() == $colissimoPickupPoint->getModuleModel()->getId()) { + $contact_email = ConfigQuery::read('store_email'); + + if ($contact_email) { + + $message = MessageQuery::create() + ->filterByName('mail_colissimo_pickup_point') + ->findOne(); + + if (false === $message || null === $message) { + throw new \Exception("Failed to load message 'order_confirmation'."); + } + + $order = $event->getOrder(); + $customer = $order->getCustomer(); + + $this->parser->assign('customer_id', $customer->getId()); + $this->parser->assign('order_ref', $order->getRef()); + $this->parser->assign('order_date', $order->getCreatedAt()); + $this->parser->assign('update_date', $order->getUpdatedAt()); + $this->parser->assign('package', $order->getDeliveryRef()); + + $message + ->setLocale($order->getLang()->getLocale()); + + $instance = \Swift_Message::newInstance() + ->addTo($customer->getEmail(), $customer->getFirstname() . ' ' . $customer->getLastname()) + ->addFrom($contact_email, ConfigQuery::read('store_name')) + ; + + // Build subject and body + + $message->buildMessage($this->parser, $instance); + + $this->mailer->send($instance); + } + } + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::ORDER_UPDATE_STATUS => array('updateStatus', 128) + ); + } +} diff --git a/local/modules/ColissimoPickupPoint/Listener/SetDeliveryModule.php b/local/modules/ColissimoPickupPoint/Listener/SetDeliveryModule.php new file mode 100755 index 00000000..b5874c69 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Listener/SetDeliveryModule.php @@ -0,0 +1,249 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Listener; + +use ColissimoPickupPoint\Utils\ColissimoCodeReseau; +use ColissimoPickupPoint\WebService\FindById; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Delivery\DeliveryPostageEvent; +use Thelia\Core\Event\TheliaEvents; + +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Translation\Translator; +use Thelia\Model\Address; +use Thelia\Model\CountryQuery; +use Thelia\Model\OrderAddressQuery; +use ColissimoPickupPoint\ColissimoPickupPoint; +use Thelia\Core\Event\Order\OrderEvent; +use Thelia\Model\AddressQuery; +use ColissimoPickupPoint\Model\AddressColissimoPickupPointQuery; +use ColissimoPickupPoint\Model\AddressColissimoPickupPoint; +use ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint; + +/** + * Class SetDeliveryModule + * @package ColissimoPickupPoint\Listener + * @author Thelia + */ +class SetDeliveryModule implements EventSubscriberInterface +{ + protected $request; + + public function __construct(Request $request) + { + $this->request = $request; + } + + public function getRequest() + { + return $this->request; + } + + protected function check_module($id) + { + return $id == ColissimoPickupPoint::getModCode(); + } + + private function callWebServiceFindRelayPointByIdFromRequest(Request $request) + { + $relay_infos = explode(':', $request->get('colissimo_pickup_point_code')); + + $pr_code = $relay_infos[0]; + $relayType = count($relay_infos) > 1 ? $relay_infos[1] : null ; + $relayCountryCode = count($relay_infos) > 2 ? $relay_infos[2] : null ; + + if (!empty($pr_code)) { + $req = new FindById(); + + $req->setId($pr_code) + ->setLangue('FR') + ->setDate(date('d/m/Y')) + ->setAccountNumber(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME)) + ->setPassword(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD)); + + // An argument "Code réseau" is now required in addition to the Relay Point Code to identify a relay point outside France. + // This argument is optional for relay points inside France. + if ($relayType != null && $relayCountryCode != null) { + $codeReseau = ColissimoCodeReseau::getCodeReseau($relayCountryCode, $relayType); + if ($codeReseau !== null) { + $req->setReseau($codeReseau); + } + } + + return $req->exec(); + } + + return null; + } + + public function isModuleColissimoPickupPoint(OrderEvent $event) + { + if ($this->check_module($event->getDeliveryModule())) { + $request = $this->getRequest(); + + $address = AddressColissimoPickupPointQuery::create() + ->findPk($event->getDeliveryAddress()); + + $request->getSession()->set('ColissimoPickupPointDeliveryId', $event->getDeliveryAddress()); + if ($address === null) { + $address = new AddressColissimoPickupPoint(); + $address->setId($event->getDeliveryAddress()); + } + + $response = $this->callWebServiceFindRelayPointByIdFromRequest($request); + + if ($response !== null) { + $customerName = AddressQuery::create() + ->findPk($event->getDeliveryAddress()); + + $address = AddressColissimoPickupPointQuery::create() + ->findPk($event->getDeliveryAddress()); + + $request->getSession()->set('ColissimoPickupPointDeliveryId', $event->getDeliveryAddress()); + + if ($address === null) { + $address = new AddressColissimoPickupPoint(); + $address->setId($event->getDeliveryAddress()); + } + + $relayCountry = CountryQuery::create()->findOneByIsoalpha2($response->codePays); + + if ($relayCountry == null) { + $relayCountry = $customerName->getCountry(); + } + + $address + ->setCode($response->identifiant) + ->setType($response->typeDePoint) + ->setCompany($response->nom) + ->setAddress1($response->adresse1) + ->setAddress2($response->adresse2) + ->setAddress3($response->adresse3) + ->setZipcode($response->codePostal) + ->setCity($response->localite) + ->setFirstname($customerName->getFirstname()) + ->setLastname($customerName->getLastname()) + ->setTitleId($customerName->getTitleId()) + ->setCountryId($relayCountry->getId()) + ->save() + ; + } else { + $message = Translator::getInstance()->trans('No pickup points were selected', [], ColissimoPickupPoint::DOMAIN); + throw new \Exception($message); + } + } + } + + public function updateDeliveryAddress(OrderEvent $event) + { + if ($this->check_module($event->getOrder()->getDeliveryModuleId())) { + $request = $this->getRequest(); + + $tmp_address = AddressColissimoPickupPointQuery::create() + ->findPk($request->getSession()->get('ColissimoPickupPointDeliveryId')); + + if ($tmp_address === null) { + throw new \ErrorException('Got an error with ColissimoPickupPoint module. Please try again to checkout.'); + } + + $savecode = new OrderAddressColissimoPickupPoint(); + + $savecode + ->setId($event->getOrder()->getDeliveryOrderAddressId()) + ->setCode($tmp_address->getCode()) + ->setType($tmp_address->getType()) + ->save() + ; + + $update = OrderAddressQuery::create() + ->findPK($event->getOrder()->getDeliveryOrderAddressId()) + ->setCompany($tmp_address->getCompany()) + ->setAddress1($tmp_address->getAddress1()) + ->setAddress2($tmp_address->getAddress2()) + ->setAddress3($tmp_address->getAddress3()) + ->setZipcode($tmp_address->getZipcode()) + ->setCity($tmp_address->getCity()) + ->save() + ; + } + } + + public function getPostageRelayPoint(DeliveryPostageEvent $event) + { + if ($this->check_module($event->getModule()->getModuleModel()->getId())) { + $request = $this->getRequest(); + + // If the relay point service was chosen, we store the address of the chosen relay point in + // the DeliveryPostageEvent in order for Thelia to recalculate the postage cost from this address. + + $response = $this->callWebServiceFindRelayPointByIdFromRequest($request); + + if ($response !== null) { + $address = new Address(); + $relayCountry = CountryQuery::create()->findOneByIsoalpha2($response->codePays); + + $address + ->setCompany($response->nom) + ->setAddress1($response->adresse1) + ->setAddress2($response->adresse2) + ->setAddress3($response->adresse3) + ->setZipcode($response->codePostal) + ->setCity($response->localite) + ->setCountryId($relayCountry->getId()) + ; + + $event->setAddress($address); + } + } + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::ORDER_SET_DELIVERY_MODULE => array('isModuleColissimoPickupPoint', 64), + TheliaEvents::ORDER_BEFORE_PAYMENT => array('updateDeliveryAddress', 256), + TheliaEvents::MODULE_DELIVERY_GET_POSTAGE => array('getPostageRelayPoint', 257) + ); + } +} diff --git a/local/modules/ColissimoPickupPoint/Loop/AreaFreeshipping.php b/local/modules/ColissimoPickupPoint/Loop/AreaFreeshipping.php new file mode 100644 index 00000000..d487e48a --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/AreaFreeshipping.php @@ -0,0 +1,54 @@ +getAreaId(); + + $modes = ColissimoPickupPointAreaFreeshippingQuery::create(); + + if (null !== $areaId) { + $modes->filterByAreaId($areaId); + } + + return $modes; + } + + public function parseResults(LoopResult $loopResult) + { + /** @var ColissimoPickupPointAreaFreeshipping $mode */ + foreach ($loopResult->getResultDataCollection() as $mode) { + $loopResultRow = new LoopResultRow($mode); + $loopResultRow + ->set('ID', $mode->getId()) + ->set('AREA_ID', $mode->getAreaId()) + ->set('CART_AMOUNT', $mode->getCartAmount()); + + $loopResult->addRow($loopResultRow); + } + return $loopResult; + } + +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Loop/CheckRightsLoop.php b/local/modules/ColissimoPickupPoint/Loop/CheckRightsLoop.php new file mode 100755 index 00000000..6d2e0b0f --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/CheckRightsLoop.php @@ -0,0 +1,78 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Loop; + +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Core\Template\Element\BaseLoop; +use Thelia\Core\Template\Element\LoopResultRow; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\ArraySearchLoopInterface; +use Thelia\Core\Translation\Translator; + +/** + * Class CheckRightsLoop + * @package Colissimo\Looop + * @author Thelia + */ + +class CheckRightsLoop extends BaseLoop implements ArraySearchLoopInterface +{ + protected function getArgDefinitions() + { + return new ArgumentCollection(); + } + + public function buildArray() + { + $ret = array(); + $dir = __DIR__ . '/../Config/'; + if (!is_readable($dir)) { + $ret[] = array('ERRMES' => Translator::getInstance()->trans("Can't read Config directory"), 'ERRFILE' => ''); + } + if ($handle = opendir($dir)) { + while (false !== ($file = readdir($handle))) { + if (strlen($file) > 5 && substr($file, -5) === '.json') { + if (!is_readable($dir.$file)) { + $ret[] = array('ERRMES' => Translator::getInstance()->trans("Can't read file"), 'ERRFILE' => 'Colissimo/Config/' . $file); + } + } + } + } + + return $ret; + } + public function parseResults(LoopResult $loopResult) + { + foreach ($loopResult->getResultDataCollection() as $arr) { + $loopResultRow = new LoopResultRow(); + $loopResultRow + ->set('ERRMES', $arr['ERRMES']) + ->set('ERRFILE', $arr['ERRFILE']) + ; + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} diff --git a/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointAddress.php b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointAddress.php new file mode 100755 index 00000000..e8afb380 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointAddress.php @@ -0,0 +1,83 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Loop; + +use ColissimoPickupPoint\Model\AddressColissimoPickupPoint; +use ColissimoPickupPoint\Model\AddressColissimoPickupPointQuery; +use Thelia\Core\Template\Loop\Address; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; +/** + * class ColissimoPickupPointDelivery + * @package ColissimoPickupPoint\Loop + * @author Thelia + */ +class ColissimoPickupPointAddress extends Address +{ + protected $exists = false; + protected $timestampable = false; + + protected function setExists($id) + { + $this->exists = AddressColissimoPickupPointQuery::create()->findPK($id) !== null; + } + + public function buildModelCriteria() + { + $id = $this->getId(); + $this->setExists($id[0]); + + return $this->exists ? + AddressColissimoPickupPointQuery::create()->filterById($id[0]) : + parent::buildModelCriteria(); + } + + public function parseResults(LoopResult $loopResult) + { + if (!$this->exists) { + return parent::parseResults($loopResult); + } + + /** @var AddressColissimoPickupPoint $address */ + foreach ($loopResult->getResultDataCollection() as $address) { + $loopResultRow = new LoopResultRow(); + $loopResultRow + ->set('TITLE', $address->getTitleId()) + ->set('COMPANY', $address->getCompany()) + ->set('FIRSTNAME', $address->getFirstname()) + ->set('LASTNAME', $address->getLastname()) + ->set('ADDRESS1', $address->getAddress1()) + ->set('ADDRESS2', $address->getAddress2()) + ->set('ADDRESS3', $address->getAddress3()) + ->set('ZIPCODE', $address->getZipcode()) + ->set('CITY', $address->getCity()) + ->set('COUNTRY', $address->getCountryId()) + ->set('CELLPHONE', $address->getCellphone()) + ; + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} diff --git a/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointFreeshippingLoop.php b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointFreeshippingLoop.php new file mode 100644 index 00000000..385689ee --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointFreeshippingLoop.php @@ -0,0 +1,52 @@ +findOneById(1)){ + $isFreeShippingActive = new ColissimoPickupPointFreeshipping(); + $isFreeShippingActive->setId(1); + $isFreeShippingActive->setActive(0); + $isFreeShippingActive->save(); + } + + return ColissimoPickupPointFreeshippingQuery::create()->filterById(1); + } + + public function parseResults(LoopResult $loopResult) + { + /** @var ColissimoPickupPointFreeshipping $freeshipping */ + foreach ($loopResult->getResultDataCollection() as $freeshipping) { + $loopResultRow = new LoopResultRow($freeshipping); + $loopResultRow + ->set('FREESHIPPING_ACTIVE', $freeshipping->getActive()) + ->set('FREESHIPPING_FROM', $freeshipping->getFreeshippingFrom()); + $loopResult->addRow($loopResultRow); + } + return $loopResult; + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointId.php b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointId.php new file mode 100755 index 00000000..5b9bcd6f --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointId.php @@ -0,0 +1,71 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Loop; +use ColissimoPickupPoint\ColissimoPickupPoint; +use Thelia\Core\Template\Element\ArraySearchLoopInterface; +use Thelia\Core\Template\Element\BaseLoop; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; + +/** + * class ColissimoPickupPointId + * @package ColissimoPickupPoint\Loop + * @author Thelia + */ +class ColissimoPickupPointId extends BaseLoop implements ArraySearchLoopInterface +{ + /** + * this method returns an array + * + * @return array + */ + public function buildArray() + { + return array(ColissimoPickupPoint::getModCode()); + } + + /** + * @param LoopResult $loopResult + * + * @return LoopResult + */ + public function parseResults(LoopResult $loopResult) + { + foreach ($loopResult->getResultDataCollection() as $id) { + $loopResultRow = new LoopResultRow(); + $loopResult->addRow( + $loopResultRow->set('MODULE_ID', $id) + ); + } + + return $loopResult; + } + + protected function getArgDefinitions() + { + return new ArgumentCollection(); + } + +} diff --git a/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointOrderAddressLoop.php b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointOrderAddressLoop.php new file mode 100644 index 00000000..812843f7 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointOrderAddressLoop.php @@ -0,0 +1,92 @@ +getId()) !== null) { + $query->filterById((int)$id); + } + + return $query; + } + + /** + * @param LoopResult $loopResult + * + * @return LoopResult + */ + public function parseResults(LoopResult $loopResult) + { + /** @var OrderAddressColissimoPickupPoint $orderAddressColissimoPickupPoint */ + foreach ($loopResult->getResultDataCollection() as $orderAddressColissimoPickupPoint) { + $row = new LoopResultRow(); + $row->set('ID', $orderAddressColissimoPickupPoint->getId()); + $row->set('CODE', $orderAddressColissimoPickupPoint->getCode()); + $row->set('TYPE', $orderAddressColissimoPickupPoint->getType()); + $loopResult->addRow($row) + ; + } + + return $loopResult; + } +} diff --git a/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointPriceSlices.php b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointPriceSlices.php new file mode 100644 index 00000000..6e351fe6 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/ColissimoPickupPointPriceSlices.php @@ -0,0 +1,52 @@ +getAreaId(); + + $areaPrices = ColissimoPickupPointPriceSlicesQuery::create() + ->filterByAreaId($areaId) + ->orderByWeightMax(); + + return $areaPrices; + } + + public function parseResults(LoopResult $loopResult) + { + /** @var \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices $price */ + foreach ($loopResult->getResultDataCollection() as $price) { + $loopResultRow = new LoopResultRow($price); + $loopResultRow + ->set('SLICE_ID', $price->getId()) + ->set('MAX_WEIGHT', $price->getWeightMax()) + ->set('MAX_PRICE', $price->getPriceMax()) + ->set('PRICE', $price->getPrice()) + ->set('FRANCO', $price->getFrancoMinPrice()) + ; + $loopResult->addRow($loopResultRow); + } + return $loopResult; + } +} diff --git a/local/modules/ColissimoPickupPoint/Loop/GetRelais.php b/local/modules/ColissimoPickupPoint/Loop/GetRelais.php new file mode 100755 index 00000000..9fc142a0 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/GetRelais.php @@ -0,0 +1,179 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Loop; + +use ColissimoPickupPoint\ColissimoPickupPoint; +use ColissimoPickupPoint\WebService\FindByAddress; +use Symfony\Component\Serializer\Exception\InvalidArgumentException; +use Thelia\Core\Template\Element\ArraySearchLoopInterface; +use Thelia\Core\Template\Element\BaseLoop; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Log\Tlog; +use Thelia\Model\AddressQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Model\CountryQuery; + +/** + * Class GetRelais + * @package ColissimoPickupPoint\Loop + * @author Thelia + */ +class GetRelais extends BaseLoop implements ArraySearchLoopInterface +{ + /** + * @inheritdoc + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntTypeArgument('countryid', ''), + Argument::createAnyTypeArgument('zipcode', ''), + Argument::createAnyTypeArgument('city', ''), + Argument::createIntTypeArgument('address') + ); + } + + /** + * @return array|mixed + * @throws \ErrorException + * @throws \Propel\Runtime\Exception\PropelException + */ + public function buildArray() + { + // Find the address ... To find ! \m/ + $zipcode = $this->getZipcode(); + $city = $this->getCity(); + $countryId = $this->getCountryid(); + + $addressId = $this->getAddress(); + + if (!empty($addressId) && (!empty($zipcode) || !empty($city))) { + throw new \InvalidArgumentException( + "Cannot have argument 'address' and 'zipcode' or 'city' at the same time." + ); + } + + if (null !== $addressModel = AddressQuery::create()->findPk($addressId)) { + $address = array( + 'zipcode' => $addressModel->getZipcode(), + 'city' => $addressModel->getCity(), + 'address' => $addressModel->getAddress1(), + 'countrycode' => $addressModel->getCountry()->getIsoalpha2() + ); + } elseif (empty($zipcode) || empty($city)) { + $search = AddressQuery::create(); + + $customer = $this->securityContext->getCustomerUser(); + if ($customer !== null) { + $search->filterByCustomerId($customer->getId()); + $search->filterByIsDefault('1'); + } else { + throw new \ErrorException('Customer not connected.'); + } + + $search = $search->findOne(); + $address['zipcode'] = $search->getZipcode(); + $address['city'] = $search->getCity(); + $address['address'] = $search->getAddress1(); + $address['countrycode'] = $search->getCountry()->getIsoalpha2(); + } else { + $address = array( + 'zipcode' => $zipcode, + 'city' => $city, + 'address' => '', + 'countrycode' => CountryQuery::create() + ->findOneById($countryId) + ->getIsoalpha2() + ); + } + + // Then ask the Web Service + $request = new FindByAddress(); + $request + ->setAddress($address['address']) + ->setZipCode($address['zipcode']) + ->setCity($address['city']) + ->setCountryCode($address['countrycode']) + ->setFilterRelay('1') + ->setRequestId(md5(microtime())) + ->setLang('FR') + ->setOptionInter('1') + ->setShippingDate(date('d/m/Y')) + ->setAccountNumber(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_USERNAME)) + ->setPassword(ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_PASSWORD)) + ; + + try { + $response = $request->exec(); + } catch (InvalidArgumentException $e) { + $response = array(); + } catch (\SoapFault $e) { + $response = array(); + } + + if (!is_array($response) && $response !== null) { + $newResponse[] = $response; + $response = $newResponse; + } + + return $response; + } + + /** + * @param LoopResult $loopResult + * + * @return LoopResult + */ + public function parseResults(LoopResult $loopResult) + { + foreach ($loopResult->getResultDataCollection() as $item) { + $loopResultRow = new LoopResultRow(); + + //Tlog::getInstance()->addDebug(print_r($item, true)); + foreach ($item as $key => $value) { + $loopResultRow->set($key, $value); + } + + // format distance + $distance = (string) $loopResultRow->get('distanceEnMetre'); + if (strlen($distance) < 4) { + $distance .= ' m'; + } else { + $distance = (string)(float)$distance / 1000; + while (substr($distance, strlen($distance) - 1, 1) == "0") { + $distance = substr($distance, 0, strlen($distance) - 1); + } + $distance = str_replace('.', ',', $distance) . ' km'; + } + $loopResultRow->set('distance', $distance); + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} diff --git a/local/modules/ColissimoPickupPoint/Loop/NotSentOrders.php b/local/modules/ColissimoPickupPoint/Loop/NotSentOrders.php new file mode 100755 index 00000000..871b68af --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Loop/NotSentOrders.php @@ -0,0 +1,75 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\Loop; + +use Propel\Runtime\ActiveQuery\Criteria; +use ColissimoPickupPoint\ColissimoPickupPoint; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Model\OrderQuery; +use Thelia\Core\Template\Loop\Order; +use Thelia\Model\OrderStatus; +use Thelia\Model\OrderStatusQuery; + +/** + * Class NotSentOrders + * @package ColissimoPickupPoint\Loop + * @author Thelia + */ +class NotSentOrders extends Order +{ + public function getArgDefinitions() + { + return new ArgumentCollection(Argument::createBooleanTypeArgument('with_prev_next_info', false)); + } + + /** + * this method returns a Propel ModelCriteria + * + * @return \Propel\Runtime\ActiveQuery\ModelCriteria + */ + public function buildModelCriteria() + { + $status = OrderStatusQuery::create() + ->filterByCode( + array( + OrderStatus::CODE_PAID, + OrderStatus::CODE_PROCESSING, + ), + Criteria::IN + ) + ->find() + ->toArray('code'); + $query = OrderQuery::create() + ->filterByDeliveryModuleId(ColissimoPickupPoint::getModCode()) + ->filterByStatusId( + array( + $status[OrderStatus::CODE_PAID]['Id'], + $status[OrderStatus::CODE_PROCESSING]['Id']), + Criteria::IN + ); + + return $query; + } +} diff --git a/local/modules/ColissimoPickupPoint/Model/AddressColissimoPickupPoint.php b/local/modules/ColissimoPickupPoint/Model/AddressColissimoPickupPoint.php new file mode 100644 index 00000000..38044c2e --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/AddressColissimoPickupPoint.php @@ -0,0 +1,10 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another AddressColissimoPickupPoint instance. If + * obj is an instance of AddressColissimoPickupPoint, delegates to + * equals(AddressColissimoPickupPoint). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return AddressColissimoPickupPoint The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return AddressColissimoPickupPoint The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [title_id] column value. + * + * @return int + */ + public function getTitleId() + { + + return $this->title_id; + } + + /** + * Get the [company] column value. + * + * @return string + */ + public function getCompany() + { + + return $this->company; + } + + /** + * Get the [firstname] column value. + * + * @return string + */ + public function getFirstname() + { + + return $this->firstname; + } + + /** + * Get the [lastname] column value. + * + * @return string + */ + public function getLastname() + { + + return $this->lastname; + } + + /** + * Get the [address1] column value. + * + * @return string + */ + public function getAddress1() + { + + return $this->address1; + } + + /** + * Get the [address2] column value. + * + * @return string + */ + public function getAddress2() + { + + return $this->address2; + } + + /** + * Get the [address3] column value. + * + * @return string + */ + public function getAddress3() + { + + return $this->address3; + } + + /** + * Get the [zipcode] column value. + * + * @return string + */ + public function getZipcode() + { + + return $this->zipcode; + } + + /** + * Get the [city] column value. + * + * @return string + */ + public function getCity() + { + + return $this->city; + } + + /** + * Get the [country_id] column value. + * + * @return int + */ + public function getCountryId() + { + + return $this->country_id; + } + + /** + * Get the [code] column value. + * + * @return string + */ + public function getCode() + { + + return $this->code; + } + + /** + * Get the [type] column value. + * + * @return string + */ + public function getType() + { + + return $this->type; + } + + /** + * Get the [cellphone] column value. + * + * @return string + */ + public function getCellphone() + { + + return $this->cellphone; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [title_id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setTitleId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->title_id !== $v) { + $this->title_id = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::TITLE_ID] = true; + } + + if ($this->aCustomerTitle !== null && $this->aCustomerTitle->getId() !== $v) { + $this->aCustomerTitle = null; + } + + + return $this; + } // setTitleId() + + /** + * Set the value of [company] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setCompany($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->company !== $v) { + $this->company = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::COMPANY] = true; + } + + + return $this; + } // setCompany() + + /** + * Set the value of [firstname] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setFirstname($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->firstname !== $v) { + $this->firstname = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::FIRSTNAME] = true; + } + + + return $this; + } // setFirstname() + + /** + * Set the value of [lastname] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setLastname($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->lastname !== $v) { + $this->lastname = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::LASTNAME] = true; + } + + + return $this; + } // setLastname() + + /** + * Set the value of [address1] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setAddress1($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->address1 !== $v) { + $this->address1 = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::ADDRESS1] = true; + } + + + return $this; + } // setAddress1() + + /** + * Set the value of [address2] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setAddress2($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->address2 !== $v) { + $this->address2 = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::ADDRESS2] = true; + } + + + return $this; + } // setAddress2() + + /** + * Set the value of [address3] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setAddress3($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->address3 !== $v) { + $this->address3 = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::ADDRESS3] = true; + } + + + return $this; + } // setAddress3() + + /** + * Set the value of [zipcode] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setZipcode($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->zipcode !== $v) { + $this->zipcode = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::ZIPCODE] = true; + } + + + return $this; + } // setZipcode() + + /** + * Set the value of [city] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setCity($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->city !== $v) { + $this->city = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::CITY] = true; + } + + + return $this; + } // setCity() + + /** + * Set the value of [country_id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setCountryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->country_id !== $v) { + $this->country_id = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::COUNTRY_ID] = true; + } + + if ($this->aCountry !== null && $this->aCountry->getId() !== $v) { + $this->aCountry = null; + } + + + return $this; + } // setCountryId() + + /** + * Set the value of [code] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setCode($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->code !== $v) { + $this->code = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::CODE] = true; + } + + + return $this; + } // setCode() + + /** + * Set the value of [type] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setType($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->type !== $v) { + $this->type = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::TYPE] = true; + } + + + return $this; + } // setType() + + /** + * Set the value of [cellphone] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setCellphone($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->cellphone !== $v) { + $this->cellphone = $v; + $this->modifiedColumns[AddressColissimoPickupPointTableMap::CELLPHONE] = true; + } + + + return $this; + } // setCellphone() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('TitleId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->title_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Company', TableMap::TYPE_PHPNAME, $indexType)]; + $this->company = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Firstname', TableMap::TYPE_PHPNAME, $indexType)]; + $this->firstname = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Lastname', TableMap::TYPE_PHPNAME, $indexType)]; + $this->lastname = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Address1', TableMap::TYPE_PHPNAME, $indexType)]; + $this->address1 = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Address2', TableMap::TYPE_PHPNAME, $indexType)]; + $this->address2 = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Address3', TableMap::TYPE_PHPNAME, $indexType)]; + $this->address3 = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Zipcode', TableMap::TYPE_PHPNAME, $indexType)]; + $this->zipcode = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('City', TableMap::TYPE_PHPNAME, $indexType)]; + $this->city = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('CountryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->country_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Code', TableMap::TYPE_PHPNAME, $indexType)]; + $this->code = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Type', TableMap::TYPE_PHPNAME, $indexType)]; + $this->type = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : AddressColissimoPickupPointTableMap::translateFieldName('Cellphone', TableMap::TYPE_PHPNAME, $indexType)]; + $this->cellphone = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 14; // 14 = AddressColissimoPickupPointTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \ColissimoPickupPoint\Model\AddressColissimoPickupPoint object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCustomerTitle !== null && $this->title_id !== $this->aCustomerTitle->getId()) { + $this->aCustomerTitle = null; + } + if ($this->aCountry !== null && $this->country_id !== $this->aCountry->getId()) { + $this->aCountry = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildAddressColissimoPickupPointQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCustomerTitle = null; + $this->aCountry = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see AddressColissimoPickupPoint::setDeleted() + * @see AddressColissimoPickupPoint::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildAddressColissimoPickupPointQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + AddressColissimoPickupPointTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCustomerTitle !== null) { + if ($this->aCustomerTitle->isModified() || $this->aCustomerTitle->isNew()) { + $affectedRows += $this->aCustomerTitle->save($con); + } + $this->setCustomerTitle($this->aCustomerTitle); + } + + if ($this->aCountry !== null) { + if ($this->aCountry->isModified() || $this->aCountry->isNew()) { + $affectedRows += $this->aCountry->save($con); + } + $this->setCountry($this->aCountry); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::TITLE_ID)) { + $modifiedColumns[':p' . $index++] = 'TITLE_ID'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::COMPANY)) { + $modifiedColumns[':p' . $index++] = 'COMPANY'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::FIRSTNAME)) { + $modifiedColumns[':p' . $index++] = 'FIRSTNAME'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::LASTNAME)) { + $modifiedColumns[':p' . $index++] = 'LASTNAME'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ADDRESS1)) { + $modifiedColumns[':p' . $index++] = 'ADDRESS1'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ADDRESS2)) { + $modifiedColumns[':p' . $index++] = 'ADDRESS2'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ADDRESS3)) { + $modifiedColumns[':p' . $index++] = 'ADDRESS3'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ZIPCODE)) { + $modifiedColumns[':p' . $index++] = 'ZIPCODE'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::CITY)) { + $modifiedColumns[':p' . $index++] = 'CITY'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::COUNTRY_ID)) { + $modifiedColumns[':p' . $index++] = 'COUNTRY_ID'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::CODE)) { + $modifiedColumns[':p' . $index++] = 'CODE'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::TYPE)) { + $modifiedColumns[':p' . $index++] = 'TYPE'; + } + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::CELLPHONE)) { + $modifiedColumns[':p' . $index++] = 'CELLPHONE'; + } + + $sql = sprintf( + 'INSERT INTO address_colissimo_pickup_point (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'TITLE_ID': + $stmt->bindValue($identifier, $this->title_id, PDO::PARAM_INT); + break; + case 'COMPANY': + $stmt->bindValue($identifier, $this->company, PDO::PARAM_STR); + break; + case 'FIRSTNAME': + $stmt->bindValue($identifier, $this->firstname, PDO::PARAM_STR); + break; + case 'LASTNAME': + $stmt->bindValue($identifier, $this->lastname, PDO::PARAM_STR); + break; + case 'ADDRESS1': + $stmt->bindValue($identifier, $this->address1, PDO::PARAM_STR); + break; + case 'ADDRESS2': + $stmt->bindValue($identifier, $this->address2, PDO::PARAM_STR); + break; + case 'ADDRESS3': + $stmt->bindValue($identifier, $this->address3, PDO::PARAM_STR); + break; + case 'ZIPCODE': + $stmt->bindValue($identifier, $this->zipcode, PDO::PARAM_STR); + break; + case 'CITY': + $stmt->bindValue($identifier, $this->city, PDO::PARAM_STR); + break; + case 'COUNTRY_ID': + $stmt->bindValue($identifier, $this->country_id, PDO::PARAM_INT); + break; + case 'CODE': + $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR); + break; + case 'TYPE': + $stmt->bindValue($identifier, $this->type, PDO::PARAM_STR); + break; + case 'CELLPHONE': + $stmt->bindValue($identifier, $this->cellphone, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = AddressColissimoPickupPointTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getTitleId(); + break; + case 2: + return $this->getCompany(); + break; + case 3: + return $this->getFirstname(); + break; + case 4: + return $this->getLastname(); + break; + case 5: + return $this->getAddress1(); + break; + case 6: + return $this->getAddress2(); + break; + case 7: + return $this->getAddress3(); + break; + case 8: + return $this->getZipcode(); + break; + case 9: + return $this->getCity(); + break; + case 10: + return $this->getCountryId(); + break; + case 11: + return $this->getCode(); + break; + case 12: + return $this->getType(); + break; + case 13: + return $this->getCellphone(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['AddressColissimoPickupPoint'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['AddressColissimoPickupPoint'][$this->getPrimaryKey()] = true; + $keys = AddressColissimoPickupPointTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getTitleId(), + $keys[2] => $this->getCompany(), + $keys[3] => $this->getFirstname(), + $keys[4] => $this->getLastname(), + $keys[5] => $this->getAddress1(), + $keys[6] => $this->getAddress2(), + $keys[7] => $this->getAddress3(), + $keys[8] => $this->getZipcode(), + $keys[9] => $this->getCity(), + $keys[10] => $this->getCountryId(), + $keys[11] => $this->getCode(), + $keys[12] => $this->getType(), + $keys[13] => $this->getCellphone(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCustomerTitle) { + $result['CustomerTitle'] = $this->aCustomerTitle->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aCountry) { + $result['Country'] = $this->aCountry->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = AddressColissimoPickupPointTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setTitleId($value); + break; + case 2: + $this->setCompany($value); + break; + case 3: + $this->setFirstname($value); + break; + case 4: + $this->setLastname($value); + break; + case 5: + $this->setAddress1($value); + break; + case 6: + $this->setAddress2($value); + break; + case 7: + $this->setAddress3($value); + break; + case 8: + $this->setZipcode($value); + break; + case 9: + $this->setCity($value); + break; + case 10: + $this->setCountryId($value); + break; + case 11: + $this->setCode($value); + break; + case 12: + $this->setType($value); + break; + case 13: + $this->setCellphone($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = AddressColissimoPickupPointTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setTitleId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setCompany($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setFirstname($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setLastname($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setAddress1($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setAddress2($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setAddress3($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setZipcode($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setCity($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setCountryId($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setCode($arr[$keys[11]]); + if (array_key_exists($keys[12], $arr)) $this->setType($arr[$keys[12]]); + if (array_key_exists($keys[13], $arr)) $this->setCellphone($arr[$keys[13]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(AddressColissimoPickupPointTableMap::DATABASE_NAME); + + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ID)) $criteria->add(AddressColissimoPickupPointTableMap::ID, $this->id); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::TITLE_ID)) $criteria->add(AddressColissimoPickupPointTableMap::TITLE_ID, $this->title_id); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::COMPANY)) $criteria->add(AddressColissimoPickupPointTableMap::COMPANY, $this->company); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::FIRSTNAME)) $criteria->add(AddressColissimoPickupPointTableMap::FIRSTNAME, $this->firstname); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::LASTNAME)) $criteria->add(AddressColissimoPickupPointTableMap::LASTNAME, $this->lastname); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ADDRESS1)) $criteria->add(AddressColissimoPickupPointTableMap::ADDRESS1, $this->address1); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ADDRESS2)) $criteria->add(AddressColissimoPickupPointTableMap::ADDRESS2, $this->address2); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ADDRESS3)) $criteria->add(AddressColissimoPickupPointTableMap::ADDRESS3, $this->address3); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::ZIPCODE)) $criteria->add(AddressColissimoPickupPointTableMap::ZIPCODE, $this->zipcode); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::CITY)) $criteria->add(AddressColissimoPickupPointTableMap::CITY, $this->city); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::COUNTRY_ID)) $criteria->add(AddressColissimoPickupPointTableMap::COUNTRY_ID, $this->country_id); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::CODE)) $criteria->add(AddressColissimoPickupPointTableMap::CODE, $this->code); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::TYPE)) $criteria->add(AddressColissimoPickupPointTableMap::TYPE, $this->type); + if ($this->isColumnModified(AddressColissimoPickupPointTableMap::CELLPHONE)) $criteria->add(AddressColissimoPickupPointTableMap::CELLPHONE, $this->cellphone); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(AddressColissimoPickupPointTableMap::DATABASE_NAME); + $criteria->add(AddressColissimoPickupPointTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \ColissimoPickupPoint\Model\AddressColissimoPickupPoint (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setTitleId($this->getTitleId()); + $copyObj->setCompany($this->getCompany()); + $copyObj->setFirstname($this->getFirstname()); + $copyObj->setLastname($this->getLastname()); + $copyObj->setAddress1($this->getAddress1()); + $copyObj->setAddress2($this->getAddress2()); + $copyObj->setAddress3($this->getAddress3()); + $copyObj->setZipcode($this->getZipcode()); + $copyObj->setCity($this->getCity()); + $copyObj->setCountryId($this->getCountryId()); + $copyObj->setCode($this->getCode()); + $copyObj->setType($this->getType()); + $copyObj->setCellphone($this->getCellphone()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCustomerTitle object. + * + * @param ChildCustomerTitle $v + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + * @throws PropelException + */ + public function setCustomerTitle(ChildCustomerTitle $v = null) + { + if ($v === null) { + $this->setTitleId(NULL); + } else { + $this->setTitleId($v->getId()); + } + + $this->aCustomerTitle = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCustomerTitle object, it will not be re-added. + if ($v !== null) { + $v->addAddressColissimoPickupPoint($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCustomerTitle object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCustomerTitle The associated ChildCustomerTitle object. + * @throws PropelException + */ + public function getCustomerTitle(ConnectionInterface $con = null) + { + if ($this->aCustomerTitle === null && ($this->title_id !== null)) { + $this->aCustomerTitle = CustomerTitleQuery::create()->findPk($this->title_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCustomerTitle->addAddressColissimoPickupPoints($this); + */ + } + + return $this->aCustomerTitle; + } + + /** + * Declares an association between this object and a ChildCountry object. + * + * @param ChildCountry $v + * @return \ColissimoPickupPoint\Model\AddressColissimoPickupPoint The current object (for fluent API support) + * @throws PropelException + */ + public function setCountry(ChildCountry $v = null) + { + if ($v === null) { + $this->setCountryId(NULL); + } else { + $this->setCountryId($v->getId()); + } + + $this->aCountry = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCountry object, it will not be re-added. + if ($v !== null) { + $v->addAddressColissimoPickupPoint($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCountry object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCountry The associated ChildCountry object. + * @throws PropelException + */ + public function getCountry(ConnectionInterface $con = null) + { + if ($this->aCountry === null && ($this->country_id !== null)) { + $this->aCountry = CountryQuery::create()->findPk($this->country_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCountry->addAddressColissimoPickupPoints($this); + */ + } + + return $this->aCountry; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->title_id = null; + $this->company = null; + $this->firstname = null; + $this->lastname = null; + $this->address1 = null; + $this->address2 = null; + $this->address3 = null; + $this->zipcode = null; + $this->city = null; + $this->country_id = null; + $this->code = null; + $this->type = null; + $this->cellphone = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aCustomerTitle = null; + $this->aCountry = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(AddressColissimoPickupPointTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/local/modules/ColissimoPickupPoint/Model/Base/AddressColissimoPickupPointQuery.php b/local/modules/ColissimoPickupPoint/Model/Base/AddressColissimoPickupPointQuery.php new file mode 100644 index 00000000..5fde914b --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/AddressColissimoPickupPointQuery.php @@ -0,0 +1,964 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildAddressColissimoPickupPoint|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = AddressColissimoPickupPointTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildAddressColissimoPickupPoint A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, TITLE_ID, COMPANY, FIRSTNAME, LASTNAME, ADDRESS1, ADDRESS2, ADDRESS3, ZIPCODE, CITY, COUNTRY_ID, CODE, TYPE, CELLPHONE FROM address_colissimo_pickup_point WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildAddressColissimoPickupPoint(); + $obj->hydrate($row); + AddressColissimoPickupPointTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildAddressColissimoPickupPoint|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(AddressColissimoPickupPointTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(AddressColissimoPickupPointTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the title_id column + * + * Example usage: + * + * $query->filterByTitleId(1234); // WHERE title_id = 1234 + * $query->filterByTitleId(array(12, 34)); // WHERE title_id IN (12, 34) + * $query->filterByTitleId(array('min' => 12)); // WHERE title_id > 12 + * + * + * @see filterByCustomerTitle() + * + * @param mixed $titleId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByTitleId($titleId = null, $comparison = null) + { + if (is_array($titleId)) { + $useMinMax = false; + if (isset($titleId['min'])) { + $this->addUsingAlias(AddressColissimoPickupPointTableMap::TITLE_ID, $titleId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($titleId['max'])) { + $this->addUsingAlias(AddressColissimoPickupPointTableMap::TITLE_ID, $titleId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::TITLE_ID, $titleId, $comparison); + } + + /** + * Filter the query on the company column + * + * Example usage: + * + * $query->filterByCompany('fooValue'); // WHERE company = 'fooValue' + * $query->filterByCompany('%fooValue%'); // WHERE company LIKE '%fooValue%' + * + * + * @param string $company The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCompany($company = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($company)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $company)) { + $company = str_replace('*', '%', $company); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::COMPANY, $company, $comparison); + } + + /** + * Filter the query on the firstname column + * + * Example usage: + * + * $query->filterByFirstname('fooValue'); // WHERE firstname = 'fooValue' + * $query->filterByFirstname('%fooValue%'); // WHERE firstname LIKE '%fooValue%' + * + * + * @param string $firstname The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByFirstname($firstname = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($firstname)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $firstname)) { + $firstname = str_replace('*', '%', $firstname); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::FIRSTNAME, $firstname, $comparison); + } + + /** + * Filter the query on the lastname column + * + * Example usage: + * + * $query->filterByLastname('fooValue'); // WHERE lastname = 'fooValue' + * $query->filterByLastname('%fooValue%'); // WHERE lastname LIKE '%fooValue%' + * + * + * @param string $lastname The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByLastname($lastname = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($lastname)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $lastname)) { + $lastname = str_replace('*', '%', $lastname); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::LASTNAME, $lastname, $comparison); + } + + /** + * Filter the query on the address1 column + * + * Example usage: + * + * $query->filterByAddress1('fooValue'); // WHERE address1 = 'fooValue' + * $query->filterByAddress1('%fooValue%'); // WHERE address1 LIKE '%fooValue%' + * + * + * @param string $address1 The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByAddress1($address1 = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($address1)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $address1)) { + $address1 = str_replace('*', '%', $address1); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::ADDRESS1, $address1, $comparison); + } + + /** + * Filter the query on the address2 column + * + * Example usage: + * + * $query->filterByAddress2('fooValue'); // WHERE address2 = 'fooValue' + * $query->filterByAddress2('%fooValue%'); // WHERE address2 LIKE '%fooValue%' + * + * + * @param string $address2 The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByAddress2($address2 = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($address2)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $address2)) { + $address2 = str_replace('*', '%', $address2); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::ADDRESS2, $address2, $comparison); + } + + /** + * Filter the query on the address3 column + * + * Example usage: + * + * $query->filterByAddress3('fooValue'); // WHERE address3 = 'fooValue' + * $query->filterByAddress3('%fooValue%'); // WHERE address3 LIKE '%fooValue%' + * + * + * @param string $address3 The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByAddress3($address3 = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($address3)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $address3)) { + $address3 = str_replace('*', '%', $address3); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::ADDRESS3, $address3, $comparison); + } + + /** + * Filter the query on the zipcode column + * + * Example usage: + * + * $query->filterByZipcode('fooValue'); // WHERE zipcode = 'fooValue' + * $query->filterByZipcode('%fooValue%'); // WHERE zipcode LIKE '%fooValue%' + * + * + * @param string $zipcode The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByZipcode($zipcode = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($zipcode)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $zipcode)) { + $zipcode = str_replace('*', '%', $zipcode); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::ZIPCODE, $zipcode, $comparison); + } + + /** + * Filter the query on the city column + * + * Example usage: + * + * $query->filterByCity('fooValue'); // WHERE city = 'fooValue' + * $query->filterByCity('%fooValue%'); // WHERE city LIKE '%fooValue%' + * + * + * @param string $city The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCity($city = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($city)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $city)) { + $city = str_replace('*', '%', $city); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::CITY, $city, $comparison); + } + + /** + * Filter the query on the country_id column + * + * Example usage: + * + * $query->filterByCountryId(1234); // WHERE country_id = 1234 + * $query->filterByCountryId(array(12, 34)); // WHERE country_id IN (12, 34) + * $query->filterByCountryId(array('min' => 12)); // WHERE country_id > 12 + * + * + * @see filterByCountry() + * + * @param mixed $countryId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCountryId($countryId = null, $comparison = null) + { + if (is_array($countryId)) { + $useMinMax = false; + if (isset($countryId['min'])) { + $this->addUsingAlias(AddressColissimoPickupPointTableMap::COUNTRY_ID, $countryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($countryId['max'])) { + $this->addUsingAlias(AddressColissimoPickupPointTableMap::COUNTRY_ID, $countryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::COUNTRY_ID, $countryId, $comparison); + } + + /** + * Filter the query on the code column + * + * Example usage: + * + * $query->filterByCode('fooValue'); // WHERE code = 'fooValue' + * $query->filterByCode('%fooValue%'); // WHERE code LIKE '%fooValue%' + * + * + * @param string $code The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCode($code = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($code)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $code)) { + $code = str_replace('*', '%', $code); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::CODE, $code, $comparison); + } + + /** + * Filter the query on the type column + * + * Example usage: + * + * $query->filterByType('fooValue'); // WHERE type = 'fooValue' + * $query->filterByType('%fooValue%'); // WHERE type LIKE '%fooValue%' + * + * + * @param string $type The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByType($type = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($type)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $type)) { + $type = str_replace('*', '%', $type); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::TYPE, $type, $comparison); + } + + /** + * Filter the query on the cellphone column + * + * Example usage: + * + * $query->filterByCellphone('fooValue'); // WHERE cellphone = 'fooValue' + * $query->filterByCellphone('%fooValue%'); // WHERE cellphone LIKE '%fooValue%' + * + * + * @param string $cellphone The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCellphone($cellphone = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($cellphone)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $cellphone)) { + $cellphone = str_replace('*', '%', $cellphone); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(AddressColissimoPickupPointTableMap::CELLPHONE, $cellphone, $comparison); + } + + /** + * Filter the query by a related \ColissimoPickupPoint\Model\Thelia\Model\CustomerTitle object + * + * @param \ColissimoPickupPoint\Model\Thelia\Model\CustomerTitle|ObjectCollection $customerTitle The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCustomerTitle($customerTitle, $comparison = null) + { + if ($customerTitle instanceof \ColissimoPickupPoint\Model\Thelia\Model\CustomerTitle) { + return $this + ->addUsingAlias(AddressColissimoPickupPointTableMap::TITLE_ID, $customerTitle->getId(), $comparison); + } elseif ($customerTitle instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(AddressColissimoPickupPointTableMap::TITLE_ID, $customerTitle->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCustomerTitle() only accepts arguments of type \ColissimoPickupPoint\Model\Thelia\Model\CustomerTitle or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CustomerTitle relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function joinCustomerTitle($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CustomerTitle'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CustomerTitle'); + } + + return $this; + } + + /** + * Use the CustomerTitle relation CustomerTitle object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \ColissimoPickupPoint\Model\Thelia\Model\CustomerTitleQuery A secondary query class using the current class as primary query + */ + public function useCustomerTitleQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCustomerTitle($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CustomerTitle', '\ColissimoPickupPoint\Model\Thelia\Model\CustomerTitleQuery'); + } + + /** + * Filter the query by a related \ColissimoPickupPoint\Model\Thelia\Model\Country object + * + * @param \ColissimoPickupPoint\Model\Thelia\Model\Country|ObjectCollection $country The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCountry($country, $comparison = null) + { + if ($country instanceof \ColissimoPickupPoint\Model\Thelia\Model\Country) { + return $this + ->addUsingAlias(AddressColissimoPickupPointTableMap::COUNTRY_ID, $country->getId(), $comparison); + } elseif ($country instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(AddressColissimoPickupPointTableMap::COUNTRY_ID, $country->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCountry() only accepts arguments of type \ColissimoPickupPoint\Model\Thelia\Model\Country or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Country relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function joinCountry($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Country'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Country'); + } + + return $this; + } + + /** + * Use the Country relation Country object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \ColissimoPickupPoint\Model\Thelia\Model\CountryQuery A secondary query class using the current class as primary query + */ + public function useCountryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCountry($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Country', '\ColissimoPickupPoint\Model\Thelia\Model\CountryQuery'); + } + + /** + * Exclude object from result + * + * @param ChildAddressColissimoPickupPoint $addressColissimoPickupPoint Object to remove from the list of results + * + * @return ChildAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function prune($addressColissimoPickupPoint = null) + { + if ($addressColissimoPickupPoint) { + $this->addUsingAlias(AddressColissimoPickupPointTableMap::ID, $addressColissimoPickupPoint->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the address_colissimo_pickup_point table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + AddressColissimoPickupPointTableMap::clearInstancePool(); + AddressColissimoPickupPointTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildAddressColissimoPickupPoint or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildAddressColissimoPickupPoint object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(AddressColissimoPickupPointTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + AddressColissimoPickupPointTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + AddressColissimoPickupPointTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // AddressColissimoPickupPointQuery diff --git a/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointAreaFreeshipping.php b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointAreaFreeshipping.php new file mode 100644 index 00000000..d51ecd8a --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointAreaFreeshipping.php @@ -0,0 +1,1272 @@ +cart_amount = '0.00'; + } + + /** + * Initializes internal state of ColissimoPickupPoint\Model\Base\ColissimoPickupPointAreaFreeshipping object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ColissimoPickupPointAreaFreeshipping instance. If + * obj is an instance of ColissimoPickupPointAreaFreeshipping, delegates to + * equals(ColissimoPickupPointAreaFreeshipping). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ColissimoPickupPointAreaFreeshipping The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ColissimoPickupPointAreaFreeshipping The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [area_id] column value. + * + * @return int + */ + public function getAreaId() + { + + return $this->area_id; + } + + /** + * Get the [cart_amount] column value. + * + * @return string + */ + public function getCartAmount() + { + + return $this->cart_amount; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ColissimoPickupPointAreaFreeshippingTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [area_id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping The current object (for fluent API support) + */ + public function setAreaId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->area_id !== $v) { + $this->area_id = $v; + $this->modifiedColumns[ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID] = true; + } + + if ($this->aArea !== null && $this->aArea->getId() !== $v) { + $this->aArea = null; + } + + + return $this; + } // setAreaId() + + /** + * Set the value of [cart_amount] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping The current object (for fluent API support) + */ + public function setCartAmount($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->cart_amount !== $v) { + $this->cart_amount = $v; + $this->modifiedColumns[ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT] = true; + } + + + return $this; + } // setCartAmount() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->cart_amount !== '0.00') { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ColissimoPickupPointAreaFreeshippingTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ColissimoPickupPointAreaFreeshippingTableMap::translateFieldName('AreaId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->area_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ColissimoPickupPointAreaFreeshippingTableMap::translateFieldName('CartAmount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->cart_amount = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = ColissimoPickupPointAreaFreeshippingTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aArea !== null && $this->area_id !== $this->aArea->getId()) { + $this->aArea = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildColissimoPickupPointAreaFreeshippingQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aArea = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ColissimoPickupPointAreaFreeshipping::setDeleted() + * @see ColissimoPickupPointAreaFreeshipping::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildColissimoPickupPointAreaFreeshippingQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ColissimoPickupPointAreaFreeshippingTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aArea !== null) { + if ($this->aArea->isModified() || $this->aArea->isNew()) { + $affectedRows += $this->aArea->save($con); + } + $this->setArea($this->aArea); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[ColissimoPickupPointAreaFreeshippingTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ColissimoPickupPointAreaFreeshippingTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ColissimoPickupPointAreaFreeshippingTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID)) { + $modifiedColumns[':p' . $index++] = 'AREA_ID'; + } + if ($this->isColumnModified(ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT)) { + $modifiedColumns[':p' . $index++] = 'CART_AMOUNT'; + } + + $sql = sprintf( + 'INSERT INTO colissimo_pickup_point_area_freeshipping (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'AREA_ID': + $stmt->bindValue($identifier, $this->area_id, PDO::PARAM_INT); + break; + case 'CART_AMOUNT': + $stmt->bindValue($identifier, $this->cart_amount, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ColissimoPickupPointAreaFreeshippingTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getAreaId(); + break; + case 2: + return $this->getCartAmount(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ColissimoPickupPointAreaFreeshipping'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ColissimoPickupPointAreaFreeshipping'][$this->getPrimaryKey()] = true; + $keys = ColissimoPickupPointAreaFreeshippingTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getAreaId(), + $keys[2] => $this->getCartAmount(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aArea) { + $result['Area'] = $this->aArea->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ColissimoPickupPointAreaFreeshippingTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setAreaId($value); + break; + case 2: + $this->setCartAmount($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ColissimoPickupPointAreaFreeshippingTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setAreaId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setCartAmount($arr[$keys[2]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ColissimoPickupPointAreaFreeshippingTableMap::ID)) $criteria->add(ColissimoPickupPointAreaFreeshippingTableMap::ID, $this->id); + if ($this->isColumnModified(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID)) $criteria->add(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID, $this->area_id); + if ($this->isColumnModified(ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT)) $criteria->add(ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT, $this->cart_amount); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + $criteria->add(ColissimoPickupPointAreaFreeshippingTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setAreaId($this->getAreaId()); + $copyObj->setCartAmount($this->getCartAmount()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildArea object. + * + * @param ChildArea $v + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping The current object (for fluent API support) + * @throws PropelException + */ + public function setArea(ChildArea $v = null) + { + if ($v === null) { + $this->setAreaId(NULL); + } else { + $this->setAreaId($v->getId()); + } + + $this->aArea = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildArea object, it will not be re-added. + if ($v !== null) { + $v->addColissimoPickupPointAreaFreeshipping($this); + } + + + return $this; + } + + + /** + * Get the associated ChildArea object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildArea The associated ChildArea object. + * @throws PropelException + */ + public function getArea(ConnectionInterface $con = null) + { + if ($this->aArea === null && ($this->area_id !== null)) { + $this->aArea = AreaQuery::create()->findPk($this->area_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aArea->addColissimoPickupPointAreaFreeshippings($this); + */ + } + + return $this->aArea; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->area_id = null; + $this->cart_amount = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aArea = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ColissimoPickupPointAreaFreeshippingTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointAreaFreeshippingQuery.php b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointAreaFreeshippingQuery.php new file mode 100644 index 00000000..eafcfcaf --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointAreaFreeshippingQuery.php @@ -0,0 +1,519 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildColissimoPickupPointAreaFreeshipping|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ColissimoPickupPointAreaFreeshippingTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildColissimoPickupPointAreaFreeshipping A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, AREA_ID, CART_AMOUNT FROM colissimo_pickup_point_area_freeshipping WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildColissimoPickupPointAreaFreeshipping(); + $obj->hydrate($row); + ColissimoPickupPointAreaFreeshippingTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildColissimoPickupPointAreaFreeshipping|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the area_id column + * + * Example usage: + * + * $query->filterByAreaId(1234); // WHERE area_id = 1234 + * $query->filterByAreaId(array(12, 34)); // WHERE area_id IN (12, 34) + * $query->filterByAreaId(array('min' => 12)); // WHERE area_id > 12 + * + * + * @see filterByArea() + * + * @param mixed $areaId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function filterByAreaId($areaId = null, $comparison = null) + { + if (is_array($areaId)) { + $useMinMax = false; + if (isset($areaId['min'])) { + $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID, $areaId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($areaId['max'])) { + $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID, $areaId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID, $areaId, $comparison); + } + + /** + * Filter the query on the cart_amount column + * + * Example usage: + * + * $query->filterByCartAmount(1234); // WHERE cart_amount = 1234 + * $query->filterByCartAmount(array(12, 34)); // WHERE cart_amount IN (12, 34) + * $query->filterByCartAmount(array('min' => 12)); // WHERE cart_amount > 12 + * + * + * @param mixed $cartAmount The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function filterByCartAmount($cartAmount = null, $comparison = null) + { + if (is_array($cartAmount)) { + $useMinMax = false; + if (isset($cartAmount['min'])) { + $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT, $cartAmount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($cartAmount['max'])) { + $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT, $cartAmount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT, $cartAmount, $comparison); + } + + /** + * Filter the query by a related \ColissimoPickupPoint\Model\Thelia\Model\Area object + * + * @param \ColissimoPickupPoint\Model\Thelia\Model\Area|ObjectCollection $area The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function filterByArea($area, $comparison = null) + { + if ($area instanceof \ColissimoPickupPoint\Model\Thelia\Model\Area) { + return $this + ->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID, $area->getId(), $comparison); + } elseif ($area instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID, $area->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByArea() only accepts arguments of type \ColissimoPickupPoint\Model\Thelia\Model\Area or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Area relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function joinArea($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Area'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Area'); + } + + return $this; + } + + /** + * Use the Area relation Area object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \ColissimoPickupPoint\Model\Thelia\Model\AreaQuery A secondary query class using the current class as primary query + */ + public function useAreaQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinArea($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Area', '\ColissimoPickupPoint\Model\Thelia\Model\AreaQuery'); + } + + /** + * Exclude object from result + * + * @param ChildColissimoPickupPointAreaFreeshipping $colissimoPickupPointAreaFreeshipping Object to remove from the list of results + * + * @return ChildColissimoPickupPointAreaFreeshippingQuery The current query, for fluid interface + */ + public function prune($colissimoPickupPointAreaFreeshipping = null) + { + if ($colissimoPickupPointAreaFreeshipping) { + $this->addUsingAlias(ColissimoPickupPointAreaFreeshippingTableMap::ID, $colissimoPickupPointAreaFreeshipping->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the colissimo_pickup_point_area_freeshipping table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ColissimoPickupPointAreaFreeshippingTableMap::clearInstancePool(); + ColissimoPickupPointAreaFreeshippingTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildColissimoPickupPointAreaFreeshipping or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildColissimoPickupPointAreaFreeshipping object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ColissimoPickupPointAreaFreeshippingTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ColissimoPickupPointAreaFreeshippingTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // ColissimoPickupPointAreaFreeshippingQuery diff --git a/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointFreeshipping.php b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointFreeshipping.php new file mode 100644 index 00000000..22c1c039 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointFreeshipping.php @@ -0,0 +1,1184 @@ +active = false; + } + + /** + * Initializes internal state of ColissimoPickupPoint\Model\Base\ColissimoPickupPointFreeshipping object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ColissimoPickupPointFreeshipping instance. If + * obj is an instance of ColissimoPickupPointFreeshipping, delegates to + * equals(ColissimoPickupPointFreeshipping). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ColissimoPickupPointFreeshipping The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ColissimoPickupPointFreeshipping The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [active] column value. + * + * @return boolean + */ + public function getActive() + { + + return $this->active; + } + + /** + * Get the [freeshipping_from] column value. + * + * @return string + */ + public function getFreeshippingFrom() + { + + return $this->freeshipping_from; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ColissimoPickupPointFreeshippingTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Sets the value of the [active] column. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * + * @param boolean|integer|string $v The new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping The current object (for fluent API support) + */ + public function setActive($v) + { + if ($v !== null) { + if (is_string($v)) { + $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } else { + $v = (boolean) $v; + } + } + + if ($this->active !== $v) { + $this->active = $v; + $this->modifiedColumns[ColissimoPickupPointFreeshippingTableMap::ACTIVE] = true; + } + + + return $this; + } // setActive() + + /** + * Set the value of [freeshipping_from] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping The current object (for fluent API support) + */ + public function setFreeshippingFrom($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->freeshipping_from !== $v) { + $this->freeshipping_from = $v; + $this->modifiedColumns[ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM] = true; + } + + + return $this; + } // setFreeshippingFrom() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->active !== false) { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ColissimoPickupPointFreeshippingTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ColissimoPickupPointFreeshippingTableMap::translateFieldName('Active', TableMap::TYPE_PHPNAME, $indexType)]; + $this->active = (null !== $col) ? (boolean) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ColissimoPickupPointFreeshippingTableMap::translateFieldName('FreeshippingFrom', TableMap::TYPE_PHPNAME, $indexType)]; + $this->freeshipping_from = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = ColissimoPickupPointFreeshippingTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildColissimoPickupPointFreeshippingQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ColissimoPickupPointFreeshipping::setDeleted() + * @see ColissimoPickupPointFreeshipping::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildColissimoPickupPointFreeshippingQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ColissimoPickupPointFreeshippingTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ColissimoPickupPointFreeshippingTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(ColissimoPickupPointFreeshippingTableMap::ACTIVE)) { + $modifiedColumns[':p' . $index++] = 'ACTIVE'; + } + if ($this->isColumnModified(ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM)) { + $modifiedColumns[':p' . $index++] = 'FREESHIPPING_FROM'; + } + + $sql = sprintf( + 'INSERT INTO colissimo_pickup_point_freeshipping (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'ACTIVE': + $stmt->bindValue($identifier, (int) $this->active, PDO::PARAM_INT); + break; + case 'FREESHIPPING_FROM': + $stmt->bindValue($identifier, $this->freeshipping_from, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ColissimoPickupPointFreeshippingTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getActive(); + break; + case 2: + return $this->getFreeshippingFrom(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array()) + { + if (isset($alreadyDumpedObjects['ColissimoPickupPointFreeshipping'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ColissimoPickupPointFreeshipping'][$this->getPrimaryKey()] = true; + $keys = ColissimoPickupPointFreeshippingTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getActive(), + $keys[2] => $this->getFreeshippingFrom(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ColissimoPickupPointFreeshippingTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setActive($value); + break; + case 2: + $this->setFreeshippingFrom($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ColissimoPickupPointFreeshippingTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setActive($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setFreeshippingFrom($arr[$keys[2]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ColissimoPickupPointFreeshippingTableMap::ID)) $criteria->add(ColissimoPickupPointFreeshippingTableMap::ID, $this->id); + if ($this->isColumnModified(ColissimoPickupPointFreeshippingTableMap::ACTIVE)) $criteria->add(ColissimoPickupPointFreeshippingTableMap::ACTIVE, $this->active); + if ($this->isColumnModified(ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM)) $criteria->add(ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM, $this->freeshipping_from); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + $criteria->add(ColissimoPickupPointFreeshippingTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setActive($this->getActive()); + $copyObj->setFreeshippingFrom($this->getFreeshippingFrom()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->active = null; + $this->freeshipping_from = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ColissimoPickupPointFreeshippingTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointFreeshippingQuery.php b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointFreeshippingQuery.php new file mode 100644 index 00000000..f9121ba8 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointFreeshippingQuery.php @@ -0,0 +1,420 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildColissimoPickupPointFreeshipping|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ColissimoPickupPointFreeshippingTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildColissimoPickupPointFreeshipping A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, ACTIVE, FREESHIPPING_FROM FROM colissimo_pickup_point_freeshipping WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildColissimoPickupPointFreeshipping(); + $obj->hydrate($row); + ColissimoPickupPointFreeshippingTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildColissimoPickupPointFreeshipping|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildColissimoPickupPointFreeshippingQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildColissimoPickupPointFreeshippingQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointFreeshippingQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the active column + * + * Example usage: + * + * $query->filterByActive(true); // WHERE active = true + * $query->filterByActive('yes'); // WHERE active = true + * + * + * @param boolean|string $active The value to use as filter. + * Non-boolean arguments are converted using the following rules: + * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true + * * 0, '0', 'false', 'off', and 'no' are converted to boolean false + * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointFreeshippingQuery The current query, for fluid interface + */ + public function filterByActive($active = null, $comparison = null) + { + if (is_string($active)) { + $active = in_array(strtolower($active), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; + } + + return $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::ACTIVE, $active, $comparison); + } + + /** + * Filter the query on the freeshipping_from column + * + * Example usage: + * + * $query->filterByFreeshippingFrom(1234); // WHERE freeshipping_from = 1234 + * $query->filterByFreeshippingFrom(array(12, 34)); // WHERE freeshipping_from IN (12, 34) + * $query->filterByFreeshippingFrom(array('min' => 12)); // WHERE freeshipping_from > 12 + * + * + * @param mixed $freeshippingFrom The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointFreeshippingQuery The current query, for fluid interface + */ + public function filterByFreeshippingFrom($freeshippingFrom = null, $comparison = null) + { + if (is_array($freeshippingFrom)) { + $useMinMax = false; + if (isset($freeshippingFrom['min'])) { + $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM, $freeshippingFrom['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($freeshippingFrom['max'])) { + $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM, $freeshippingFrom['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM, $freeshippingFrom, $comparison); + } + + /** + * Exclude object from result + * + * @param ChildColissimoPickupPointFreeshipping $colissimoPickupPointFreeshipping Object to remove from the list of results + * + * @return ChildColissimoPickupPointFreeshippingQuery The current query, for fluid interface + */ + public function prune($colissimoPickupPointFreeshipping = null) + { + if ($colissimoPickupPointFreeshipping) { + $this->addUsingAlias(ColissimoPickupPointFreeshippingTableMap::ID, $colissimoPickupPointFreeshipping->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the colissimo_pickup_point_freeshipping table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ColissimoPickupPointFreeshippingTableMap::clearInstancePool(); + ColissimoPickupPointFreeshippingTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildColissimoPickupPointFreeshipping or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildColissimoPickupPointFreeshipping object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ColissimoPickupPointFreeshippingTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ColissimoPickupPointFreeshippingTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // ColissimoPickupPointFreeshippingQuery diff --git a/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointPriceSlices.php b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointPriceSlices.php new file mode 100644 index 00000000..e308c628 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointPriceSlices.php @@ -0,0 +1,1427 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ColissimoPickupPointPriceSlices instance. If + * obj is an instance of ColissimoPickupPointPriceSlices, delegates to + * equals(ColissimoPickupPointPriceSlices). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ColissimoPickupPointPriceSlices The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ColissimoPickupPointPriceSlices The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [area_id] column value. + * + * @return int + */ + public function getAreaId() + { + + return $this->area_id; + } + + /** + * Get the [weight_max] column value. + * + * @return double + */ + public function getWeightMax() + { + + return $this->weight_max; + } + + /** + * Get the [price_max] column value. + * + * @return double + */ + public function getPriceMax() + { + + return $this->price_max; + } + + /** + * Get the [franco_min_price] column value. + * + * @return double + */ + public function getFrancoMinPrice() + { + + return $this->franco_min_price; + } + + /** + * Get the [price] column value. + * + * @return double + */ + public function getPrice() + { + + return $this->price; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ColissimoPickupPointPriceSlicesTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [area_id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices The current object (for fluent API support) + */ + public function setAreaId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->area_id !== $v) { + $this->area_id = $v; + $this->modifiedColumns[ColissimoPickupPointPriceSlicesTableMap::AREA_ID] = true; + } + + if ($this->aArea !== null && $this->aArea->getId() !== $v) { + $this->aArea = null; + } + + + return $this; + } // setAreaId() + + /** + * Set the value of [weight_max] column. + * + * @param double $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices The current object (for fluent API support) + */ + public function setWeightMax($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->weight_max !== $v) { + $this->weight_max = $v; + $this->modifiedColumns[ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX] = true; + } + + + return $this; + } // setWeightMax() + + /** + * Set the value of [price_max] column. + * + * @param double $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices The current object (for fluent API support) + */ + public function setPriceMax($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->price_max !== $v) { + $this->price_max = $v; + $this->modifiedColumns[ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX] = true; + } + + + return $this; + } // setPriceMax() + + /** + * Set the value of [franco_min_price] column. + * + * @param double $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices The current object (for fluent API support) + */ + public function setFrancoMinPrice($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->franco_min_price !== $v) { + $this->franco_min_price = $v; + $this->modifiedColumns[ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE] = true; + } + + + return $this; + } // setFrancoMinPrice() + + /** + * Set the value of [price] column. + * + * @param double $v new value + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices The current object (for fluent API support) + */ + public function setPrice($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->price !== $v) { + $this->price = $v; + $this->modifiedColumns[ColissimoPickupPointPriceSlicesTableMap::PRICE] = true; + } + + + return $this; + } // setPrice() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ColissimoPickupPointPriceSlicesTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ColissimoPickupPointPriceSlicesTableMap::translateFieldName('AreaId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->area_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ColissimoPickupPointPriceSlicesTableMap::translateFieldName('WeightMax', TableMap::TYPE_PHPNAME, $indexType)]; + $this->weight_max = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ColissimoPickupPointPriceSlicesTableMap::translateFieldName('PriceMax', TableMap::TYPE_PHPNAME, $indexType)]; + $this->price_max = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ColissimoPickupPointPriceSlicesTableMap::translateFieldName('FrancoMinPrice', TableMap::TYPE_PHPNAME, $indexType)]; + $this->franco_min_price = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ColissimoPickupPointPriceSlicesTableMap::translateFieldName('Price', TableMap::TYPE_PHPNAME, $indexType)]; + $this->price = (null !== $col) ? (double) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 6; // 6 = ColissimoPickupPointPriceSlicesTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aArea !== null && $this->area_id !== $this->aArea->getId()) { + $this->aArea = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildColissimoPickupPointPriceSlicesQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aArea = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ColissimoPickupPointPriceSlices::setDeleted() + * @see ColissimoPickupPointPriceSlices::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildColissimoPickupPointPriceSlicesQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ColissimoPickupPointPriceSlicesTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aArea !== null) { + if ($this->aArea->isModified() || $this->aArea->isNew()) { + $affectedRows += $this->aArea->save($con); + } + $this->setArea($this->aArea); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[ColissimoPickupPointPriceSlicesTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ColissimoPickupPointPriceSlicesTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::AREA_ID)) { + $modifiedColumns[':p' . $index++] = 'AREA_ID'; + } + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX)) { + $modifiedColumns[':p' . $index++] = 'WEIGHT_MAX'; + } + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX)) { + $modifiedColumns[':p' . $index++] = 'PRICE_MAX'; + } + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE)) { + $modifiedColumns[':p' . $index++] = 'FRANCO_MIN_PRICE'; + } + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::PRICE)) { + $modifiedColumns[':p' . $index++] = 'PRICE'; + } + + $sql = sprintf( + 'INSERT INTO colissimo_pickup_point_price_slices (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'AREA_ID': + $stmt->bindValue($identifier, $this->area_id, PDO::PARAM_INT); + break; + case 'WEIGHT_MAX': + $stmt->bindValue($identifier, $this->weight_max, PDO::PARAM_STR); + break; + case 'PRICE_MAX': + $stmt->bindValue($identifier, $this->price_max, PDO::PARAM_STR); + break; + case 'FRANCO_MIN_PRICE': + $stmt->bindValue($identifier, $this->franco_min_price, PDO::PARAM_STR); + break; + case 'PRICE': + $stmt->bindValue($identifier, $this->price, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ColissimoPickupPointPriceSlicesTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getAreaId(); + break; + case 2: + return $this->getWeightMax(); + break; + case 3: + return $this->getPriceMax(); + break; + case 4: + return $this->getFrancoMinPrice(); + break; + case 5: + return $this->getPrice(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ColissimoPickupPointPriceSlices'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ColissimoPickupPointPriceSlices'][$this->getPrimaryKey()] = true; + $keys = ColissimoPickupPointPriceSlicesTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getAreaId(), + $keys[2] => $this->getWeightMax(), + $keys[3] => $this->getPriceMax(), + $keys[4] => $this->getFrancoMinPrice(), + $keys[5] => $this->getPrice(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aArea) { + $result['Area'] = $this->aArea->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ColissimoPickupPointPriceSlicesTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setAreaId($value); + break; + case 2: + $this->setWeightMax($value); + break; + case 3: + $this->setPriceMax($value); + break; + case 4: + $this->setFrancoMinPrice($value); + break; + case 5: + $this->setPrice($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ColissimoPickupPointPriceSlicesTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setAreaId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setWeightMax($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setPriceMax($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setFrancoMinPrice($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setPrice($arr[$keys[5]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::ID)) $criteria->add(ColissimoPickupPointPriceSlicesTableMap::ID, $this->id); + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::AREA_ID)) $criteria->add(ColissimoPickupPointPriceSlicesTableMap::AREA_ID, $this->area_id); + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX)) $criteria->add(ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX, $this->weight_max); + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX)) $criteria->add(ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX, $this->price_max); + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE)) $criteria->add(ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE, $this->franco_min_price); + if ($this->isColumnModified(ColissimoPickupPointPriceSlicesTableMap::PRICE)) $criteria->add(ColissimoPickupPointPriceSlicesTableMap::PRICE, $this->price); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + $criteria->add(ColissimoPickupPointPriceSlicesTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setAreaId($this->getAreaId()); + $copyObj->setWeightMax($this->getWeightMax()); + $copyObj->setPriceMax($this->getPriceMax()); + $copyObj->setFrancoMinPrice($this->getFrancoMinPrice()); + $copyObj->setPrice($this->getPrice()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildArea object. + * + * @param ChildArea $v + * @return \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices The current object (for fluent API support) + * @throws PropelException + */ + public function setArea(ChildArea $v = null) + { + if ($v === null) { + $this->setAreaId(NULL); + } else { + $this->setAreaId($v->getId()); + } + + $this->aArea = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildArea object, it will not be re-added. + if ($v !== null) { + $v->addColissimoPickupPointPriceSlices($this); + } + + + return $this; + } + + + /** + * Get the associated ChildArea object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildArea The associated ChildArea object. + * @throws PropelException + */ + public function getArea(ConnectionInterface $con = null) + { + if ($this->aArea === null && ($this->area_id !== null)) { + $this->aArea = AreaQuery::create()->findPk($this->area_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aArea->addColissimoPickupPointPriceSlicess($this); + */ + } + + return $this->aArea; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->area_id = null; + $this->weight_max = null; + $this->price_max = null; + $this->franco_min_price = null; + $this->price = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aArea = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ColissimoPickupPointPriceSlicesTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointPriceSlicesQuery.php b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointPriceSlicesQuery.php new file mode 100644 index 00000000..ded790ea --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/ColissimoPickupPointPriceSlicesQuery.php @@ -0,0 +1,654 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildColissimoPickupPointPriceSlices|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ColissimoPickupPointPriceSlicesTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildColissimoPickupPointPriceSlices A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, AREA_ID, WEIGHT_MAX, PRICE_MAX, FRANCO_MIN_PRICE, PRICE FROM colissimo_pickup_point_price_slices WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildColissimoPickupPointPriceSlices(); + $obj->hydrate($row); + ColissimoPickupPointPriceSlicesTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildColissimoPickupPointPriceSlices|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the area_id column + * + * Example usage: + * + * $query->filterByAreaId(1234); // WHERE area_id = 1234 + * $query->filterByAreaId(array(12, 34)); // WHERE area_id IN (12, 34) + * $query->filterByAreaId(array('min' => 12)); // WHERE area_id > 12 + * + * + * @see filterByArea() + * + * @param mixed $areaId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByAreaId($areaId = null, $comparison = null) + { + if (is_array($areaId)) { + $useMinMax = false; + if (isset($areaId['min'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::AREA_ID, $areaId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($areaId['max'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::AREA_ID, $areaId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::AREA_ID, $areaId, $comparison); + } + + /** + * Filter the query on the weight_max column + * + * Example usage: + * + * $query->filterByWeightMax(1234); // WHERE weight_max = 1234 + * $query->filterByWeightMax(array(12, 34)); // WHERE weight_max IN (12, 34) + * $query->filterByWeightMax(array('min' => 12)); // WHERE weight_max > 12 + * + * + * @param mixed $weightMax The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByWeightMax($weightMax = null, $comparison = null) + { + if (is_array($weightMax)) { + $useMinMax = false; + if (isset($weightMax['min'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX, $weightMax['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($weightMax['max'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX, $weightMax['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX, $weightMax, $comparison); + } + + /** + * Filter the query on the price_max column + * + * Example usage: + * + * $query->filterByPriceMax(1234); // WHERE price_max = 1234 + * $query->filterByPriceMax(array(12, 34)); // WHERE price_max IN (12, 34) + * $query->filterByPriceMax(array('min' => 12)); // WHERE price_max > 12 + * + * + * @param mixed $priceMax The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByPriceMax($priceMax = null, $comparison = null) + { + if (is_array($priceMax)) { + $useMinMax = false; + if (isset($priceMax['min'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX, $priceMax['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($priceMax['max'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX, $priceMax['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX, $priceMax, $comparison); + } + + /** + * Filter the query on the franco_min_price column + * + * Example usage: + * + * $query->filterByFrancoMinPrice(1234); // WHERE franco_min_price = 1234 + * $query->filterByFrancoMinPrice(array(12, 34)); // WHERE franco_min_price IN (12, 34) + * $query->filterByFrancoMinPrice(array('min' => 12)); // WHERE franco_min_price > 12 + * + * + * @param mixed $francoMinPrice The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByFrancoMinPrice($francoMinPrice = null, $comparison = null) + { + if (is_array($francoMinPrice)) { + $useMinMax = false; + if (isset($francoMinPrice['min'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE, $francoMinPrice['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($francoMinPrice['max'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE, $francoMinPrice['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE, $francoMinPrice, $comparison); + } + + /** + * Filter the query on the price column + * + * Example usage: + * + * $query->filterByPrice(1234); // WHERE price = 1234 + * $query->filterByPrice(array(12, 34)); // WHERE price IN (12, 34) + * $query->filterByPrice(array('min' => 12)); // WHERE price > 12 + * + * + * @param mixed $price The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByPrice($price = null, $comparison = null) + { + if (is_array($price)) { + $useMinMax = false; + if (isset($price['min'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::PRICE, $price['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($price['max'])) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::PRICE, $price['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::PRICE, $price, $comparison); + } + + /** + * Filter the query by a related \ColissimoPickupPoint\Model\Thelia\Model\Area object + * + * @param \ColissimoPickupPoint\Model\Thelia\Model\Area|ObjectCollection $area The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function filterByArea($area, $comparison = null) + { + if ($area instanceof \ColissimoPickupPoint\Model\Thelia\Model\Area) { + return $this + ->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::AREA_ID, $area->getId(), $comparison); + } elseif ($area instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::AREA_ID, $area->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByArea() only accepts arguments of type \ColissimoPickupPoint\Model\Thelia\Model\Area or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Area relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function joinArea($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Area'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Area'); + } + + return $this; + } + + /** + * Use the Area relation Area object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \ColissimoPickupPoint\Model\Thelia\Model\AreaQuery A secondary query class using the current class as primary query + */ + public function useAreaQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinArea($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Area', '\ColissimoPickupPoint\Model\Thelia\Model\AreaQuery'); + } + + /** + * Exclude object from result + * + * @param ChildColissimoPickupPointPriceSlices $colissimoPickupPointPriceSlices Object to remove from the list of results + * + * @return ChildColissimoPickupPointPriceSlicesQuery The current query, for fluid interface + */ + public function prune($colissimoPickupPointPriceSlices = null) + { + if ($colissimoPickupPointPriceSlices) { + $this->addUsingAlias(ColissimoPickupPointPriceSlicesTableMap::ID, $colissimoPickupPointPriceSlices->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the colissimo_pickup_point_price_slices table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ColissimoPickupPointPriceSlicesTableMap::clearInstancePool(); + ColissimoPickupPointPriceSlicesTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildColissimoPickupPointPriceSlices or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildColissimoPickupPointPriceSlices object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ColissimoPickupPointPriceSlicesTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ColissimoPickupPointPriceSlicesTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // ColissimoPickupPointPriceSlicesQuery diff --git a/local/modules/ColissimoPickupPoint/Model/Base/OrderAddressColissimoPickupPoint.php b/local/modules/ColissimoPickupPoint/Model/Base/OrderAddressColissimoPickupPoint.php new file mode 100644 index 00000000..fb4fa11a --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/OrderAddressColissimoPickupPoint.php @@ -0,0 +1,1236 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another OrderAddressColissimoPickupPoint instance. If + * obj is an instance of OrderAddressColissimoPickupPoint, delegates to + * equals(OrderAddressColissimoPickupPoint). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return OrderAddressColissimoPickupPoint The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return OrderAddressColissimoPickupPoint The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [code] column value. + * + * @return string + */ + public function getCode() + { + + return $this->code; + } + + /** + * Get the [type] column value. + * + * @return string + */ + public function getType() + { + + return $this->type; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[OrderAddressColissimoPickupPointTableMap::ID] = true; + } + + if ($this->aOrderAddress !== null && $this->aOrderAddress->getId() !== $v) { + $this->aOrderAddress = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [code] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setCode($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->code !== $v) { + $this->code = $v; + $this->modifiedColumns[OrderAddressColissimoPickupPointTableMap::CODE] = true; + } + + + return $this; + } // setCode() + + /** + * Set the value of [type] column. + * + * @param string $v new value + * @return \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint The current object (for fluent API support) + */ + public function setType($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->type !== $v) { + $this->type = $v; + $this->modifiedColumns[OrderAddressColissimoPickupPointTableMap::TYPE] = true; + } + + + return $this; + } // setType() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : OrderAddressColissimoPickupPointTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : OrderAddressColissimoPickupPointTableMap::translateFieldName('Code', TableMap::TYPE_PHPNAME, $indexType)]; + $this->code = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : OrderAddressColissimoPickupPointTableMap::translateFieldName('Type', TableMap::TYPE_PHPNAME, $indexType)]; + $this->type = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = OrderAddressColissimoPickupPointTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aOrderAddress !== null && $this->id !== $this->aOrderAddress->getId()) { + $this->aOrderAddress = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildOrderAddressColissimoPickupPointQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aOrderAddress = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see OrderAddressColissimoPickupPoint::setDeleted() + * @see OrderAddressColissimoPickupPoint::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildOrderAddressColissimoPickupPointQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + OrderAddressColissimoPickupPointTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aOrderAddress !== null) { + if ($this->aOrderAddress->isModified() || $this->aOrderAddress->isNew()) { + $affectedRows += $this->aOrderAddress->save($con); + } + $this->setOrderAddress($this->aOrderAddress); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(OrderAddressColissimoPickupPointTableMap::ID)) { + $modifiedColumns[':p' . $index++] = 'ID'; + } + if ($this->isColumnModified(OrderAddressColissimoPickupPointTableMap::CODE)) { + $modifiedColumns[':p' . $index++] = 'CODE'; + } + if ($this->isColumnModified(OrderAddressColissimoPickupPointTableMap::TYPE)) { + $modifiedColumns[':p' . $index++] = 'TYPE'; + } + + $sql = sprintf( + 'INSERT INTO order_address_colissimo_pickup_point (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'ID': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'CODE': + $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR); + break; + case 'TYPE': + $stmt->bindValue($identifier, $this->type, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = OrderAddressColissimoPickupPointTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getCode(); + break; + case 2: + return $this->getType(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['OrderAddressColissimoPickupPoint'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['OrderAddressColissimoPickupPoint'][$this->getPrimaryKey()] = true; + $keys = OrderAddressColissimoPickupPointTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getCode(), + $keys[2] => $this->getType(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aOrderAddress) { + $result['OrderAddress'] = $this->aOrderAddress->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = OrderAddressColissimoPickupPointTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setCode($value); + break; + case 2: + $this->setType($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = OrderAddressColissimoPickupPointTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setType($arr[$keys[2]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + + if ($this->isColumnModified(OrderAddressColissimoPickupPointTableMap::ID)) $criteria->add(OrderAddressColissimoPickupPointTableMap::ID, $this->id); + if ($this->isColumnModified(OrderAddressColissimoPickupPointTableMap::CODE)) $criteria->add(OrderAddressColissimoPickupPointTableMap::CODE, $this->code); + if ($this->isColumnModified(OrderAddressColissimoPickupPointTableMap::TYPE)) $criteria->add(OrderAddressColissimoPickupPointTableMap::TYPE, $this->type); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + $criteria->add(OrderAddressColissimoPickupPointTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setCode($this->getCode()); + $copyObj->setType($this->getType()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildOrderAddress object. + * + * @param ChildOrderAddress $v + * @return \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint The current object (for fluent API support) + * @throws PropelException + */ + public function setOrderAddress(ChildOrderAddress $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aOrderAddress = $v; + + // Add binding for other direction of this 1:1 relationship. + if ($v !== null) { + $v->setOrderAddressColissimoPickupPoint($this); + } + + + return $this; + } + + + /** + * Get the associated ChildOrderAddress object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildOrderAddress The associated ChildOrderAddress object. + * @throws PropelException + */ + public function getOrderAddress(ConnectionInterface $con = null) + { + if ($this->aOrderAddress === null && ($this->id !== null)) { + $this->aOrderAddress = OrderAddressQuery::create()->findPk($this->id, $con); + // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association. + $this->aOrderAddress->setOrderAddressColissimoPickupPoint($this); + } + + return $this->aOrderAddress; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->code = null; + $this->type = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aOrderAddress = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(OrderAddressColissimoPickupPointTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/local/modules/ColissimoPickupPoint/Model/Base/OrderAddressColissimoPickupPointQuery.php b/local/modules/ColissimoPickupPoint/Model/Base/OrderAddressColissimoPickupPointQuery.php new file mode 100644 index 00000000..c517ea98 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Base/OrderAddressColissimoPickupPointQuery.php @@ -0,0 +1,495 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildOrderAddressColissimoPickupPoint|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = OrderAddressColissimoPickupPointTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildOrderAddressColissimoPickupPoint A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT ID, CODE, TYPE FROM order_address_colissimo_pickup_point WHERE ID = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildOrderAddressColissimoPickupPoint(); + $obj->hydrate($row); + OrderAddressColissimoPickupPointTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildOrderAddressColissimoPickupPoint|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByOrderAddress() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the code column + * + * Example usage: + * + * $query->filterByCode('fooValue'); // WHERE code = 'fooValue' + * $query->filterByCode('%fooValue%'); // WHERE code LIKE '%fooValue%' + * + * + * @param string $code The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByCode($code = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($code)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $code)) { + $code = str_replace('*', '%', $code); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::CODE, $code, $comparison); + } + + /** + * Filter the query on the type column + * + * Example usage: + * + * $query->filterByType('fooValue'); // WHERE type = 'fooValue' + * $query->filterByType('%fooValue%'); // WHERE type LIKE '%fooValue%' + * + * + * @param string $type The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByType($type = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($type)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $type)) { + $type = str_replace('*', '%', $type); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::TYPE, $type, $comparison); + } + + /** + * Filter the query by a related \ColissimoPickupPoint\Model\Thelia\Model\OrderAddress object + * + * @param \ColissimoPickupPoint\Model\Thelia\Model\OrderAddress|ObjectCollection $orderAddress The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function filterByOrderAddress($orderAddress, $comparison = null) + { + if ($orderAddress instanceof \ColissimoPickupPoint\Model\Thelia\Model\OrderAddress) { + return $this + ->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $orderAddress->getId(), $comparison); + } elseif ($orderAddress instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $orderAddress->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByOrderAddress() only accepts arguments of type \ColissimoPickupPoint\Model\Thelia\Model\OrderAddress or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the OrderAddress relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function joinOrderAddress($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('OrderAddress'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'OrderAddress'); + } + + return $this; + } + + /** + * Use the OrderAddress relation OrderAddress object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \ColissimoPickupPoint\Model\Thelia\Model\OrderAddressQuery A secondary query class using the current class as primary query + */ + public function useOrderAddressQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinOrderAddress($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'OrderAddress', '\ColissimoPickupPoint\Model\Thelia\Model\OrderAddressQuery'); + } + + /** + * Exclude object from result + * + * @param ChildOrderAddressColissimoPickupPoint $orderAddressColissimoPickupPoint Object to remove from the list of results + * + * @return ChildOrderAddressColissimoPickupPointQuery The current query, for fluid interface + */ + public function prune($orderAddressColissimoPickupPoint = null) + { + if ($orderAddressColissimoPickupPoint) { + $this->addUsingAlias(OrderAddressColissimoPickupPointTableMap::ID, $orderAddressColissimoPickupPoint->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the order_address_colissimo_pickup_point table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + OrderAddressColissimoPickupPointTableMap::clearInstancePool(); + OrderAddressColissimoPickupPointTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildOrderAddressColissimoPickupPoint or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildOrderAddressColissimoPickupPoint object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + OrderAddressColissimoPickupPointTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + OrderAddressColissimoPickupPointTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // OrderAddressColissimoPickupPointQuery diff --git a/local/modules/ColissimoPickupPoint/Model/ColissimoPickupPointAreaFreeshipping.php b/local/modules/ColissimoPickupPoint/Model/ColissimoPickupPointAreaFreeshipping.php new file mode 100644 index 00000000..7c2fd1fa --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/ColissimoPickupPointAreaFreeshipping.php @@ -0,0 +1,10 @@ + array('Id', 'TitleId', 'Company', 'Firstname', 'Lastname', 'Address1', 'Address2', 'Address3', 'Zipcode', 'City', 'CountryId', 'Code', 'Type', 'Cellphone', ), + self::TYPE_STUDLYPHPNAME => array('id', 'titleId', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'countryId', 'code', 'type', 'cellphone', ), + self::TYPE_COLNAME => array(AddressColissimoPickupPointTableMap::ID, AddressColissimoPickupPointTableMap::TITLE_ID, AddressColissimoPickupPointTableMap::COMPANY, AddressColissimoPickupPointTableMap::FIRSTNAME, AddressColissimoPickupPointTableMap::LASTNAME, AddressColissimoPickupPointTableMap::ADDRESS1, AddressColissimoPickupPointTableMap::ADDRESS2, AddressColissimoPickupPointTableMap::ADDRESS3, AddressColissimoPickupPointTableMap::ZIPCODE, AddressColissimoPickupPointTableMap::CITY, AddressColissimoPickupPointTableMap::COUNTRY_ID, AddressColissimoPickupPointTableMap::CODE, AddressColissimoPickupPointTableMap::TYPE, AddressColissimoPickupPointTableMap::CELLPHONE, ), + self::TYPE_RAW_COLNAME => array('ID', 'TITLE_ID', 'COMPANY', 'FIRSTNAME', 'LASTNAME', 'ADDRESS1', 'ADDRESS2', 'ADDRESS3', 'ZIPCODE', 'CITY', 'COUNTRY_ID', 'CODE', 'TYPE', 'CELLPHONE', ), + self::TYPE_FIELDNAME => array('id', 'title_id', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'country_id', 'code', 'type', 'cellphone', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'TitleId' => 1, 'Company' => 2, 'Firstname' => 3, 'Lastname' => 4, 'Address1' => 5, 'Address2' => 6, 'Address3' => 7, 'Zipcode' => 8, 'City' => 9, 'CountryId' => 10, 'Code' => 11, 'Type' => 12, 'Cellphone' => 13, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'titleId' => 1, 'company' => 2, 'firstname' => 3, 'lastname' => 4, 'address1' => 5, 'address2' => 6, 'address3' => 7, 'zipcode' => 8, 'city' => 9, 'countryId' => 10, 'code' => 11, 'type' => 12, 'cellphone' => 13, ), + self::TYPE_COLNAME => array(AddressColissimoPickupPointTableMap::ID => 0, AddressColissimoPickupPointTableMap::TITLE_ID => 1, AddressColissimoPickupPointTableMap::COMPANY => 2, AddressColissimoPickupPointTableMap::FIRSTNAME => 3, AddressColissimoPickupPointTableMap::LASTNAME => 4, AddressColissimoPickupPointTableMap::ADDRESS1 => 5, AddressColissimoPickupPointTableMap::ADDRESS2 => 6, AddressColissimoPickupPointTableMap::ADDRESS3 => 7, AddressColissimoPickupPointTableMap::ZIPCODE => 8, AddressColissimoPickupPointTableMap::CITY => 9, AddressColissimoPickupPointTableMap::COUNTRY_ID => 10, AddressColissimoPickupPointTableMap::CODE => 11, AddressColissimoPickupPointTableMap::TYPE => 12, AddressColissimoPickupPointTableMap::CELLPHONE => 13, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'TITLE_ID' => 1, 'COMPANY' => 2, 'FIRSTNAME' => 3, 'LASTNAME' => 4, 'ADDRESS1' => 5, 'ADDRESS2' => 6, 'ADDRESS3' => 7, 'ZIPCODE' => 8, 'CITY' => 9, 'COUNTRY_ID' => 10, 'CODE' => 11, 'TYPE' => 12, 'CELLPHONE' => 13, ), + self::TYPE_FIELDNAME => array('id' => 0, 'title_id' => 1, 'company' => 2, 'firstname' => 3, 'lastname' => 4, 'address1' => 5, 'address2' => 6, 'address3' => 7, 'zipcode' => 8, 'city' => 9, 'country_id' => 10, 'code' => 11, 'type' => 12, 'cellphone' => 13, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('address_colissimo_pickup_point'); + $this->setPhpName('AddressColissimoPickupPoint'); + $this->setClassName('\\ColissimoPickupPoint\\Model\\AddressColissimoPickupPoint'); + $this->setPackage('ColissimoPickupPoint.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('TITLE_ID', 'TitleId', 'INTEGER', 'customer_title', 'ID', true, null, null); + $this->addColumn('COMPANY', 'Company', 'VARCHAR', false, 255, null); + $this->addColumn('FIRSTNAME', 'Firstname', 'VARCHAR', true, 255, null); + $this->addColumn('LASTNAME', 'Lastname', 'VARCHAR', true, 255, null); + $this->addColumn('ADDRESS1', 'Address1', 'VARCHAR', true, 255, null); + $this->addColumn('ADDRESS2', 'Address2', 'VARCHAR', true, 255, null); + $this->addColumn('ADDRESS3', 'Address3', 'VARCHAR', true, 255, null); + $this->addColumn('ZIPCODE', 'Zipcode', 'VARCHAR', true, 10, null); + $this->addColumn('CITY', 'City', 'VARCHAR', true, 255, null); + $this->addForeignKey('COUNTRY_ID', 'CountryId', 'INTEGER', 'country', 'ID', true, null, null); + $this->addColumn('CODE', 'Code', 'VARCHAR', true, 10, null); + $this->addColumn('TYPE', 'Type', 'VARCHAR', true, 10, null); + $this->addColumn('CELLPHONE', 'Cellphone', 'VARCHAR', false, 20, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('CustomerTitle', '\\ColissimoPickupPoint\\Model\\Thelia\\Model\\CustomerTitle', RelationMap::MANY_TO_ONE, array('title_id' => 'id', ), 'RESTRICT', 'RESTRICT'); + $this->addRelation('Country', '\\ColissimoPickupPoint\\Model\\Thelia\\Model\\Country', RelationMap::MANY_TO_ONE, array('country_id' => 'id', ), 'RESTRICT', 'RESTRICT'); + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? AddressColissimoPickupPointTableMap::CLASS_DEFAULT : AddressColissimoPickupPointTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (AddressColissimoPickupPoint object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = AddressColissimoPickupPointTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = AddressColissimoPickupPointTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + AddressColissimoPickupPointTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = AddressColissimoPickupPointTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + AddressColissimoPickupPointTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = AddressColissimoPickupPointTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = AddressColissimoPickupPointTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + AddressColissimoPickupPointTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::ID); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::TITLE_ID); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::COMPANY); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::FIRSTNAME); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::LASTNAME); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::ADDRESS1); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::ADDRESS2); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::ADDRESS3); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::ZIPCODE); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::CITY); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::COUNTRY_ID); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::CODE); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::TYPE); + $criteria->addSelectColumn(AddressColissimoPickupPointTableMap::CELLPHONE); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.TITLE_ID'); + $criteria->addSelectColumn($alias . '.COMPANY'); + $criteria->addSelectColumn($alias . '.FIRSTNAME'); + $criteria->addSelectColumn($alias . '.LASTNAME'); + $criteria->addSelectColumn($alias . '.ADDRESS1'); + $criteria->addSelectColumn($alias . '.ADDRESS2'); + $criteria->addSelectColumn($alias . '.ADDRESS3'); + $criteria->addSelectColumn($alias . '.ZIPCODE'); + $criteria->addSelectColumn($alias . '.CITY'); + $criteria->addSelectColumn($alias . '.COUNTRY_ID'); + $criteria->addSelectColumn($alias . '.CODE'); + $criteria->addSelectColumn($alias . '.TYPE'); + $criteria->addSelectColumn($alias . '.CELLPHONE'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(AddressColissimoPickupPointTableMap::DATABASE_NAME)->getTable(AddressColissimoPickupPointTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(AddressColissimoPickupPointTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(AddressColissimoPickupPointTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new AddressColissimoPickupPointTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a AddressColissimoPickupPoint or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or AddressColissimoPickupPoint object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \ColissimoPickupPoint\Model\AddressColissimoPickupPoint) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(AddressColissimoPickupPointTableMap::DATABASE_NAME); + $criteria->add(AddressColissimoPickupPointTableMap::ID, (array) $values, Criteria::IN); + } + + $query = AddressColissimoPickupPointQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { AddressColissimoPickupPointTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { AddressColissimoPickupPointTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the address_colissimo_pickup_point table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return AddressColissimoPickupPointQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a AddressColissimoPickupPoint or Criteria object. + * + * @param mixed $criteria Criteria or AddressColissimoPickupPoint object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(AddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from AddressColissimoPickupPoint object + } + + + // Set the correct dbName + $query = AddressColissimoPickupPointQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // AddressColissimoPickupPointTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +AddressColissimoPickupPointTableMap::buildTableMap(); diff --git a/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointAreaFreeshippingTableMap.php b/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointAreaFreeshippingTableMap.php new file mode 100644 index 00000000..8933c601 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointAreaFreeshippingTableMap.php @@ -0,0 +1,419 @@ + array('Id', 'AreaId', 'CartAmount', ), + self::TYPE_STUDLYPHPNAME => array('id', 'areaId', 'cartAmount', ), + self::TYPE_COLNAME => array(ColissimoPickupPointAreaFreeshippingTableMap::ID, ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID, ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT, ), + self::TYPE_RAW_COLNAME => array('ID', 'AREA_ID', 'CART_AMOUNT', ), + self::TYPE_FIELDNAME => array('id', 'area_id', 'cart_amount', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'AreaId' => 1, 'CartAmount' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'areaId' => 1, 'cartAmount' => 2, ), + self::TYPE_COLNAME => array(ColissimoPickupPointAreaFreeshippingTableMap::ID => 0, ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID => 1, ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'AREA_ID' => 1, 'CART_AMOUNT' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'area_id' => 1, 'cart_amount' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('colissimo_pickup_point_area_freeshipping'); + $this->setPhpName('ColissimoPickupPointAreaFreeshipping'); + $this->setClassName('\\ColissimoPickupPoint\\Model\\ColissimoPickupPointAreaFreeshipping'); + $this->setPackage('ColissimoPickupPoint.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('AREA_ID', 'AreaId', 'INTEGER', 'area', 'ID', true, null, null); + $this->addColumn('CART_AMOUNT', 'CartAmount', 'DECIMAL', false, 18, 0); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Area', '\\ColissimoPickupPoint\\Model\\Thelia\\Model\\Area', RelationMap::MANY_TO_ONE, array('area_id' => 'id', ), 'RESTRICT', 'RESTRICT'); + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ColissimoPickupPointAreaFreeshippingTableMap::CLASS_DEFAULT : ColissimoPickupPointAreaFreeshippingTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ColissimoPickupPointAreaFreeshipping object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ColissimoPickupPointAreaFreeshippingTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ColissimoPickupPointAreaFreeshippingTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ColissimoPickupPointAreaFreeshippingTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ColissimoPickupPointAreaFreeshippingTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ColissimoPickupPointAreaFreeshippingTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ColissimoPickupPointAreaFreeshippingTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ColissimoPickupPointAreaFreeshippingTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ColissimoPickupPointAreaFreeshippingTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ColissimoPickupPointAreaFreeshippingTableMap::ID); + $criteria->addSelectColumn(ColissimoPickupPointAreaFreeshippingTableMap::AREA_ID); + $criteria->addSelectColumn(ColissimoPickupPointAreaFreeshippingTableMap::CART_AMOUNT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.AREA_ID'); + $criteria->addSelectColumn($alias . '.CART_AMOUNT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME)->getTable(ColissimoPickupPointAreaFreeshippingTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ColissimoPickupPointAreaFreeshippingTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ColissimoPickupPointAreaFreeshippingTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ColissimoPickupPointAreaFreeshipping or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ColissimoPickupPointAreaFreeshipping object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \ColissimoPickupPoint\Model\ColissimoPickupPointAreaFreeshipping) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + $criteria->add(ColissimoPickupPointAreaFreeshippingTableMap::ID, (array) $values, Criteria::IN); + } + + $query = ColissimoPickupPointAreaFreeshippingQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ColissimoPickupPointAreaFreeshippingTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ColissimoPickupPointAreaFreeshippingTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the colissimo_pickup_point_area_freeshipping table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ColissimoPickupPointAreaFreeshippingQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ColissimoPickupPointAreaFreeshipping or Criteria object. + * + * @param mixed $criteria Criteria or ColissimoPickupPointAreaFreeshipping object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointAreaFreeshippingTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ColissimoPickupPointAreaFreeshipping object + } + + if ($criteria->containsKey(ColissimoPickupPointAreaFreeshippingTableMap::ID) && $criteria->keyContainsValue(ColissimoPickupPointAreaFreeshippingTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ColissimoPickupPointAreaFreeshippingTableMap::ID.')'); + } + + + // Set the correct dbName + $query = ColissimoPickupPointAreaFreeshippingQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ColissimoPickupPointAreaFreeshippingTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ColissimoPickupPointAreaFreeshippingTableMap::buildTableMap(); diff --git a/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointFreeshippingTableMap.php b/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointFreeshippingTableMap.php new file mode 100644 index 00000000..968fa576 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointFreeshippingTableMap.php @@ -0,0 +1,414 @@ + array('Id', 'Active', 'FreeshippingFrom', ), + self::TYPE_STUDLYPHPNAME => array('id', 'active', 'freeshippingFrom', ), + self::TYPE_COLNAME => array(ColissimoPickupPointFreeshippingTableMap::ID, ColissimoPickupPointFreeshippingTableMap::ACTIVE, ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM, ), + self::TYPE_RAW_COLNAME => array('ID', 'ACTIVE', 'FREESHIPPING_FROM', ), + self::TYPE_FIELDNAME => array('id', 'active', 'freeshipping_from', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Active' => 1, 'FreeshippingFrom' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'active' => 1, 'freeshippingFrom' => 2, ), + self::TYPE_COLNAME => array(ColissimoPickupPointFreeshippingTableMap::ID => 0, ColissimoPickupPointFreeshippingTableMap::ACTIVE => 1, ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'ACTIVE' => 1, 'FREESHIPPING_FROM' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'active' => 1, 'freeshipping_from' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('colissimo_pickup_point_freeshipping'); + $this->setPhpName('ColissimoPickupPointFreeshipping'); + $this->setClassName('\\ColissimoPickupPoint\\Model\\ColissimoPickupPointFreeshipping'); + $this->setPackage('ColissimoPickupPoint.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('ACTIVE', 'Active', 'BOOLEAN', false, 1, false); + $this->addColumn('FREESHIPPING_FROM', 'FreeshippingFrom', 'DECIMAL', false, 18, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ColissimoPickupPointFreeshippingTableMap::CLASS_DEFAULT : ColissimoPickupPointFreeshippingTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ColissimoPickupPointFreeshipping object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ColissimoPickupPointFreeshippingTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ColissimoPickupPointFreeshippingTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ColissimoPickupPointFreeshippingTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ColissimoPickupPointFreeshippingTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ColissimoPickupPointFreeshippingTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ColissimoPickupPointFreeshippingTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ColissimoPickupPointFreeshippingTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ColissimoPickupPointFreeshippingTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ColissimoPickupPointFreeshippingTableMap::ID); + $criteria->addSelectColumn(ColissimoPickupPointFreeshippingTableMap::ACTIVE); + $criteria->addSelectColumn(ColissimoPickupPointFreeshippingTableMap::FREESHIPPING_FROM); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.ACTIVE'); + $criteria->addSelectColumn($alias . '.FREESHIPPING_FROM'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME)->getTable(ColissimoPickupPointFreeshippingTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ColissimoPickupPointFreeshippingTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ColissimoPickupPointFreeshippingTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ColissimoPickupPointFreeshipping or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ColissimoPickupPointFreeshipping object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \ColissimoPickupPoint\Model\ColissimoPickupPointFreeshipping) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + $criteria->add(ColissimoPickupPointFreeshippingTableMap::ID, (array) $values, Criteria::IN); + } + + $query = ColissimoPickupPointFreeshippingQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ColissimoPickupPointFreeshippingTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ColissimoPickupPointFreeshippingTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the colissimo_pickup_point_freeshipping table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ColissimoPickupPointFreeshippingQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ColissimoPickupPointFreeshipping or Criteria object. + * + * @param mixed $criteria Criteria or ColissimoPickupPointFreeshipping object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointFreeshippingTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ColissimoPickupPointFreeshipping object + } + + + // Set the correct dbName + $query = ColissimoPickupPointFreeshippingQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ColissimoPickupPointFreeshippingTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ColissimoPickupPointFreeshippingTableMap::buildTableMap(); diff --git a/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointPriceSlicesTableMap.php b/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointPriceSlicesTableMap.php new file mode 100644 index 00000000..d7b40a4b --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Map/ColissimoPickupPointPriceSlicesTableMap.php @@ -0,0 +1,443 @@ + array('Id', 'AreaId', 'WeightMax', 'PriceMax', 'FrancoMinPrice', 'Price', ), + self::TYPE_STUDLYPHPNAME => array('id', 'areaId', 'weightMax', 'priceMax', 'francoMinPrice', 'price', ), + self::TYPE_COLNAME => array(ColissimoPickupPointPriceSlicesTableMap::ID, ColissimoPickupPointPriceSlicesTableMap::AREA_ID, ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX, ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX, ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE, ColissimoPickupPointPriceSlicesTableMap::PRICE, ), + self::TYPE_RAW_COLNAME => array('ID', 'AREA_ID', 'WEIGHT_MAX', 'PRICE_MAX', 'FRANCO_MIN_PRICE', 'PRICE', ), + self::TYPE_FIELDNAME => array('id', 'area_id', 'weight_max', 'price_max', 'franco_min_price', 'price', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'AreaId' => 1, 'WeightMax' => 2, 'PriceMax' => 3, 'FrancoMinPrice' => 4, 'Price' => 5, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'areaId' => 1, 'weightMax' => 2, 'priceMax' => 3, 'francoMinPrice' => 4, 'price' => 5, ), + self::TYPE_COLNAME => array(ColissimoPickupPointPriceSlicesTableMap::ID => 0, ColissimoPickupPointPriceSlicesTableMap::AREA_ID => 1, ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX => 2, ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX => 3, ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE => 4, ColissimoPickupPointPriceSlicesTableMap::PRICE => 5, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'AREA_ID' => 1, 'WEIGHT_MAX' => 2, 'PRICE_MAX' => 3, 'FRANCO_MIN_PRICE' => 4, 'PRICE' => 5, ), + self::TYPE_FIELDNAME => array('id' => 0, 'area_id' => 1, 'weight_max' => 2, 'price_max' => 3, 'franco_min_price' => 4, 'price' => 5, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('colissimo_pickup_point_price_slices'); + $this->setPhpName('ColissimoPickupPointPriceSlices'); + $this->setClassName('\\ColissimoPickupPoint\\Model\\ColissimoPickupPointPriceSlices'); + $this->setPackage('ColissimoPickupPoint.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('AREA_ID', 'AreaId', 'INTEGER', 'area', 'ID', true, null, null); + $this->addColumn('WEIGHT_MAX', 'WeightMax', 'FLOAT', false, null, null); + $this->addColumn('PRICE_MAX', 'PriceMax', 'FLOAT', false, null, null); + $this->addColumn('FRANCO_MIN_PRICE', 'FrancoMinPrice', 'FLOAT', false, null, null); + $this->addColumn('PRICE', 'Price', 'FLOAT', true, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Area', '\\ColissimoPickupPoint\\Model\\Thelia\\Model\\Area', RelationMap::MANY_TO_ONE, array('area_id' => 'id', ), 'RESTRICT', 'RESTRICT'); + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ColissimoPickupPointPriceSlicesTableMap::CLASS_DEFAULT : ColissimoPickupPointPriceSlicesTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ColissimoPickupPointPriceSlices object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ColissimoPickupPointPriceSlicesTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ColissimoPickupPointPriceSlicesTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ColissimoPickupPointPriceSlicesTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ColissimoPickupPointPriceSlicesTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ColissimoPickupPointPriceSlicesTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ColissimoPickupPointPriceSlicesTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ColissimoPickupPointPriceSlicesTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ColissimoPickupPointPriceSlicesTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ColissimoPickupPointPriceSlicesTableMap::ID); + $criteria->addSelectColumn(ColissimoPickupPointPriceSlicesTableMap::AREA_ID); + $criteria->addSelectColumn(ColissimoPickupPointPriceSlicesTableMap::WEIGHT_MAX); + $criteria->addSelectColumn(ColissimoPickupPointPriceSlicesTableMap::PRICE_MAX); + $criteria->addSelectColumn(ColissimoPickupPointPriceSlicesTableMap::FRANCO_MIN_PRICE); + $criteria->addSelectColumn(ColissimoPickupPointPriceSlicesTableMap::PRICE); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.AREA_ID'); + $criteria->addSelectColumn($alias . '.WEIGHT_MAX'); + $criteria->addSelectColumn($alias . '.PRICE_MAX'); + $criteria->addSelectColumn($alias . '.FRANCO_MIN_PRICE'); + $criteria->addSelectColumn($alias . '.PRICE'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME)->getTable(ColissimoPickupPointPriceSlicesTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ColissimoPickupPointPriceSlicesTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ColissimoPickupPointPriceSlicesTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ColissimoPickupPointPriceSlices or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ColissimoPickupPointPriceSlices object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \ColissimoPickupPoint\Model\ColissimoPickupPointPriceSlices) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + $criteria->add(ColissimoPickupPointPriceSlicesTableMap::ID, (array) $values, Criteria::IN); + } + + $query = ColissimoPickupPointPriceSlicesQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ColissimoPickupPointPriceSlicesTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ColissimoPickupPointPriceSlicesTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the colissimo_pickup_point_price_slices table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ColissimoPickupPointPriceSlicesQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ColissimoPickupPointPriceSlices or Criteria object. + * + * @param mixed $criteria Criteria or ColissimoPickupPointPriceSlices object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ColissimoPickupPointPriceSlicesTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ColissimoPickupPointPriceSlices object + } + + if ($criteria->containsKey(ColissimoPickupPointPriceSlicesTableMap::ID) && $criteria->keyContainsValue(ColissimoPickupPointPriceSlicesTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ColissimoPickupPointPriceSlicesTableMap::ID.')'); + } + + + // Set the correct dbName + $query = ColissimoPickupPointPriceSlicesQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ColissimoPickupPointPriceSlicesTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ColissimoPickupPointPriceSlicesTableMap::buildTableMap(); diff --git a/local/modules/ColissimoPickupPoint/Model/Map/OrderAddressColissimoPickupPointTableMap.php b/local/modules/ColissimoPickupPoint/Model/Map/OrderAddressColissimoPickupPointTableMap.php new file mode 100644 index 00000000..6b58545e --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/Map/OrderAddressColissimoPickupPointTableMap.php @@ -0,0 +1,415 @@ + array('Id', 'Code', 'Type', ), + self::TYPE_STUDLYPHPNAME => array('id', 'code', 'type', ), + self::TYPE_COLNAME => array(OrderAddressColissimoPickupPointTableMap::ID, OrderAddressColissimoPickupPointTableMap::CODE, OrderAddressColissimoPickupPointTableMap::TYPE, ), + self::TYPE_RAW_COLNAME => array('ID', 'CODE', 'TYPE', ), + self::TYPE_FIELDNAME => array('id', 'code', 'type', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Code' => 1, 'Type' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'code' => 1, 'type' => 2, ), + self::TYPE_COLNAME => array(OrderAddressColissimoPickupPointTableMap::ID => 0, OrderAddressColissimoPickupPointTableMap::CODE => 1, OrderAddressColissimoPickupPointTableMap::TYPE => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'CODE' => 1, 'TYPE' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'code' => 1, 'type' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('order_address_colissimo_pickup_point'); + $this->setPhpName('OrderAddressColissimoPickupPoint'); + $this->setClassName('\\ColissimoPickupPoint\\Model\\OrderAddressColissimoPickupPoint'); + $this->setPackage('ColissimoPickupPoint.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'order_address', 'ID', true, null, null); + $this->addColumn('CODE', 'Code', 'VARCHAR', true, 10, null); + $this->addColumn('TYPE', 'Type', 'VARCHAR', true, 10, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('OrderAddress', '\\ColissimoPickupPoint\\Model\\Thelia\\Model\\OrderAddress', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', 'CASCADE'); + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? OrderAddressColissimoPickupPointTableMap::CLASS_DEFAULT : OrderAddressColissimoPickupPointTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (OrderAddressColissimoPickupPoint object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = OrderAddressColissimoPickupPointTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = OrderAddressColissimoPickupPointTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + OrderAddressColissimoPickupPointTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = OrderAddressColissimoPickupPointTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + OrderAddressColissimoPickupPointTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = OrderAddressColissimoPickupPointTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = OrderAddressColissimoPickupPointTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + OrderAddressColissimoPickupPointTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(OrderAddressColissimoPickupPointTableMap::ID); + $criteria->addSelectColumn(OrderAddressColissimoPickupPointTableMap::CODE); + $criteria->addSelectColumn(OrderAddressColissimoPickupPointTableMap::TYPE); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.CODE'); + $criteria->addSelectColumn($alias . '.TYPE'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME)->getTable(OrderAddressColissimoPickupPointTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(OrderAddressColissimoPickupPointTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new OrderAddressColissimoPickupPointTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a OrderAddressColissimoPickupPoint or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or OrderAddressColissimoPickupPoint object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \ColissimoPickupPoint\Model\OrderAddressColissimoPickupPoint) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + $criteria->add(OrderAddressColissimoPickupPointTableMap::ID, (array) $values, Criteria::IN); + } + + $query = OrderAddressColissimoPickupPointQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { OrderAddressColissimoPickupPointTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { OrderAddressColissimoPickupPointTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the order_address_colissimo_pickup_point table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return OrderAddressColissimoPickupPointQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a OrderAddressColissimoPickupPoint or Criteria object. + * + * @param mixed $criteria Criteria or OrderAddressColissimoPickupPoint object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderAddressColissimoPickupPointTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from OrderAddressColissimoPickupPoint object + } + + + // Set the correct dbName + $query = OrderAddressColissimoPickupPointQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // OrderAddressColissimoPickupPointTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +OrderAddressColissimoPickupPointTableMap::buildTableMap(); diff --git a/local/modules/ColissimoPickupPoint/Model/OrderAddressColissimoPickupPoint.php b/local/modules/ColissimoPickupPoint/Model/OrderAddressColissimoPickupPoint.php new file mode 100644 index 00000000..1d4ddc03 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Model/OrderAddressColissimoPickupPoint.php @@ -0,0 +1,10 @@ +/local/modules/``` directory and be sure that the name of the module is ColissimoPickupPoint. +* Activate it in your thelia administration panel + +### Composer + +Add it in your main thelia composer.json file + +``` +composer require thelia/colissimo-pickup-point-module:~1.0.0 +``` + +How to use +----------- +First, go to your back office, tab Modules, and activate the module ColissimoPickupPoint. +Then go to the ColissimoPickupPoint config page, tab "Advanced Configuration" and enter your Colissimo id and password. +To import exported files in Expeditor INET, you need the file THELIA_INET.FMT, that is in the archive. + +Loops +----- +1. colissimo.pickup.point.check.rights + - Arguments: + None + - Output: + 1. $ERRMES: Error message + 2. $ERRFILE: File where the error has been detected + - Usage: + ```{loop name="yourloopname" type="colissimo.pickup.point.check.rights"}{/loop}``` + +2. colissimo.pickup.point + - Arguments: + 1. area_id | mandatory | id of the area we want to know the price slices of + - Output: + 1. $SLICE_ID: The ID of this price slice + 2. $MAX_WEIGHT: Max cart weight for the price slice + 3. $MAX_PRICE: Max cart price for the price slice + 4. $PRICE: Delivery price for this price slice + 5. $FRANCO: UNUSED + - Usage: + ```{loop name="yourloopname" type="colissimo.pickup.point"}{/loop}``` + +3. colissimo.pickup.point.id + - Arguments: + None + - Output: + 1. $MODULE_ID: Id of the ColissimoPickupPoint module + - Usage: + ```{loop name="yourloopname" type="colissimo.pickup.point.id"}{/loop}``` + +4. colissimo.pickup.point.around + - Arguments: + 1. countryid | optionnal | Country ID of where the search location is + 2. zipcode | optionnal | Zipcode of the searched city + 3. city | optionnal | Name of the searched city + 4. address | optionnal | Id of the address to use for the search. + address cannot be used at the same time as zipcode + city + - Output: + 1. $LONGITUDE: longitude of the pickup & go store + 2. $LATITUDE : latitude of the pickup & go store + 3. $CODE : ID of the pickup & go store + 4. $ADDRESS : address of the pickup & go store + 5. $ZIPCODE : zipcode of the pickup & go store + 6. $CITY : city of the pickup & go store + 7. $DISTANCE : distance between the store and the customer's address/searched address + - Usage: + ```{loop name="yourloopname" type="colissimo.pickup.point.around"}{/loop}``` + +5. address.colissimo.pickup.point + - Arguments: + The same as the loop address + - Output: + The same as the loop address, but with pickup & go store's address + - Usage: + ```{loop name="yourloopname" type="address.colissimo.pickup.point"}{/loop}``` + +6. order.notsent.colissimo.pickup.point + - Arguments: + None + - Output: + The same as the loop order, but with not sent ColissimoPickupPoint orders. + - Usage: + ```{loop name="yourloopname" type="order.notsent.colissimo.pickup.point"}{/loop}``` + +7. colissimo.pickup.point.order_address + - Arguments: + 1. id | mandatory | ID of the OrderAddressColissimoPickupPoint that should be retrieved by the loop. + - Outputs: + 1. $ID : OrderAddressColissimoPickupPoint ID. + 2. $CODE : OrderAddressColissimoPickupPoint code. + 3. $TYPE : OrderAddressColissimoPickupPoint type. + - Usage: + ```{loop name="yourloopname" type="colissimo.pickup.point.order_address"}{/loop}``` + +8. colissimo.pickup.point.area.freeshipping + - Arguments: + 1. area_id | optionnal | Id of the area we want to know if freeshipping from is active + - Outputs: + 1. $ID : ColissimoPickupPointAreaFreeshipping ID. + 2. $AREA_ID : The area ID. + 3. $CART_AMOUNT : The minimum cart amount to have free shipping for this area. + - Usage: + ```{loop name="yourloopname" type="colissimo.pickup.point.area.freeshipping"}{/loop}``` + +9. colissimo.pickup.point.freeshipping + - Arguments: + 1. id | optionnal | Should always be 1. + - Outputs: + 1. $FREESHIPPING_ACTIVE : Whether free shipping is activated with no restrictions on all area. + 2. $FREESHIPPING_FROM : The minimum cart amount to have free shipping on all alreas. + - Usage: + ```{loop name="yourloopname" type="colissimo.pickup.point.freeshipping"}{/loop}``` + +Plugins Smarty +----- +1. colissimoPickupPointDeliveryPrice + - Arguments: + 1. country | optionnal | The country ID from which you want to get the delivery prices. Defaults to store country + - Outputs: + 1. $isValidMode : Whether the delivery is valid for the cart in session and the chosen country. + 2. $deliveryPrice : The delivery price for the cart in session in the chosen country. + - Usage: + ```{colissimoPickupPointDeliveryPrice country=64}``` + +Integration +----------- +A integration example is available for the default theme of Thelia. +To install it, copy the files of pathToColissimoPickupPoint/templates/frontOffice/default and +pathToColissimoPickupPoint/templates/frontOffice/default/ajax respectively in pathToThelia/templates/frontOffice/default +and pathToThelia/templates/frontOffice/default/ajax diff --git a/local/modules/ColissimoPickupPoint/Smarty/Plugins/ColissimoPickupPointDeliveryPrice.php b/local/modules/ColissimoPickupPoint/Smarty/Plugins/ColissimoPickupPointDeliveryPrice.php new file mode 100644 index 00000000..8bdc929b --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Smarty/Plugins/ColissimoPickupPointDeliveryPrice.php @@ -0,0 +1,56 @@ +request = $request; + $this->dispatcher = $dispatcher; + } + + public function getPluginDescriptors() + { + return array( + new SmartyPluginDescriptor('function', 'colissimoPickupPointDeliveryPrice', $this, 'colissimoPickupPointDeliveryPrice') + ); + } + + public function colissimoPickupPointDeliveryPrice($params, $smarty) + { + $country = Country::getShopLocation(); + if (isset($params['country'])) { + $country = CountryQuery::create()->findOneById($params['country']); + } + + $cartWeight = $this->request->getSession()->getSessionCart($this->dispatcher)->getWeight(); + $cartAmount = $this->request->getSession()->getSessionCart($this->dispatcher)->getTaxedAmount($country); + + try { + $price = ColissimoPickupPoint::getPostageAmount( + $country->getAreaId(), + $cartWeight, + $cartAmount + ); + } catch (DeliveryException $ex) { + $smarty->assign('isValidMode', false); + } + + $smarty->assign('deliveryPrice', $price); + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Smarty/Plugins/ColissimoPickupPointGoogleApiKey.php b/local/modules/ColissimoPickupPoint/Smarty/Plugins/ColissimoPickupPointGoogleApiKey.php new file mode 100644 index 00000000..323d7f77 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Smarty/Plugins/ColissimoPickupPointGoogleApiKey.php @@ -0,0 +1,45 @@ +request = $request; + $this->dispatcher = $dispatcher; + } + + public function getPluginDescriptors() + { + return array( + new SmartyPluginDescriptor('function', 'colissimoPickupPointGoogleApiKey', $this, 'colissimoPickupPointGoogleApiKey') + ); + } + + public function colissimoPickupPointGoogleApiKey($params, $smarty) + { + $key = ModuleConfigQuery::create() + ->filterByName('colissimo_pickup_point_google_map_key') + ->findOne() + ->getValue() + ; + + $smarty->assign('colissimoPickupPointGoogleMapKey', $key); + + return $key; + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/THELIA_INET.FMT b/local/modules/ColissimoPickupPoint/THELIA_INET.FMT new file mode 100644 index 00000000..9697ab83 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/THELIA_INET.FMT @@ -0,0 +1,25 @@ +[GENERAL] +DELIMITE=O +SEPARATEUR=59 +DELIMITEUR=34 +FINDELIGNE=CRLF +Unité poids=KG +[CHAMPS] +Prenom=1 +NomDestinataire=2 +RaisonSociale=3 +Adresse1=4 +Adresse2=5 +Adresse3=6 +CodePostal=7 +Commune=8 +CodePays=9 +Telephone=10 +Portable=11 +CodeProduit=12 +Civilite=13 +CodePointRetrait=14 +Mail=15 +Poids=16 +NomCommercialChargeur=17 +typeDePoint=18 \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/Utils/ColissimoCodeReseau.php b/local/modules/ColissimoPickupPoint/Utils/ColissimoCodeReseau.php new file mode 100644 index 00000000..68d48483 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/Utils/ColissimoCodeReseau.php @@ -0,0 +1,56 @@ + + [ + 'CMT' => 'R03', + 'BDP' => 'X00', + 'PCS' => 'X00' + ], + 'ES' => + [ + 'CMT' => 'R03', + 'BDP' => 'X00', + ], + 'GB' => + [ + 'CMT' => 'R03' + ], + 'LU' => + [ + 'CMT' => 'R03' + ], + 'NL' => + [ + 'BDP' => 'X00', + 'CMT' => 'R03', + ], + 'BE' => + [ + 'BDP' => 'R12', + 'CMT' => 'R12', + ] + ]; + + public static function getCodeReseau($countryCode, $relayTypeCode) + { + if (array_key_exists($countryCode, self::CODE_RESEAU_ARRAY)) { + $innerArray = self::CODE_RESEAU_ARRAY[$countryCode]; + if (array_key_exists($relayTypeCode, $innerArray)) { + return $innerArray[$relayTypeCode]; + } + } + return null; + } +} diff --git a/local/modules/ColissimoPickupPoint/WebService/BaseColissimoPickupPointWebService.php b/local/modules/ColissimoPickupPoint/WebService/BaseColissimoPickupPointWebService.php new file mode 100755 index 00000000..d09fb5ff --- /dev/null +++ b/local/modules/ColissimoPickupPoint/WebService/BaseColissimoPickupPointWebService.php @@ -0,0 +1,55 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\WebService; + +use ColissimoPickupPoint\ColissimoPickupPoint; + +/** + * Class BaseColissimoPickupPointWebService + * @package ColissimoPickupPoint\WebService + * @author Thelia + * + * @method BaseColissimoPickupPointWebService getAccountNumber() + * @method BaseColissimoPickupPointWebService setAccountNumber($value) + * @method BaseColissimoPickupPointWebService getPassword() + * @method BaseColissimoPickupPointWebService setPassword($value) + * @method BaseColissimoPickupPointWebService getWeight() + * @method BaseColissimoPickupPointWebService setWeight($value) + */ +abstract class BaseColissimoPickupPointWebService extends BaseWebService +{ + + protected $account_number=null; + protected $password=null; + protected $filter_relay=null; + /** @var string Weight in grammes !*/ + protected $weight=null; + + public function __construct($function) + { + $url = ColissimoPickupPoint::getConfigValue(ColissimoPickupPoint::COLISSIMO_ENDPOINT); + + parent::__construct($url, $function); + } +} diff --git a/local/modules/ColissimoPickupPoint/WebService/BaseWebService.php b/local/modules/ColissimoPickupPoint/WebService/BaseWebService.php new file mode 100755 index 00000000..1e780389 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/WebService/BaseWebService.php @@ -0,0 +1,229 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\WebService; +use Symfony\Component\Serializer\Exception\InvalidArgumentException; + +/** + * Class BaseWebService + * @package ColissimoPickupPoint\WebService + * @author Thelia + * + * @method BaseWebService getSoap() + * @method BaseWebService setSoap(\SoapClient $soap) + * @method BaseWebService getWebFunction() + * @method BaseWebService setWebFunction($value) + */ +abstract class BaseWebService +{ + protected $soap; + protected $web_function; + + public function __construct($wsdl, $web_function=null) + { + $this->soap = new \SoapClient($wsdl); + $this->web_function=$web_function; + } + + /** + * @param $name + * @return mixed|string + */ + private function getProprietyRealName($name) + { + $propriety_real_name = substr($name,3); + + if (preg_match("#^[A-Z]$#", substr($propriety_real_name, 0,1))) { + $propriety_real_name = strtolower(substr($propriety_real_name, 0, 1)).substr($propriety_real_name, 1); + $propriety_real_name = preg_replace_callback( + "#([A-Z])#", + function ($match) { + return strtolower("_".$match[0]); + }, + $propriety_real_name + ); + } + + return $propriety_real_name; + } + + /** + * @param $name + * @param $arguments + * @return mixed + * @throws \Symfony\Component\Serializer\Exception\InvalidArgumentException + * @throws \BadFunctionCallException + */ + public function __call($name, $arguments) + { + if (method_exists($this, $name)) { + return call_user_func($this->$name, $arguments); + } + + if (substr($name,0,3) === "get") { + if (!empty($arguments)) { + throw new InvalidArgumentException("The function ".$name." in ".get_class($this)." doesn't take any argument."); + } + + $real_name = $this->getProprietyRealName($name); + if (property_exists($this, $real_name)) { + return $this->$real_name; + } + + } elseif (substr($name,0,3) === "set") { + if (count($arguments) !== 1) { + throw new InvalidArgumentException("The function ".$name." in ".get_class($this)." take only one argument."); + } + + $real_name = $this->getProprietyRealName($name); + $this->$real_name = $arguments[array_keys($arguments)[0]]; + + return $this; + } + + throw new \BadFunctionCallException("The function ".$name." doesn't exist in ".get_class($this)); + } + + /** + * @return mixed + * @throws \Symfony\Component\Serializer\Exception\InvalidArgumentException + */ + public function exec() + { + $function = $this->web_function; + $response = $this->soap->$function($this->getArgs()); + + if ($this->isError($response)) { + throw new InvalidArgumentException($this->getError($response)); + } + + return $this->getFormattedResponse($response); + } + + /** + * @return array of web function args + */ + public function getArgs() + { + $args= $this->getSoapNames($this->getThisVars()); + + /* + * Clear array + */ + foreach ($args as $key => $value) { + if ($key == "address" || $key == "city") { + $args[$key] = $this->normalize($value); + } + + if (empty($value)) { + unset($args[$key]); + } + } + + return $args; + } + + /** + * @return array + */ + protected function getThisVars() + { + $this_class_vars = get_object_vars($this); + $base_class_vars = get_class_vars("\\ColissimoPickupPoint\\WebService\\BaseWebService"); + $pks = array_diff_key($this_class_vars, $base_class_vars); + + return $pks; + } + + /** + * @param array $names + * @return array + */ + protected function getSoapNames(array $names) + { + foreach ($names as $name=>$value) { + $real_name = $this->getSoapName($name); + $names[$real_name] = $value; + if ($name !== $real_name) { + unset($names[$name]); + } + } + + return $names; + } + + /** + * @param string $name + * @return string + */ + protected function getSoapName($name) + { + return preg_replace_callback( + "#_([a-z]{1})#", + function ($match) { + return strtoupper($match[1]); + }, + $name + ); + } + + protected function normalize($text) + { + $utf8 = array( + '/[áàâãªä]/u' => 'a', + '/[ÁÀÂÃÄ]/u' => 'A', + '/[ÍÌÎÏ]/u' => 'I', + '/[íìîï]/u' => 'i', + '/[éèêë]/u' => 'e', + '/[ÉÈÊË]/u' => 'E', + '/[óòôõºö]/u' => 'o', + '/[ÓÒÔÕÖ]/u' => 'O', + '/[úùûü]/u' => 'u', + '/[ÚÙÛÜ]/u' => 'U', + '/ç/' => 'c', + '/Ç/' => 'C', + '/ñ/' => 'n', + '/Ñ/' => 'N', + '/–/' => '-', // UTF-8 hyphen to "normal" hyphen + '/[’‘‹›‚]/u' => ' ', // Literally a single quote + '/[“”«»„]/u' => ' ', // Double quote + '/ /' => ' ', // nonbreaking space (equiv. to 0x160) + ); + return preg_replace(array_keys($utf8), array_values($utf8), $text); + } + + /** + * @return bool + */ + abstract public function isError(\stdClass $response); + + /** + * @return string + */ + abstract public function getError(\stdClass $response); + + /** + * @return something + */ + abstract public function getFormattedResponse(\stdClass $response); +} diff --git a/local/modules/ColissimoPickupPoint/WebService/FindByAddress.php b/local/modules/ColissimoPickupPoint/WebService/FindByAddress.php new file mode 100755 index 00000000..d4c56726 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/WebService/FindByAddress.php @@ -0,0 +1,92 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\WebService; + +use stdClass; +use Symfony\Component\Config\Definition\Exception\Exception; + +/** + * Class FindByAddress + * @package ColissimoPickupPoint\WebService + * @author Thelia + * + * @method FindByAddress getAddress() + * @method FindByAddress setAddress($value) + * @method FindByAddress getZipCode() + * @method FindByAddress setZipCode($value) + * @method FindByAddress getCity() + * @method FindByAddress setCity($value) + * @method FindByAddress getCountryCode() + * @method FindByAddress setCountryCode($value) + * @method FindByAddress getFilterRelay() + * @method FindByAddress setFilterRelay($value) + * @method FindByAddress getRequestId() + * @method FindByAddress setRequestId($value) + * @method FindByAddress getLang() + * @method FindByAddress setLang($value) + * @method FindByAddress getOptionInter() + * @method FindByAddress setOptionInter($value) + * @method FindByAddress getShippingDate() + * @method FindByAddress setShippingDate($value) + */ +class FindByAddress extends BaseColissimoPickupPointWebService +{ + protected $address=null; + protected $zip_code=null; + protected $city=null; + protected $country_code=null; + protected $request_id=null; + protected $lang=null; + protected $option_inter=null; + protected $shipping_date=null; + + public function __construct() + { + parent::__construct('findRDVPointRetraitAcheminement'); + } + + public function isError(stdClass $response) + { + return isset($response->return->errorCode) && $response->return->errorCode != 0; + } + + public function getError(stdClass $response) + { + return isset($response->return->errorMessage) ? $response->return->errorMessage : 'Unknown error'; + } + + /** + * @param stdClass $response + * @return array + * @throws Exception + */ + public function getFormattedResponse(stdClass $response) + { + if (!isset($response->return->listePointRetraitAcheminement)) { + throw new Exception('An unknown error happened'); + } + + return $response->return->listePointRetraitAcheminement; + } +} diff --git a/local/modules/ColissimoPickupPoint/WebService/FindById.php b/local/modules/ColissimoPickupPoint/WebService/FindById.php new file mode 100755 index 00000000..793e442c --- /dev/null +++ b/local/modules/ColissimoPickupPoint/WebService/FindById.php @@ -0,0 +1,79 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace ColissimoPickupPoint\WebService; +use stdClass; +use Symfony\Component\Config\Definition\Exception\Exception; + +/** + * Class FindById + * @package ColissimoPickupPoint\WebService + * @author Thelia + * + * @method FindById getId() + * @method FindById setId($value) + * @method FindById getReseau() + * @method FindById setReseau($value) + * @method FindById getLangue() + * @method FindById setLangue($value) + * @method FindById getDate() + * @method FindById setDate($value) + */ +class FindById extends BaseColissimoPickupPointWebService +{ + protected $id; + /** @var string if belgique: R12, else empty */ + protected $reseau; + protected $langue; + protected $date; + + public function __construct() + { + parent::__construct('findPointRetraitAcheminementByID'); + } + + public function isError(stdClass $response) + { + return isset($response->return->errorCode) && $response->return->errorCode != 0; + } + + public function getError(stdClass $response) + { + return isset($response->return->errorMessage) ? $response->return->errorMessage : 'Unknown error'; + } + + /** + * @param stdClass $response + * @return stdClass + * @throws Exception + */ + public function getFormattedResponse(stdClass $response) + { + if (!isset($response->return->pointRetraitAcheminement)) { + throw new Exception('An unknown error happened'); + } + + return $response->return->pointRetraitAcheminement; + } + +} diff --git a/local/modules/ColissimoPickupPoint/composer.json b/local/modules/ColissimoPickupPoint/composer.json new file mode 100644 index 00000000..320dbcb6 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/composer.json @@ -0,0 +1,11 @@ +{ + "name": "thelia/colissimo-pickup-point-module", + "license": "LGPL-3.0+", + "type": "thelia-module", + "require": { + "thelia/installer": "~1.1" + }, + "extra": { + "installer-name": "ColissimoPickupPoint" + } +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/images/socolissimo.png b/local/modules/ColissimoPickupPoint/images/socolissimo.png new file mode 100644 index 00000000..6317f927 Binary files /dev/null and b/local/modules/ColissimoPickupPoint/images/socolissimo.png differ diff --git a/local/modules/ColissimoPickupPoint/templates/backOffice/default/module-config-js.html b/local/modules/ColissimoPickupPoint/templates/backOffice/default/module-config-js.html new file mode 100755 index 00000000..c6811084 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/templates/backOffice/default/module-config-js.html @@ -0,0 +1,201 @@ +{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + +{/javascripts} + +{javascripts file='assets/js/libs/underscore-min.js'} + +{/javascripts} + + + \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/templates/backOffice/default/module_configuration.html b/local/modules/ColissimoPickupPoint/templates/backOffice/default/module_configuration.html new file mode 100755 index 00000000..1b8a8c3e --- /dev/null +++ b/local/modules/ColissimoPickupPoint/templates/backOffice/default/module_configuration.html @@ -0,0 +1,474 @@ + +
+ + {loop name="checkrights.colissimo.pickup.point" type="colissimo.pickup.point.check.rights"} +
+

{$ERRMES} {$ERRFILE} | {intl l="Please change the access rights" d='colissimo.pickup.point.bo.default'}.

+
+ {/loop} +
+ +{elseloop rel="checkrights.colissimo.pickup.point"} + + + +{assign var="tab" value="export"} +{if isset($smarty.get.current_tab)} + {assign var="tab" value=$smarty.get.current_tab} +{/if} + +{* default currency *} +{loop type="currency" name="default_currency" default_only="1"} +{$currencySymbol=$SYMBOL} +{/loop} + +
+
+
+ + + +
+
+
+
+ {intl l="operations" d='colissimo.pickup.point.bo.default'} +
+
+ + + +
+
+ {form name="colissimo.pickup.point.export"} + + {form_hidden_fields form=$form} +
+
+ {intl l="Change orders status after export" d='colissimo.pickup.point.bo.default'} +
+
+ {form_field form=$form field="new_status_id"} + + + + + + + + + + + + + + +
+   + + +
+   + + +
+   + + +
+ {/form_field} + {intl l="*If you choose this option, the exported orders would not be available on this page anymore" d='colissimo.pickup.point.bo.default'} +
+
+ + + + + + + + + + + + {loop name="order.notsent.colissimo.pickup.point" type="order.notsent.colissimo.pickup.point"} + + + + + + + + + {/loop} + +
+ {intl l="REF" d='colissimo.pickup.point.bo.default'} + + {intl l="Customer"} + + {intl l="Date" d='colissimo.pickup.point.bo.default'} + + {intl l="Total taxed amount" d='colissimo.pickup.point.bo.default'} + + {intl l="Package weight" d='colissimo.pickup.point.bo.default'} + + {intl l="Export" d='colissimo.pickup.point.bo.default'} +
+ + + {loop name='order-customer' type='customer' id={$CUSTOMER} current=false} + {$FIRSTNAME} {$LASTNAME} + {/loop} + {elseloop rel='order-customer'} + {intl l='Unknown customer' d='colissimo.pickup.point.bo.default'} + {/elseloop} + + {format_date date=$CREATE_DATE output="datetime"} + + {$TOTAL_TAXED_AMOUNT} {loop name="list.colissimo.pickup.point.getcurrency" type="currency" id=$CURRENCY}{$SYMBOL}{/loop} + + {form_field form=$form field="order_weight_"|cat:$ID} + + {/form_field} + + {form_field form=$form field="order_"|cat:$ID} + + {/form_field} +
+ + + {/form} +
+ + +
+ +
+
+ {intl l="The file has to be a CSV with 2 columns. The first contains the delivery reference, the second the order reference." d='colissimo.pickup.point.bo.default'} +
+ +
+ + {flash type='import-result'} +
+ {$MESSAGE} +
+ {/flash} + + {form name='colissimo.pickup.point.import'} +
+ {form_hidden_fields form=$form} + {render_form_field form=$form field="success_url" value={url path="/admin/module/ColissimoPickupPoint"} current_tab="import"} + + {if $form_error} +
{$form_error_message}
+ {/if} + + {form_field form=$form field="import_file"} +
+ + + +
+ {/form_field} + + +
+ {/form} +
+
+
+ +
+
+
+ {intl l="Advanced configuration" d='colissimo.pickup.bo.default'} +
+ +
+ {form name="colissimo.pickup.point.configure"} + {if $form_error && $form_error_message} +
{$form_error_message}
+ {/if} +
+ {form_hidden_fields form=$form} + {form_field form=$form field='colissimo_pickup_point_endpoint_url'} +
+ + +
+ {/form_field} + {form_field form=$form field='colissimo_pickup_point_username'} +
+ + +
+ {/form_field} + {form_field form=$form field='colissimo_pickup_point_password'} +
+ + +
+ {/form_field} + {form_field form=$form field='colissimo_pickup_point_google_map_key'} +
+ + +
+ {/form_field} +
+ +
+ {/form} +
+
+
+ +
+ {if null !== $smarty.get.price_error} + + {/if} +
+ +
+ + {assign var="isColissimoPickupPointFreeShipping" value=0} + {form name="colissimo.pickup.point.freeshipping.form"} +
+
+ {form_hidden_fields form=$form} + + {form_field form=$form field="freeshipping"} + +
+ {loop type="colissimo.pickup.point.freeshipping" name="freeshipping_colissimo_pickup_point"} + + {/loop} +
+ {/form_field} +
+ +
+
+ {form_field form=$form field="freeshipping_from"} + {loop type="colissimo.pickup.point.freeshipping" name="freeshipping_colissimo_pickup_point"} + {intl l="Or activate free shipping from (€) :" d="colissimo.pickup.point.bo.default"} + + {/loop} + {/form_field} + + + +
+
+
+ {/form} +
+ + +
+ +
+ {intl l="You can create price slices by specifying a maximum cart weight and/or a maximum cart price." d='colissimo.pickup.point.bo.default'} + {intl l="The slices are ordered by maximum cart weight then by maximum cart price." d='colissimo.pickup.point.bo.default'} + {intl l="If a cart matches multiple slices, it will take the last slice following that order." d='colissimo.pickup.point.bo.default'} + {intl l="If you don't specify a cart weight in a slice, it will have priority over the slices with weight." d='colissimo.pickup.point.bo.default'} + {intl l="If you don't specify a cart price in a slice, it will have priority over the other slices with the same weight." d='colissimo.pickup.point.bo.default'} + {intl l="If you specify both, the cart will require to have a lower weight AND a lower price in order to match the slice." d='colissimo.pickup.point.bo.default'} +
+ +
+ + {loop type="module" name="module-id-loop" code="ColissimoPickupPoint"} + {assign var="module_id" value=$ID} + {/loop} + {loop type="area" name="area_loop" module_id=$module_id backend_context=true} + {$area_id=$ID} +
+
+ + + + + + + + + + + + + + + + + {loop type="colissimo.pickup.point" name="colissimo_pickup_point_area_$ID" area_id={$area_id} } + + + + + + + {/loop} + + {* New slice *} + {loop type="auth" name="can_change" role="ADMIN" module="colissimopickuppoint" access="CREATE"} + + + + + + + {/loop} + +
+ + + +
{intl l="Weight up to ... kg" d='colissimo.pickup.point.bo.default'}{intl l="Untaxed Price up to ... %symbol" symbol=$currencySymbol d='colissimo.pickup.point.bo.default'}{intl l="Price (%symbol)" symbol=$currencySymbol d='colissimo.pickup.point.bo.default'}{intl l="Actions" d='colissimo.pickup.point.bo.default'}
+ + + + + + +
+ {loop type="auth" name="can_change" role="ADMIN" module="colissimopickuppoint" access="UPDATE"} + + + + {/loop} + {loop type="auth" name="can_change" role="ADMIN" module="colissimopickuppoint" access="DELETE"} + + + + {/loop} +
+
+ + + + + + + + + +
+
+
+ + {/loop} + {elseloop rel="area_loop"} +
+
+ {intl d='colissimo.pickup.point.bo.default' l="You should first attribute shipping zones to the modules: "} + + {intl d='colissimo.pickup.point.bo.default' l="manage shipping zones"} + +
+
+ {/elseloop} +
+ +
+ +
+
+
+
+ + + {include + file = "includes/generic-warning-dialog.html" + + dialog_id = "colissimo_pickup_point_dialog" + dialog_title = {intl d='colissimo.pickup.bo.default' l="Message"} + dialog_body = "" +} + + {* JS Templates *} + + +{/elseloop} diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/css/styles.css b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/css/styles.css new file mode 100644 index 00000000..0661c09c --- /dev/null +++ b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/css/styles.css @@ -0,0 +1,7 @@ +#colissimo-pickup-pointmap .table tbody > tr > th, #colissimo-pickup-pointmap .table tbody > tr > td { + padding: 10px 10px 0; +} + +.title-colissimo-pickup-point-pickup-type{ + color: #E47A10; +} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/A2P.png b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/A2P.png new file mode 100644 index 00000000..6930dc52 Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/A2P.png differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/BPR.png b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/BPR.png new file mode 100644 index 00000000..5afe2472 Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/BPR.png differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/CIT.png b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/CIT.png new file mode 100644 index 00000000..50818ede Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/CIT.png differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/dom-small.png b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/dom-small.png new file mode 100644 index 00000000..19c5d941 Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/dom-small.png differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/maison.png b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/maison.png new file mode 100644 index 00000000..c1685e2e Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/maison.png differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/mobilite-reduite.gif b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/mobilite-reduite.gif new file mode 100644 index 00000000..f2505d74 Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/mobilite-reduite.gif differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/parking.gif b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/parking.gif new file mode 100644 index 00000000..5bdacaea Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/parking.gif differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/pret-manutention.gif b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/pret-manutention.gif new file mode 100644 index 00000000..05843992 Binary files /dev/null and b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/assets/img/pret-manutention.gif differ diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/colissimo-pickup-point.html b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/colissimo-pickup-point.html new file mode 100644 index 00000000..e70228f0 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/colissimo-pickup-point.html @@ -0,0 +1,487 @@ + +{loop type="delivery" name="colissimopickuppoint" id=$module force_return="true" country=$country} + + +
+
+ {* Point relais *} + {* Check if Colissimo webservice is up *} + {assign var="isColissimoPickupPointUp" value=0} + {colissimoPickupPointDeliveryPrice country=$country}

{$isValidMode}

+ {if $isValidMode !== false} + {loop name="is.colissimo.pickup.point.up" type="colissimo.pickup.point.around"}{/loop} + {ifloop rel="is.colissimo.pickup.point.up"} +
+
+ {intl l="Near you" d='colissimopickuppoint.fo.default'} / {$deliveryPrice} {currency attr="symbol"} +
+
+ + +
+
+ + +
+
+ {images file="assets/img/BPR.png" source="ColissimoPickupPoint"} + + {/images} +
{intl l="Post office" d='colissimopickuppoint.fo.default'}
+

{intl l="Delivery in one of the 10,000 collection points La Poste in France or in a post office in Europe." d='colissimopickuppoint.fo.default'}

+ +
+ +
+
+
+ + +
+
+ {images file="assets/img/A2P.png" source="ColissimoPickupPoint"} + + {/images} +
{intl l="Pickup shop" d='colissimopickuppoint.fo.default'}
+

{intl l="Delivery in one of the 7,500 shops in the PICKUP network." d='colissimopickuppoint.fo.default'}

+ +
+ +
+
+
+ + +
+
+ {images file="assets/img/CIT.png" source="ColissimoPickupPoint"} + + {/images} +
{intl l="Automatic pickup point" d='colissimopickuppoint.fo.default'}
+

{intl l="Delivery in France in one of the 500 automatic instructions 7/7 and 24h/24." d='colissimopickuppoint.fo.default'}

+ +
+ +
+
+
+
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+

{intl l="Search Colissimo relay in a city" d='colissimopickuppoint.fo.default'}

+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+
+
+ + + +
+ +
+
+ {/ifloop} + {/if} +
+
+ + + + +{/loop} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/delivery-address.html b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/delivery-address.html new file mode 100644 index 00000000..3c1fd2e3 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/delivery-address.html @@ -0,0 +1,29 @@ +{assign var="addresslooptype" value="address"} + +{loop type="colissimo.pickup.point.id" name="colissimo.pickup.point.id.invoice"} + {if $module == {order attr="delivery_module"}} + {assign var="addresslooptype" value="address.colissimo.pickup.point"} + {/if} +{/loop} + +{loop type=$addresslooptype name="delivery-address" id={order attr="delivery_address"}} +
+
{intl l="Delivery address"}
+
+ {loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords} + {$COMPANY} +
+ {$ADDRESS1}
+ {if $ADDRESS2 != ""} + {$ADDRESS2}
+ {/if} + {if $ADDRESS3 != ""} + {$ADDRESS3}
+ {/if} + {$ZIPCODE} + {$CITY}, {loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}
+ {$CELLPHONE} +
+
+
+{/loop} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/templates/frontOffice/default/getSpecificLocationColissimoPickupPoint.html b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/getSpecificLocationColissimoPickupPoint.html new file mode 100755 index 00000000..e0169101 --- /dev/null +++ b/local/modules/ColissimoPickupPoint/templates/frontOffice/default/getSpecificLocationColissimoPickupPoint.html @@ -0,0 +1,36 @@ +{literal} +{ +{/literal} +"locations": +[ +{loop type="colissimo.pickup.point.around" name="delivery-selection-colissimo-pickup-point" countryid=$_countryid_ zipcode=$_zipcode_ city=$_city_ address=$_address_} + {literal} + { + {/literal} + "name": "{$nom}", + "lat": {$coordGeolocalisationLatitude}, + "lng": {$coordGeolocalisationLongitude}, + "id": "{$identifiant}", + "address": "{$adresse1}", + "zipcode": "{$codePostal}", + "city": "{$localite}", + "countrycode" : "{$codePays}", + "distance": "{$distance}", + "type": "{$typeDePoint}", + "monday": "{$horairesOuvertureLundi}", + "tuesday": "{$horairesOuvertureMardi}", + "wednesday": "{$horairesOuvertureMercredi}", + "thursday": "{$horairesOuvertureJeudi}", + "friday": "{$horairesOuvertureVendredi}", + "saturday": "{$horairesOuvertureSamedi}", + "sunday": "{$horairesOuvertureDimanche}", + "disabledPerson": "{$accesPersonneMobiliteReduite}" + {literal} + } + {/literal} + {if $LOOP_COUNT < $LOOP_TOTAL},{/if} +{/loop} +] +{literal} +} +{/literal} \ No newline at end of file diff --git a/local/modules/ColissimoPickupPoint/templates/pdf/default/delivery_mode_infos.html b/local/modules/ColissimoPickupPoint/templates/pdf/default/delivery_mode_infos.html new file mode 100644 index 00000000..d41111bb --- /dev/null +++ b/local/modules/ColissimoPickupPoint/templates/pdf/default/delivery_mode_infos.html @@ -0,0 +1,14 @@ +{loop type='colissimo.pickup.point.order_address' name='colissimo.pickup.point.order_address' id=$delivery_address_id} +

+ {intl l='Delivered at a relay.' d='colissimo.pickup.point.pdf.default'}

+ {intl l='Relay address:' d='colissimo.pickup.point.pdf.default'} + {loop name='order_address' type='order_address' id=$delivery_address_id} +

{$COMPANY}
+ {$ADDRESS1} {$ADDRESS2} {$ADDRESS3}
+ {$ZIPCODE} {$CITY}
+ {loop type="country" name="country_delivery" id=$COUNTRY}{$TITLE}{/loop} +
+ {/loop} + {elseloop rel='order_address'} {intl l='no address' d='colissimo.pickup.point.pdf.default'}{/elseloop} +

+{/loop} diff --git a/web/media/thumbs/LOGO-SAINT-JAMES-EPAULE.png b/web/media/thumbs/LOGO-SAINT-JAMES-EPAULE.png new file mode 100644 index 00000000..41fdc1b3 Binary files /dev/null and b/web/media/thumbs/LOGO-SAINT-JAMES-EPAULE.png differ diff --git a/web/media/upload/LOGO-SAINT-JAMES-EPAULE.png b/web/media/upload/LOGO-SAINT-JAMES-EPAULE.png new file mode 100644 index 00000000..e2cec6c3 Binary files /dev/null and b/web/media/upload/LOGO-SAINT-JAMES-EPAULE.png differ