Ejemplo n.º 1
0
 /**
  * Save billing action
  *
  * Save billing address data
  */
 public function saveBillingAction()
 {
     if ($this->Request()->isPost()) {
         $countryData = $this->admin->sGetCountryList();
         $countryIds = array_column($countryData, 'id');
         $rules = array('salutation' => array('required' => 1), 'company' => array('required' => 0), 'firstname' => array('required' => 1), 'lastname' => array('required' => 1), 'street' => array('required' => 1), 'streetnumber' => array('required' => 1), 'zipcode' => array('required' => 1), 'city' => array('required' => 1), 'phone' => array('required' => intval(Shopware()->Config()->get('requirePhoneField'))), 'fax' => array('required' => 0), 'country' => array('required' => 1, 'in' => $countryIds), 'department' => array('required' => 0), 'shippingAddress' => array('required' => 0), 'text1' => array('required' => 0), 'text2' => array('required' => 0), 'text3' => array('required' => 0), 'text4' => array('required' => 0), 'text5' => array('required' => 0), 'text6' => array('required' => 0), 'birthyear' => array('required' => 0), 'birthmonth' => array('required' => 0), 'birthday' => array('required' => 0));
         $values = $this->Request()->getPost('register');
         // State selection
         if (!empty($values["billing"]["country"])) {
             $stateSelectionRequired = Shopware()->Db()->fetchRow("SELECT display_state_in_registration, force_state_in_registration\n                   FROM s_core_countries WHERE id = ?", array($values["billing"]["country"]));
             if ($stateSelectionRequired["display_state_in_registration"]) {
                 $countryDataIndex = array_search($values["shipping"]["country"], $countryIds);
                 $statesIds = array_column($countryData[$countryDataIndex]['states'], 'id');
                 // if not required, allow empty values
                 if (!$stateSelectionRequired["force_state_in_registration"]) {
                     $statesIds[] = "";
                 }
                 $rules["stateID"] = array("required" => $stateSelectionRequired["force_state_in_registration"], 'in' => $statesIds);
             }
             if ($stateSelectionRequired["display_state_in_registration"] != true && $stateSelectionRequired["force_state_in_registration"] != true) {
                 $this->admin->sSYSTEM->_POST["register"]["billing"]["stateID"] = $values["billing"]["stateID"] = 0;
             } else {
                 $this->admin->sSYSTEM->_POST["register"]["billing"]["stateID"] = $values["billing"]["stateID"] = $values["billing"]["country_state_" . $values["billing"]["country"]];
             }
             unset($values["billing"]["country_state_" . $values["billing"]["country"]]);
         }
         if ($this->Request()->getParam('sSelectAddress')) {
             $address = $this->admin->sGetPreviousAddresses('billing', $this->Request()->getParam('sSelectAddress'));
             if (!empty($address['hash'])) {
                 $address = array_merge($this->View()->sUserData['billingaddress'], $address);
                 $this->admin->sSYSTEM->_POST = $address;
             }
         }
         if (!empty($values['personal']['customer_type']) && $values['personal']['customer_type'] == 'private') {
             $values['billing']['company'] = '';
             $values['billing']['department'] = '';
             $values['billing']['ustid'] = '';
         } elseif (!empty($values['personal']['customer_type']) || !empty($values['billing']['company'])) {
             $rules['ustid'] = array('required' => 0);
         }
         if (!empty($values)) {
             $this->admin->sSYSTEM->_POST = array_merge($values['personal'], $values['billing'], $this->admin->sSYSTEM->_POST->toArray());
         }
         $checkData = $this->admin->sValidateStep2($rules, true);
         if (!empty($checkData['sErrorMessages'])) {
             $this->View()->sErrorFlag = $checkData['sErrorFlag'];
             $this->View()->sErrorMessages = $checkData['sErrorMessages'];
             return $this->forward('billing');
         } else {
             $this->admin->sUpdateBilling();
         }
     }
     if (!($target = $this->Request()->getParam('sTarget'))) {
         $target = 'account';
     }
     $this->redirect(array('controller' => $target, 'action' => 'index', 'success' => 'billing'));
 }
Ejemplo n.º 2
0
    /**
     * @covers sAdmin::sUpdateBilling
     */
    public function testsUpdateBilling()
    {
        $customer = $this->createDummyCustomer();
        $this->session->offsetSet('sUserId', $customer->getId());
        $this->front->Request()->setPost(array('company' => 'TestCompany', 'department' => 'TestDepartment', 'salutation' => 'TestSalutation', 'firstname' => 'TestFirstName', 'lastname' => 'TestLastName', 'street' => 'TestStreet', 'streetnumber' => 'TestStreetNumber', 'zipcode' => 'TestZip', 'city' => 'TestCity', 'phone' => 'TestPhone', 'fax' => 'TestFax', 'country' => '2', 'stateID' => '1', 'ustid' => 'TestUstId', 'birthday' => '21', 'birthmonth' => '10', 'birthyear' => '1998', 'text1' => 'TestText1', 'text2' => 'TestText2', 'text3' => 'TestText3', 'text4' => 'TestText4', 'text5' => 'TestText5', 'text6' => 'TestText6'));
        $this->assertTrue($this->module->sUpdateBilling());
        $result = Shopware()->Db()->fetchRow('
            SELECT *

            FROM s_user_billingaddress
            LEFT JOIN s_user_billingaddress_attributes
            ON s_user_billingaddress.id = s_user_billingaddress_attributes.billingID

            WHERE s_user_billingaddress.userID = ?
        ', array($customer->getId()));
        $this->front->Request()->setPost(array('countryID' => $this->front->Request()->getPost('country'), 'birthday' => '1998-10-21', 'country' => '', 'birthmonth' => '', 'birthyear' => ''));
        $this->assertArrayHasKey('id', $result);
        foreach ($this->front->Request()->getPost() as $key => $value) {
            $this->assertEquals($value, $result[$key]);
        }
        $this->deleteDummyCustomer($customer);
    }