/** * Add shipping method to the database * * @param array $postage Array of data for shipping method * * @return void */ protected function addShippingMethod($postage) { $method = null; // Check if method has alreaby been added in current session to prevent duplicates if (!in_array($postage['CLASSID'], $this->newMethods)) { $lastMethod = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->findOneMaxPositionByProcessor($this->getProcessorId()); $method = new \XLite\Model\Shipping\Method(); $method->setProcessor($this->getProcessorId()); $method->setCarrier($this->getProcessorId()); $method->setCode($postage['CLASSID']); $method->setEnabled(\XLite\Core\Config::getInstance()->CDev->USPS->autoenable_new_methods); $method->setName($postage['MailService']); if ($lastMethod) { $method->setPosition($lastMethod->getPosition() + 1); } \XLite\Core\Database::getEM()->persist($method); \XLite\Core\Database::getEM()->flush(); $this->newMethods[] = $postage['CLASSID']; } return $method; }
/** * add new shipping method to DB * * @param array method attributes * * @return void */ protected function addShippingMethod($service) { // Check if method has already been added in current session to prevent duplicates if (!in_array($service['service_code'], $this->newMethods)) { $method = new \XLite\Model\Shipping\Method(); $method->setProcessor($this->getProcessorId()); $method->setCarrier($this->getProcessorId()); $method->setCode($service['service_code']); $method->setEnabled(false); $method->setName($service['service_name']); \XLite\Core\Database::getEM()->persist($method); \XLite\Core\Database::getEM()->flush(); $this->newMethods[] = $service['service_code']; } }