当前位置: 首页>>代码示例>>PHP>>正文


PHP Carrier::duplicateObject方法代码示例

本文整理汇总了PHP中Carrier::duplicateObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Carrier::duplicateObject方法的具体用法?PHP Carrier::duplicateObject怎么用?PHP Carrier::duplicateObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Carrier的用法示例。


在下文中一共展示了Carrier::duplicateObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ajaxProcessFinishStep

 public function ajaxProcessFinishStep()
 {
     $return = array('has_error' => false);
     if (!$this->access('edit')) {
         $return = array('has_error' => true, $return['errors'][] = $this->trans('You do not have permission to use this wizard.', array(), 'Admin.Shipping.Notification'));
     } else {
         $this->validateForm(false);
         if ($id_carrier = Tools::getValue('id_carrier')) {
             $current_carrier = new Carrier((int) $id_carrier);
             // if update we duplicate current Carrier
             /** @var Carrier $new_carrier */
             $new_carrier = $current_carrier->duplicateObject();
             if (Validate::isLoadedObject($new_carrier)) {
                 // Set flag deteled to true for historization
                 $current_carrier->deleted = true;
                 $current_carrier->update();
                 // Fill the new carrier object
                 $this->copyFromPost($new_carrier, $this->table);
                 $new_carrier->position = $current_carrier->position;
                 $new_carrier->update();
                 $this->updateAssoShop((int) $new_carrier->id);
                 $this->duplicateLogo((int) $new_carrier->id, (int) $current_carrier->id);
                 $this->changeGroups((int) $new_carrier->id);
                 //Copy default carrier
                 if (Configuration::get('PS_CARRIER_DEFAULT') == $current_carrier->id) {
                     Configuration::updateValue('PS_CARRIER_DEFAULT', (int) $new_carrier->id);
                 }
                 // Call of hooks
                 Hook::exec('actionCarrierUpdate', array('id_carrier' => (int) $current_carrier->id, 'carrier' => $new_carrier));
                 $this->postImage($new_carrier->id);
                 $this->changeZones($new_carrier->id);
                 $new_carrier->setTaxRulesGroup((int) Tools::getValue('id_tax_rules_group'));
                 $carrier = $new_carrier;
             }
         } else {
             $carrier = new Carrier();
             $this->copyFromPost($carrier, $this->table);
             if (!$carrier->add()) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving this carrier.', array(), 'Admin.Shipping.Notification');
             }
         }
         if ($carrier->is_free) {
             //if carrier is free delete shipping cost
             $carrier->deleteDeliveryPrice('range_weight');
             $carrier->deleteDeliveryPrice('range_price');
         }
         if (Validate::isLoadedObject($carrier)) {
             if (!$this->changeGroups((int) $carrier->id)) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving carrier groups.', array(), 'Admin.Shipping.Notification');
             }
             if (!$this->changeZones((int) $carrier->id)) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving carrier zones.', array(), 'Admin.Shipping.Notification');
             }
             if (!$carrier->is_free) {
                 if (!$this->processRanges((int) $carrier->id)) {
                     $return['has_error'] = true;
                     $return['errors'][] = $this->trans('An error occurred while saving carrier ranges.', array(), 'Admin.Shipping.Notification');
                 }
             }
             if (Shop::isFeatureActive() && !$this->updateAssoShop((int) $carrier->id)) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving associations of shops.', array(), 'Admin.Shipping.Notification');
             }
             if (!$carrier->setTaxRulesGroup((int) Tools::getValue('id_tax_rules_group'))) {
                 $return['has_error'] = true;
                 $return['errors'][] = $this->trans('An error occurred while saving the tax rules group.', array(), 'Admin.Shipping.Notification');
             }
             if (Tools::getValue('logo')) {
                 if (Tools::getValue('logo') == 'null' && file_exists(_PS_SHIP_IMG_DIR_ . $carrier->id . '.jpg')) {
                     unlink(_PS_SHIP_IMG_DIR_ . $carrier->id . '.jpg');
                 } else {
                     $logo = basename(Tools::getValue('logo'));
                     if (!file_exists(_PS_TMP_IMG_DIR_ . $logo) || !copy(_PS_TMP_IMG_DIR_ . $logo, _PS_SHIP_IMG_DIR_ . $carrier->id . '.jpg')) {
                         $return['has_error'] = true;
                         $return['errors'][] = $this->trans('An error occurred while saving carrier logo.', array(), 'Admin.Shipping.Notification');
                     }
                 }
             }
             $return['id_carrier'] = $carrier->id;
         }
     }
     die(json_encode($return));
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:86,代码来源:AdminCarrierWizardController.php


注:本文中的Carrier::duplicateObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。